use of fi.otavanopisto.pyramus.domainmodel.security.Permission in project pyramus by otavanopisto.
the class ImportExportPermissionsViewController method processSend.
@Override
public void processSend(PageRequestContext requestContext) {
String permissionJson = requestContext.getString("permissionJson");
JSONObject permissionMap = JSONObject.fromObject(permissionJson);
PermissionDAO permissionDAO = DAOFactory.getInstance().getPermissionDAO();
EnvironmentRolePermissionDAO environmentRolePermissionDAO = DAOFactory.getInstance().getEnvironmentRolePermissionDAO();
List<EnvironmentRolePermission> allPermissions = environmentRolePermissionDAO.listAll();
for (EnvironmentRolePermission erp : allPermissions) {
environmentRolePermissionDAO.delete(erp);
}
for (Object roleObject : permissionMap.keySet()) {
String roleValue = (String) roleObject;
Role role = Role.getRole(Integer.valueOf(roleValue));
if (role == null) {
Logger.getLogger(getClass().getName()).severe(String.format("Role with value %s not found from system", roleValue));
continue;
}
for (Object permissionNameObject : permissionMap.getJSONArray(roleValue)) {
String permissionName = (String) permissionNameObject;
Permission permission = permissionDAO.findByName(permissionName);
if (permission == null) {
Logger.getLogger(getClass().getName()).severe(String.format("Permission %s not found from system", permissionName));
continue;
}
environmentRolePermissionDAO.create(role, permission);
}
}
requestContext.setRedirectURL("/system/managepermissions.page");
}
use of fi.otavanopisto.pyramus.domainmodel.security.Permission in project pyramus by otavanopisto.
the class ManagePermissionsViewController method processSend.
@Override
public void processSend(PageRequestContext requestContext) {
String resetRole = requestContext.getString("roleReset");
if (StringUtils.isBlank(resetRole)) {
PermissionDAO permissionDAO = DAOFactory.getInstance().getPermissionDAO();
EnvironmentRolePermissionDAO environmentRolePermissionDAO = DAOFactory.getInstance().getEnvironmentRolePermissionDAO();
List<Permission> permissions = permissionDAO.listAll();
for (Permission permission : permissions) {
for (Role role : manageableRoles()) {
String paramName = permission.getId().toString() + '.' + role.name();
EnvironmentRolePermission rolePermission = environmentRolePermissionDAO.findByUserRoleAndPermission(role, permission);
boolean isSet = new Integer(1).equals(requestContext.getInteger(paramName));
boolean exists = rolePermission != null;
if (isSet != exists) {
if (isSet) {
environmentRolePermissionDAO.create(role, permission);
} else {
environmentRolePermissionDAO.delete(rolePermission);
}
}
}
}
} else {
resetRoles(Role.valueOf(resetRole));
}
processForm(requestContext);
}
use of fi.otavanopisto.pyramus.domainmodel.security.Permission in project pyramus by otavanopisto.
the class PermissionDAO method listByScope.
public List<Permission> listByScope(String scope) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Permission> criteria = criteriaBuilder.createQuery(Permission.class);
Root<Permission> root = criteria.from(Permission.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(Permission_.scope), scope));
return entityManager.createQuery(criteria).getResultList();
}
use of fi.otavanopisto.pyramus.domainmodel.security.Permission in project pyramus by otavanopisto.
the class PermissionDAO method findByName.
public Permission findByName(String name) {
EntityManager entityManager = getEntityManager();
CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
CriteriaQuery<Permission> criteria = criteriaBuilder.createQuery(Permission.class);
Root<Permission> root = criteria.from(Permission.class);
criteria.select(root);
criteria.where(criteriaBuilder.equal(root.get(Permission_.name), name));
return getSingleResult(entityManager.createQuery(criteria));
}
use of fi.otavanopisto.pyramus.domainmodel.security.Permission in project pyramus by otavanopisto.
the class PermissionDAO method create.
public Permission create(String name, String scope) {
Permission permission = new Permission();
permission.setName(name);
permission.setScope(scope);
getEntityManager().persist(permission);
return permission;
}
Aggregations