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;
}
use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.
the class UserRolePermissionObserver method onEnvironmentRoleDiscoveredEvent.
// TODO: roolit workspacen luonnissa
public void onEnvironmentRoleDiscoveredEvent(@Observes(during = TransactionPhase.BEFORE_COMPLETION) SchoolDataEnvironmentRoleDiscoveredEvent event) {
for (MuikkuPermissionCollection collection : permissionCollections) {
List<String> permissions = collection.listPermissions();
for (String permissionName : permissions) {
Permission permission = permissionDAO.findByName(permissionName);
if (permission != null) {
try {
String permissionScope = collection.getPermissionScope(permissionName);
RoleEntity role = environmentRoleEntityDAO.findById(event.getDiscoveredEnvironmentRoleEntityId());
EnvironmentRoleArchetype[] archetypes = collection.getDefaultEnvironmentRoles(permissionName);
if (archetypes != null) {
for (EnvironmentRoleArchetype archetype : archetypes) {
if (archetype.equals(event.getArchetype())) {
applyPermission(permissionScope, role, permission);
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.
the class UserRolePermissionObserver method onWorkspaceRoleDiscoveredEvent.
public void onWorkspaceRoleDiscoveredEvent(@Observes(during = TransactionPhase.BEFORE_COMPLETION) SchoolDataWorkspaceRoleDiscoveredEvent event) {
for (MuikkuPermissionCollection collection : permissionCollections) {
List<String> permissions = collection.listPermissions();
for (String permissionName : permissions) {
Permission permission = permissionDAO.findByName(permissionName);
if (permission != null) {
try {
String permissionScope = collection.getPermissionScope(permissionName);
RoleEntity role = workspaceRoleEntityDAO.findById(event.getDiscoveredWorkspaceRoleEntityId());
WorkspaceRoleArchetype[] archetypes = collection.getDefaultWorkspaceRoles(permissionName);
if (archetypes != null) {
for (WorkspaceRoleArchetype archetype : archetypes) {
if (archetype.equals(translateArchetype(event.getArchetype()))) {
applyPermission(permissionScope, role, permission);
break;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
}
use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.
the class DefaultPermissionResolver method hasEveryonePermission.
@Override
public boolean hasEveryonePermission(String permission, ContextReference contextReference) {
RoleEntity everyoneRole = getEveryoneRole();
Permission permissionEntity = permissionController.findByName(permission);
return permissionEntity != null && permissionController.hasPermission(everyoneRole, permissionEntity);
}
use of fi.otavanopisto.muikku.model.users.RoleEntity in project muikku by otavanopisto.
the class PermissionsPluginController method resetPermissions.
public void resetPermissions(Set<RoleEntity> resetRoleEntities) {
if (CollectionUtils.isEmpty(resetRoleEntities))
return;
// TODO Only handles environment and workspace scopes
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) {
try {
String permissionScope = collection.getPermissionScope(permissionName);
if (permissionScope != null) {
if (!PermissionScope.PERSONAL.equals(permissionScope)) {
// Current roles
String[] pseudoRoles = collection.getDefaultPseudoRoles(permissionName);
EnvironmentRoleArchetype[] environmentRoles = collection.getDefaultEnvironmentRoles(permissionName);
WorkspaceRoleArchetype[] workspaceRoles = collection.getDefaultWorkspaceRoles(permissionName);
List<RoleEntity> currentRoles = new ArrayList<RoleEntity>();
if (pseudoRoles != null) {
for (String pseudoRole : pseudoRoles) {
RoleEntity roleEntity = roleEntityDAO.findByName(pseudoRole);
if (roleEntity != null) {
currentRoles.add(roleEntity);
}
}
}
if (environmentRoles != null) {
for (EnvironmentRoleArchetype environmentRole : environmentRoles) {
List<EnvironmentRoleEntity> envRoles = environmentRoleEntityDAO.listByArchetype(environmentRole);
currentRoles.addAll(envRoles);
}
}
if (workspaceRoles != null) {
for (WorkspaceRoleArchetype workspaceRole : workspaceRoles) {
List<WorkspaceRoleEntity> wsRoles = workspaceRoleEntityDAO.listByArchetype(workspaceRole);
currentRoles.addAll(wsRoles);
}
}
logger.info(String.format("Permission %s applies to %d roles", permissionName, currentRoles.size()));
if (PermissionScope.ENVIRONMENT.equals(permissionScope) || PermissionScope.WORKSPACE.equals(permissionScope)) {
List<RolePermission> databasePermissions = rolePermissionDAO.listByPermission(permission);
removeNonHandledRoles(currentRoles, databasePermissions, resetRoleEntities);
for (RolePermission databasePermission : databasePermissions) {
int index = indexOfRoleEntity(currentRoles, databasePermission);
if (index >= 0) {
currentRoles.remove(index);
} else {
logger.info(String.format("Removing %s from %s", databasePermission.getRole().getName(), permission.getName()));
rolePermissionDAO.delete(databasePermission);
}
}
for (RoleEntity currentRole : currentRoles) {
logger.info(String.format("Adding environment role %s for %s", currentRole.getName(), permission.getName()));
rolePermissionDAO.create(currentRole, permission);
}
}
}
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Permission handling failed for " + permissionName);
}
}
}
}
}
Aggregations