use of com.haulmont.cuba.security.entity.PermissionType in project cuba by cuba-platform.
the class MenuItem method isPermitted.
public boolean isPermitted(UserSession session) {
if (StringUtils.isEmpty(id) || isSeparator()) {
return true;
} else {
boolean screenPermitted = session.isScreenPermitted(id);
if (screenPermitted) {
Element permissionsElem = descriptor.element("permissions");
if (permissionsElem != null) {
for (Element element : Dom4j.elements(permissionsElem, "permission")) {
PermissionType type = PermissionType.valueOf(element.attributeValue("type"));
String target = element.attributeValue("target");
screenPermitted = session.isPermitted(type, target);
if (!screenPermitted)
break;
}
}
}
return screenPermitted;
}
}
use of com.haulmont.cuba.security.entity.PermissionType in project cuba by cuba-platform.
the class PermissionUiHelper method createPermissionItem.
/**
* Add or edit permission item in datasource
* @param ds Datasource
* @param roleDs Role datasource
* @param permissionTarget Permission identifier
* @param type Permission type
* @param value Permission value
*/
public static void createPermissionItem(CollectionDatasource<Permission, UUID> ds, Datasource<Role> roleDs, final String permissionTarget, PermissionType type, Integer value) {
Permission permission = null;
for (Permission p : ds.getItems()) {
if (Objects.equals(p.getTarget(), permissionTarget)) {
permission = p;
break;
}
}
if (permission == null) {
// restore entity instead of create
if (ds instanceof RestorablePermissionDatasource) {
RestorablePermissionDatasource datasource = (RestorablePermissionDatasource) ds;
permission = datasource.findRemovedEntity(p -> p != null && Objects.equals(p.getTarget(), permissionTarget));
if (permission != null) {
datasource.restoreEntity(permission);
}
}
}
if (permission == null) {
Metadata metadata = AppBeans.get(Metadata.NAME);
Permission newPermission = metadata.create(Permission.class);
newPermission.setRole(roleDs.getItem());
newPermission.setTarget(permissionTarget);
newPermission.setType(type);
newPermission.setValue(value);
ds.addItem(newPermission);
} else {
permission.setValue(value);
}
}
use of com.haulmont.cuba.security.entity.PermissionType in project cuba by cuba-platform.
the class PermissionsControllerManager method getPermissionInfos.
public Collection<PermissionInfo> getPermissionInfos() {
Collection<PermissionInfo> result = new ArrayList<>();
for (PermissionType permissionType : PermissionType.values()) {
Map<String, Integer> permissionsMap = userSessionSource.getUserSession().getPermissionsByType(permissionType);
for (Map.Entry<String, Integer> entry : permissionsMap.entrySet()) {
String target = entry.getKey();
Integer value = entry.getValue();
PermissionInfo permissionInfo = new PermissionInfo(permissionType.name(), target, getPermissionValueStr(permissionType, value), value);
result.add(permissionInfo);
}
}
return result;
}
Aggregations