use of fi.otavanopisto.security.PermissionFeatureHandler in project pyramus by otavanopisto.
the class EnvironmentPermissionResolver method hasPermission.
@Override
public boolean hasPermission(Permission permission, ContextReference contextReference, User user) {
fi.otavanopisto.pyramus.domainmodel.users.User userEntity = getUser(user);
if (userEntity == null) {
return hasEveryonePermission(permission, contextReference);
}
boolean allowed = false;
if (PermissionScope.COURSE.equals(permission.getScope()) && (contextReference != null)) {
Course course = resolveCourse(contextReference);
if (course != null) {
allowed = hasCourseAccess(course, userEntity, permission);
}
}
Role environmentRole = userEntity.getRole();
allowed = allowed || environmentUserRolePermissionDAO.hasEnvironmentPermissionAccess(environmentRole, permission) || hasEveryonePermission(permission, contextReference);
PyramusPermissionCollection collection = findCollection(permission.getName());
try {
PermissionFeature[] features = collection.listPermissionFeatures(permission.getName());
if (features != null) {
for (PermissionFeature feature : features) {
Instance<PermissionFeatureHandler> instance = featureHandlers.select(new PermissionFeatureLiteral(feature.value()));
if (!instance.isUnsatisfied()) {
PermissionFeatureHandler permissionFeatureHandler = instance.get();
allowed = permissionFeatureHandler.hasPermission(permission.getName(), userEntity, contextReference, allowed);
} else
logger.log(Level.SEVERE, String.format("Unsatisfied permission feature %s", feature.value()));
}
}
} catch (Exception e) {
logger.log(Level.SEVERE, String.format("Could not list permission features for permission %s", permission), e);
}
return allowed;
}
Aggregations