Search in sources :

Example 1 with SecurityRole

use of com.qcadoo.security.api.SecurityRole in project qcadoo by qcadoo.

the class InternalSecurityRolesServiceImpl method canAccess.

@Override
public boolean canAccess(final String targetRoleIdetifier) {
    Preconditions.checkNotNull(targetRoleIdetifier, "targetRoleIdetifier must be not null");
    SecurityRole targetRole = getRoleByIdentifier(targetRoleIdetifier);
    Preconditions.checkState(targetRoleIdetifier != null, "No such role '" + targetRoleIdetifier + "'");
    return canAccess(targetRole);
}
Also used : SecurityRole(com.qcadoo.security.api.SecurityRole)

Example 2 with SecurityRole

use of com.qcadoo.security.api.SecurityRole in project qcadoo by qcadoo.

the class MenuServiceImplTest method stubRoleForView.

private void stubRoleForView(final String pluginIdentifier, final String viewName, final boolean canAccess) {
    SecurityRole role = mock(SecurityRole.class);
    given(viewDefinitionRoleResolver.getRoleForView(pluginIdentifier, viewName)).willReturn(role);
    given(securityRolesService.canAccess(role)).willReturn(canAccess);
}
Also used : SecurityRole(com.qcadoo.security.api.SecurityRole)

Example 3 with SecurityRole

use of com.qcadoo.security.api.SecurityRole in project qcadoo by qcadoo.

the class MenuServiceImplTest method stubSecurityRole.

private void stubSecurityRole(final String roleIdentifier, final boolean canAccess) {
    SecurityRole role = mock(SecurityRole.class);
    given(securityRolesService.getRoleByIdentifier(roleIdentifier)).willReturn(role);
    given(securityRolesService.canAccess(role)).willReturn(canAccess);
    given(securityRolesService.canAccess(roleIdentifier)).willReturn(canAccess);
}
Also used : SecurityRole(com.qcadoo.security.api.SecurityRole)

Example 4 with SecurityRole

use of com.qcadoo.security.api.SecurityRole in project qcadoo by qcadoo.

the class ViewDefinitionParserImpl method getAuthorizationRole.

public SecurityRole getAuthorizationRole(final Node node) throws ViewDefinitionParserNodeException {
    String authorizationRole = getStringAttribute(node, "defaultAuthorizationRole");
    SecurityRole role;
    if (authorizationRole != null) {
        role = securityRolesService.getRoleByIdentifier(authorizationRole);
        if (role == null) {
            throw new ViewDefinitionParserNodeException(node, "no such role: '" + authorizationRole + "'");
        }
    } else {
        role = securityRolesService.getRoleByIdentifier("ROLE_USER");
    }
    return role;
}
Also used : SecurityRole(com.qcadoo.security.api.SecurityRole)

Example 5 with SecurityRole

use of com.qcadoo.security.api.SecurityRole in project qcadoo by qcadoo.

the class ViewDefinitionParserImpl method parseViewDefinition.

private InternalViewDefinition parseViewDefinition(final Node viewNode, final String pluginIdentifier) throws ViewDefinitionParserNodeException {
    currentIndexOrder = 1;
    String name = getStringAttribute(viewNode, "name");
    Preconditions.checkState(name != null && !"".equals(name.trim()), "Name attribute cannot be empty");
    LOG.info("Reading view " + name + " for plugin " + pluginIdentifier);
    boolean menuAccessible = getBooleanAttribute(viewNode, "menuAccessible", false);
    String windowWidthStr = getStringAttribute(viewNode, "windowWidth");
    String windowHeightStr = getStringAttribute(viewNode, "windowHeight");
    Integer windowWidth = null;
    Integer windowHeight = null;
    if (windowWidthStr != null) {
        windowWidth = Integer.parseInt(windowWidthStr);
    }
    if (windowHeightStr != null) {
        windowHeight = Integer.parseInt(windowHeightStr);
    }
    SecurityRole role = getAuthorizationRole(viewNode);
    DataDefinition dataDefinition = getDataDefinition(viewNode, pluginIdentifier);
    ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl(name, pluginIdentifier, role, dataDefinition, menuAccessible, translationService);
    viewDefinition.setWindowDimmension(windowWidth, windowHeight);
    ComponentPattern root = null;
    NodeList childNodes = viewNode.getChildNodes();
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node child = childNodes.item(i);
        if (Node.ELEMENT_NODE != child.getNodeType()) {
            continue;
        }
        if ("component".equals(child.getNodeName())) {
            root = parseComponent(child, viewDefinition, null, pluginIdentifier);
        } else if ("hooks".equals(child.getNodeName())) {
            parseViewHooks(child, viewDefinition);
        } else {
            throw new ViewDefinitionParserNodeException(child, "Unknown node: " + child.getNodeName());
        }
    }
    viewDefinition.addComponentPattern(root);
    viewDefinition.initialize();
    viewDefinition.registerViews(viewDefinitionService);
    return viewDefinition;
}
Also used : SecurityRole(com.qcadoo.security.api.SecurityRole) ViewDefinitionImpl(com.qcadoo.view.internal.internal.ViewDefinitionImpl) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) AbstractComponentPattern(com.qcadoo.view.internal.patterns.AbstractComponentPattern) DataDefinition(com.qcadoo.model.api.DataDefinition)

Aggregations

SecurityRole (com.qcadoo.security.api.SecurityRole)8 Node (org.w3c.dom.Node)2 NodeList (org.w3c.dom.NodeList)2 DataDefinition (com.qcadoo.model.api.DataDefinition)1 Entity (com.qcadoo.model.api.Entity)1 QcadooUser (com.qcadoo.security.internal.api.QcadooUser)1 ViewDefinitionImpl (com.qcadoo.view.internal.internal.ViewDefinitionImpl)1 AbstractComponentPattern (com.qcadoo.view.internal.patterns.AbstractComponentPattern)1 InternalRibbonGroup (com.qcadoo.view.internal.ribbon.model.InternalRibbonGroup)1 RibbonGroupImpl (com.qcadoo.view.internal.ribbon.model.RibbonGroupImpl)1 ViewDefinitionParserNodeException (com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException)1 GrantedAuthority (org.springframework.security.core.GrantedAuthority)1 GrantedAuthorityImpl (org.springframework.security.core.authority.GrantedAuthorityImpl)1 User (org.springframework.security.core.userdetails.User)1