use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.
the class PermissionsPluginController method processPermissions.
public void processPermissions() {
logger.log(Level.INFO, "Starting permission gathering");
for (SystemRoleType systemRoleType : SystemRoleType.values()) {
if (systemRoleEntityDAO.findByRoleType(systemRoleType) == null)
systemRoleEntityDAO.create(systemRoleType.name(), systemRoleType);
}
for (MuikkuPermissionCollection collection : permissionCollections) {
logger.log(Level.INFO, "Processing permission collection " + collection.getClass().getSimpleName());
List<String> permissions = collection.listPermissions();
for (String permissionName : permissions) {
Permission permission = permissionDAO.findByName(permissionName);
if (permission == null) {
logger.log(Level.INFO, "Recording new permission " + permissionName);
try {
final String permissionScope = collection.getPermissionScope(permissionName);
if (permissionScope != null) {
permission = permissionDAO.create(permissionName, permissionScope);
if (!PermissionScope.PERSONAL.equals(permissionScope)) {
String[] pseudoRoles = collection.getDefaultPseudoRoles(permissionName);
EnvironmentRoleArchetype[] environmentRoles = collection.getDefaultEnvironmentRoles(permissionName);
WorkspaceRoleArchetype[] workspaceRoles = collection.getDefaultWorkspaceRoles(permissionName);
List<RoleEntity> roles = new ArrayList<RoleEntity>();
if (pseudoRoles != null) {
for (String pseudoRole : pseudoRoles) {
RoleEntity roleEntity = roleEntityDAO.findByName(pseudoRole);
if (roleEntity != null)
roles.add(roleEntity);
}
}
if (environmentRoles != null) {
for (EnvironmentRoleArchetype envRole : environmentRoles) {
List<EnvironmentRoleEntity> envRoles = environmentRoleEntityDAO.listByArchetype(envRole);
roles.addAll(envRoles);
}
}
if (workspaceRoles != null) {
for (WorkspaceRoleArchetype arc : workspaceRoles) {
List<WorkspaceRoleEntity> wsRoles = workspaceRoleEntityDAO.listByArchetype(arc);
roles.addAll(wsRoles);
}
}
switch(permissionScope) {
case PermissionScope.ENVIRONMENT:
case PermissionScope.WORKSPACE:
for (RoleEntity role : roles) {
rolePermissionDAO.create(role, permission);
}
break;
case PermissionScope.USERGROUP:
List<UserGroupEntity> userGroups = userGroupDAO.listAll();
for (RoleEntity role : roles) {
// TODO Workspace creation & templates - is this necessary and bulletproof?
for (UserGroupEntity userGroup : userGroups) {
userGroupRolePermissionDAO.create(userGroup, role, permission);
}
}
break;
default:
permissionDiscoveredEvent.select(new PermissionScopeBinding() {
private static final long serialVersionUID = 9009824962970938515L;
@Override
public String value() {
return permissionScope;
}
}).fire(new PermissionDiscoveredEvent(permission));
break;
}
}
} else
logger.log(Level.WARNING, "PermissionScope null for " + permissionName);
} catch (Exception e) {
logger.log(Level.SEVERE, "Permission handling failed for " + permissionName);
}
}
}
}
logger.log(Level.INFO, "Finished permission gathering");
}
use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.
the class ForumPermissionResolver method hasEveryonePermission.
@Override
public boolean hasEveryonePermission(String permission, ContextReference contextReference) {
ForumArea forumArea = getForumArea(contextReference);
RoleEntity userRole = getEveryoneRole();
Permission perm = permissionDAO.findByName(permission);
if (forumArea == null)
return false;
return resourceUserRolePermissionDAO.hasResourcePermissionAccess(resourceRightsController.findResourceRightsById(forumArea.getRights()), userRole, perm);
}
use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.
the class WorkspaceController method findWorkspaceRoleEntityByDataSourceAndIdentifier.
/* WorkspaceRoleEntity */
public WorkspaceRoleEntity findWorkspaceRoleEntityByDataSourceAndIdentifier(String schoolDataSource, String roleIdentifier) {
SchoolDataSource dataSource = schoolDataSourceDAO.findByIdentifier(schoolDataSource);
if (dataSource == null) {
logger.log(Level.SEVERE, "Could not find school data source '" + schoolDataSource + "'");
return null;
}
RoleSchoolDataIdentifier roleSchoolDataIdentifier = roleSchoolDataIdentifierDAO.findByDataSourceAndIdentifier(dataSource, roleIdentifier);
if (roleSchoolDataIdentifier != null) {
RoleEntity roleEntity = roleSchoolDataIdentifier.getRoleEntity();
if (roleEntity.getType() == UserRoleType.WORKSPACE) {
return (WorkspaceRoleEntity) roleEntity;
}
}
return null;
}
use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.
the class RoleEntityDAO method findByName.
public RoleEntity findByName(String roleName) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<RoleEntity> criteria = criteriaBuilder.createQuery(RoleEntity.class);
Root<RoleEntity> root = criteria.from(RoleEntity.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(RoleEntity_.name), roleName));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.
the class LocalUserSchoolDataBridge method listRoles.
/**
* {@inheritDoc}
*/
@Override
public List<Role> listRoles() throws SchoolDataBridgeInternalException {
List<Role> result = new ArrayList<>();
List<RoleEntity> roleEntities = localUserSchoolDataController.listCoreRoleEntities();
for (RoleEntity roleEntity : roleEntities) {
result.add(toLocalRoleEntity(roleEntity));
}
return result;
}
Aggregations