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