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);
}
}
}
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);
}
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;
}
Aggregations