Search in sources :

Example 1 with PermissionFeatureHandler

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;
}
Also used : PermissionFeatureLiteral(fi.otavanopisto.security.PermissionFeatureLiteral) PermissionFeatureHandler(fi.otavanopisto.security.PermissionFeatureHandler) Role(fi.otavanopisto.pyramus.domainmodel.users.Role) PermissionFeature(fi.otavanopisto.security.PermissionFeature) Course(fi.otavanopisto.pyramus.domainmodel.courses.Course)

Aggregations

Course (fi.otavanopisto.pyramus.domainmodel.courses.Course)1 Role (fi.otavanopisto.pyramus.domainmodel.users.Role)1 PermissionFeature (fi.otavanopisto.security.PermissionFeature)1 PermissionFeatureHandler (fi.otavanopisto.security.PermissionFeatureHandler)1 PermissionFeatureLiteral (fi.otavanopisto.security.PermissionFeatureLiteral)1