Search in sources :

Example 1 with RoleEntity

use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.

the class ForumPermissionResolver method hasPermission.

@Override
public boolean hasPermission(String permission, ContextReference contextReference, User user) {
    ForumArea forumArea = getForumArea(contextReference);
    Permission perm = permissionDAO.findByName(permission);
    UserEntity userEntity = getUserEntity(user);
    if (forumArea == null) {
        return false;
    }
    RoleEntity userRole;
    // TODO: typecasts
    if (forumArea instanceof WorkspaceForumArea) {
        WorkspaceForumArea workspaceForum = (WorkspaceForumArea) forumArea;
        WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityById(workspaceForum.getWorkspace());
        WorkspaceUserEntity workspaceUserEntity = workspaceUserEntityController.findActiveWorkspaceUserByWorkspaceEntityAndUserEntity(workspaceEntity, userEntity);
        if (workspaceUserEntity != null) {
            userRole = workspaceUserEntity.getWorkspaceUserRole();
            if (resourceUserRolePermissionDAO.hasResourcePermissionAccess(resourceRightsController.findResourceRightsById(forumArea.getRights()), userRole, perm) || hasEveryonePermission(permission, forumArea) || userEntity.getId().equals(forumArea.getOwner()))
                return true;
        }
    }
    EnvironmentUser environmentUser = environmentUserDAO.findByUserAndArchived(userEntity, Boolean.FALSE);
    userRole = environmentUser.getRole();
    boolean isOwner = userEntity != null ? userEntity.getId().equals(forumArea.getOwner()) : false;
    return resourceUserRolePermissionDAO.hasResourcePermissionAccess(resourceRightsController.findResourceRightsById(forumArea.getRights()), userRole, perm) || hasEveryonePermission(permission, forumArea) || isOwner;
}
Also used : RoleEntity(fi.otavanopisto.muikku.model.users.RoleEntity) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) EnvironmentUser(fi.otavanopisto.muikku.model.users.EnvironmentUser) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) Permission(fi.otavanopisto.muikku.model.security.Permission) WorkspaceForumArea(fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea) ForumArea(fi.otavanopisto.muikku.plugins.forum.model.ForumArea) WorkspaceUserEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceUserEntity) UserEntity(fi.otavanopisto.muikku.model.users.UserEntity)

Example 2 with RoleEntity

use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.

the class LocalUserSchoolDataBridge method findUserEnvironmentRole.

/**
 * {@inheritDoc}
 */
public Role findUserEnvironmentRole(String userIdentifier) {
    LocalUser user = localUserSchoolDataController.findUser(userIdentifier);
    if (user == null) {
        throw new SchoolDataBridgeInternalException("User not found");
    }
    Long roleId = user.getRoleId();
    if (roleId != null) {
        RoleEntity roleEntity = localUserSchoolDataController.findCoreRoleEntityById(roleId);
        if (roleEntity == null) {
            throw new SchoolDataBridgeInternalException("User role could not be found");
        }
        return toLocalRoleEntity(roleEntity);
    }
    return null;
}
Also used : WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity) RoleEntity(fi.otavanopisto.muikku.model.users.RoleEntity) EnvironmentRoleEntity(fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity) SchoolDataBridgeInternalException(fi.otavanopisto.muikku.schooldata.SchoolDataBridgeInternalException) LocalUser(fi.otavanopisto.muikku.plugins.schooldatalocal.model.LocalUser)

Example 3 with RoleEntity

use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.

the class WorkspacePermissionsRoleManagementBackingBean method init.

@RequestAction
public String init() {
    String urlName = getWorkspaceUrlName();
    if (StringUtils.isBlank(urlName)) {
        return NavigationRules.NOT_FOUND;
    }
    WorkspaceEntity workspaceEntity = workspaceController.findWorkspaceEntityByUrlName(urlName);
    if (workspaceEntity == null) {
        return NavigationRules.NOT_FOUND;
    }
    if (!sessionController.hasWorkspacePermission(MuikkuPermissions.WORKSPACE_MANAGEWORKSPACESETTINGS, workspaceEntity)) {
        return NavigationRules.ACCESS_DENIED;
    }
    workspaceEntityId = workspaceEntity.getId();
    workspaceBackingBean.setWorkspaceUrlName(urlName);
    workspaceName = workspaceBackingBean.getWorkspaceName();
    /**
     * View data
     */
    permissions = permissionController.listPermissionsByScope(PermissionScope.WORKSPACE);
    Collections.sort(permissions, new Comparator<Permission>() {

        @Override
        public int compare(Permission o1, Permission o2) {
            return o1.getName().compareTo(o2.getName());
        }
    });
    roleEntities = new ArrayList<RoleEntity>();
    List<SystemRoleEntity> systemRoleEntities = roleController.listSystemRoleEntities();
    List<EnvironmentRoleEntity> environmentRoleEnties = roleController.listEnvironmentRoleEntities();
    List<WorkspaceRoleEntity> workspaceRoleEntities = roleController.listWorkspaceRoleEntities();
    Collections.sort(environmentRoleEnties, new Comparator<EnvironmentRoleEntity>() {

        @Override
        public int compare(EnvironmentRoleEntity o1, EnvironmentRoleEntity o2) {
            return o1.getArchetype().compareTo(o2.getArchetype());
        }
    });
    Collections.sort(workspaceRoleEntities, new Comparator<WorkspaceRoleEntity>() {

        @Override
        public int compare(WorkspaceRoleEntity o1, WorkspaceRoleEntity o2) {
            return o1.getArchetype().compareTo(o2.getArchetype());
        }
    });
    for (SystemRoleEntity systemRoleEntity : systemRoleEntities) {
        roleEntities.add(systemRoleEntity);
    }
    for (EnvironmentRoleEntity environmentRoleEntity : environmentRoleEnties) {
        roleEntities.add(environmentRoleEntity);
    }
    for (WorkspaceRoleEntity workspaceRoleEntity : workspaceRoleEntities) {
        roleEntities.add(workspaceRoleEntity);
    }
    return null;
}
Also used : EnvironmentRoleEntity(fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity) SystemRoleEntity(fi.otavanopisto.muikku.model.users.SystemRoleEntity) WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity) SystemRoleEntity(fi.otavanopisto.muikku.model.users.SystemRoleEntity) RoleEntity(fi.otavanopisto.muikku.model.users.RoleEntity) EnvironmentRoleEntity(fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity) WorkspaceEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceEntity) WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity) Permission(fi.otavanopisto.muikku.model.security.Permission) RequestAction(org.ocpsoft.rewrite.annotation.RequestAction)

Example 4 with RoleEntity

use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.

the class WorkspaceRoleEntityController method findWorkspaceRoleEntityByDataSourceAndIdentifier.

public WorkspaceRoleEntity findWorkspaceRoleEntityByDataSourceAndIdentifier(String dataSource, String identifier) {
    SchoolDataSource schoolDataSource = schoolDataSourceDAO.findByIdentifier(dataSource);
    if (schoolDataSource == null) {
        logger.severe("Could not find datasource " + dataSource);
        return null;
    }
    RoleSchoolDataIdentifier roleIdentifier = roleSchoolDataIdentifierDAO.findByDataSourceAndIdentifier(schoolDataSource, identifier);
    if (roleIdentifier != null) {
        RoleEntity roleEntity = roleIdentifier.getRoleEntity();
        if (roleEntity != null && roleEntity.getType() == UserRoleType.WORKSPACE) {
            return (WorkspaceRoleEntity) roleEntity;
        }
    }
    return null;
}
Also used : WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity) RoleEntity(fi.otavanopisto.muikku.model.users.RoleEntity) RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier) SchoolDataSource(fi.otavanopisto.muikku.model.base.SchoolDataSource) WorkspaceRoleEntity(fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)

Example 5 with RoleEntity

use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.

the class EnvironmentRoleEntityController method findEnvironmentRoleEntity.

public EnvironmentRoleEntity findEnvironmentRoleEntity(String dataSource, String identifier) {
    SchoolDataSource schoolDataSource = schoolDataSourceDAO.findByIdentifier(dataSource);
    if (schoolDataSource == null) {
        logger.severe("Could not find datasource " + dataSource);
        return null;
    }
    RoleSchoolDataIdentifier roleIdentifier = roleSchoolDataIdentifierDAO.findByDataSourceAndIdentifier(schoolDataSource, identifier);
    if (roleIdentifier != null) {
        RoleEntity roleEntity = roleIdentifier.getRoleEntity();
        if (roleEntity != null && roleEntity.getType() == UserRoleType.ENVIRONMENT) {
            return (EnvironmentRoleEntity) roleEntity;
        }
    }
    return null;
}
Also used : RoleEntity(fi.otavanopisto.muikku.model.users.RoleEntity) EnvironmentRoleEntity(fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity) RoleSchoolDataIdentifier(fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier) SchoolDataSource(fi.otavanopisto.muikku.model.base.SchoolDataSource) EnvironmentRoleEntity(fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity)

Aggregations

RoleEntity (fi.otavanopisto.muikku.model.users.RoleEntity)16 Permission (fi.otavanopisto.muikku.model.security.Permission)9 EnvironmentRoleEntity (fi.otavanopisto.muikku.model.users.EnvironmentRoleEntity)8 WorkspaceRoleEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceRoleEntity)8 RolePermission (fi.otavanopisto.muikku.model.security.RolePermission)4 SchoolDataSource (fi.otavanopisto.muikku.model.base.SchoolDataSource)3 EnvironmentRoleArchetype (fi.otavanopisto.muikku.model.users.EnvironmentRoleArchetype)3 RoleSchoolDataIdentifier (fi.otavanopisto.muikku.model.users.RoleSchoolDataIdentifier)3 WorkspaceRoleArchetype (fi.otavanopisto.muikku.model.workspace.WorkspaceRoleArchetype)3 ArrayList (java.util.ArrayList)3 SystemRoleEntity (fi.otavanopisto.muikku.model.users.SystemRoleEntity)2 WorkspaceEntity (fi.otavanopisto.muikku.model.workspace.WorkspaceEntity)2 ForumArea (fi.otavanopisto.muikku.plugins.forum.model.ForumArea)2 WorkspaceForumArea (fi.otavanopisto.muikku.plugins.forum.model.WorkspaceForumArea)2 MuikkuPermissionCollection (fi.otavanopisto.muikku.security.MuikkuPermissionCollection)2 RequestAction (org.ocpsoft.rewrite.annotation.RequestAction)2 EnvironmentUser (fi.otavanopisto.muikku.model.users.EnvironmentUser)1 SystemRoleType (fi.otavanopisto.muikku.model.users.SystemRoleType)1 UserEntity (fi.otavanopisto.muikku.model.users.UserEntity)1 UserGroupEntity (fi.otavanopisto.muikku.model.users.UserGroupEntity)1