Search in sources :

Example 6 with SecurityRole

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

the class RibbonParserService method parseRibbonGroup.

public InternalRibbonGroup parseRibbonGroup(final Node groupNode, final ViewDefinitionParser parser, final ViewDefinition viewDefinition) throws ViewDefinitionParserNodeException {
    String template = parser.getStringAttribute(groupNode, "template");
    SecurityRole role = parser.getAuthorizationRole(groupNode);
    if (template == null) {
        String groupName = parser.getStringAttribute(groupNode, NAME);
        if (groupName == null) {
            throw new ViewDefinitionParserNodeException(groupNode, "Name attribute cannot be empty");
        }
        InternalRibbonGroup ribbonGroup = new RibbonGroupImpl(groupName, role);
        NodeList childNodes = groupNode.getChildNodes();
        for (int i = 0; i < childNodes.getLength(); i++) {
            Node child = childNodes.item(i);
            if (child.getNodeType() == Node.ELEMENT_NODE) {
                ribbonGroup.addItem(parseRibbonItem(child, parser, viewDefinition));
            }
        }
        return ribbonGroup;
    } else {
        try {
            return ribbonTemplates.getGroupTemplate(template, viewDefinition, role);
        } catch (IllegalStateException e) {
            throw new ViewDefinitionParserNodeException(groupNode, e);
        }
    }
}
Also used : SecurityRole(com.qcadoo.security.api.SecurityRole) RibbonGroupImpl(com.qcadoo.view.internal.ribbon.model.RibbonGroupImpl) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ViewDefinitionParserNodeException(com.qcadoo.view.internal.xml.ViewDefinitionParserNodeException) InternalRibbonGroup(com.qcadoo.view.internal.ribbon.model.InternalRibbonGroup)

Example 7 with SecurityRole

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

the class SecurityServiceImpl method convertEntityToUserDetails.

protected UserDetails convertEntityToUserDetails(final Entity user) {
    List<GrantedAuthority> grantedAuthorities = Lists.newArrayList();
    for (Entity role : user.getBelongsToField(UserFields.GROUP).getManyToManyField(GroupFields.ROLES)) {
        SecurityRole securityRole = securityRolesService.getRoleByIdentifier(role.getStringField(RoleFields.IDENTIFIER));
        checkState(Objects.nonNull(securityRole), "Role '%s' not defined", role.getStringField(RoleFields.IDENTIFIER));
        grantedAuthorities.add(new GrantedAuthorityImpl(securityRole.getRoleIdentifier()));
    }
    checkState(!grantedAuthorities.isEmpty(), "Current user with login %s cannot be found", user.getStringField(UserFields.USER_NAME));
    return new User(user.getStringField(UserFields.USER_NAME), user.getStringField(UserFields.PASSWORD), true, true, true, true, grantedAuthorities);
}
Also used : Entity(com.qcadoo.model.api.Entity) SecurityRole(com.qcadoo.security.api.SecurityRole) User(org.springframework.security.core.userdetails.User) QcadooUser(com.qcadoo.security.internal.api.QcadooUser) GrantedAuthorityImpl(org.springframework.security.core.authority.GrantedAuthorityImpl) GrantedAuthority(org.springframework.security.core.GrantedAuthority)

Example 8 with SecurityRole

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

the class MenuServiceImpl method getAuthorizationRole.

private SecurityRole getAuthorizationRole(final String roleIdentifierOrNull) {
    String roleIdentifierOrDefault = (String) ObjectUtils.defaultIfNull(roleIdentifierOrNull, "ROLE_USER");
    SecurityRole role = securityRolesService.getRoleByIdentifier(roleIdentifierOrDefault);
    Preconditions.checkState(role != null, String.format("No such role: '%s'", roleIdentifierOrDefault));
    return role;
}
Also used : SecurityRole(com.qcadoo.security.api.SecurityRole)

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