use of io.jans.as.model.config.adminui.AdminRole in project jans by JanssenProject.
the class UserManagementService method addRole.
public List<AdminRole> addRole(AdminRole roleArg) throws ApplicationException {
try {
AdminConf adminConf = entryManager.find(AdminConf.class, CONFIG_DN);
List<AdminRole> roles = adminConf.getDynamic().getRoles();
if (roles.contains(roleArg)) {
return adminConf.getDynamic().getRoles();
}
roles.add(roleArg);
adminConf.getDynamic().setRoles(roles);
entryManager.merge(adminConf);
return adminConf.getDynamic().getRoles();
} catch (Exception e) {
log.error(ErrorResponse.SAVE_ADMIUI_ROLES_ERROR.getDescription(), e);
throw new ApplicationException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ErrorResponse.SAVE_ADMIUI_ROLES_ERROR.getDescription());
}
}
use of io.jans.as.model.config.adminui.AdminRole in project jans by JanssenProject.
the class UserManagementService method deleteRole.
public List<AdminRole> deleteRole(String role) throws ApplicationException {
try {
AdminConf adminConf = entryManager.find(AdminConf.class, CONFIG_DN);
List<RolePermissionMapping> roleScopeMapping = adminConf.getDynamic().getRolePermissionMapping().stream().filter(ele -> ele.getRole().equalsIgnoreCase(role)).collect(Collectors.toList());
if (!roleScopeMapping.isEmpty()) {
Optional<RolePermissionMapping> rolePermissionMappingOptional = roleScopeMapping.stream().findAny();
List<String> permissions = Lists.newArrayList();
if (rolePermissionMappingOptional.isPresent()) {
permissions = rolePermissionMappingOptional.get().getPermissions();
}
if (!permissions.isEmpty()) {
log.error(ErrorResponse.UNABLE_TO_DELETE_ROLE_MAPPED_TO_PERMISSIONS.getDescription());
throw new ApplicationException(Response.Status.BAD_REQUEST.getStatusCode(), ErrorResponse.UNABLE_TO_DELETE_ROLE_MAPPED_TO_PERMISSIONS.getDescription());
}
}
List<AdminRole> roles = adminConf.getDynamic().getRoles();
if (isFalse(getRoleObjByName(role).getDeletable())) {
log.error(ErrorResponse.ROLE_MARKED_UNDELETABLE.getDescription());
throw new ApplicationException(Response.Status.BAD_REQUEST.getStatusCode(), ErrorResponse.ROLE_MARKED_UNDELETABLE.getDescription());
}
roles.removeIf(ele -> ele.getRole().equals(role));
adminConf.getDynamic().setRoles(roles);
entryManager.merge(adminConf);
return adminConf.getDynamic().getRoles();
} catch (ApplicationException e) {
log.error(ErrorResponse.DELETE_ADMIUI_ROLES_ERROR.getDescription());
throw e;
} catch (Exception e) {
log.error(ErrorResponse.DELETE_ADMIUI_ROLES_ERROR.getDescription(), e);
throw new ApplicationException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ErrorResponse.DELETE_ADMIUI_ROLES_ERROR.getDescription());
}
}
use of io.jans.as.model.config.adminui.AdminRole in project jans by JanssenProject.
the class UserManagementService method editRole.
public List<AdminRole> editRole(AdminRole roleArg) throws ApplicationException {
try {
AdminConf adminConf = entryManager.find(AdminConf.class, CONFIG_DN);
List<AdminRole> roles = adminConf.getDynamic().getRoles();
if (roles.stream().noneMatch(ele -> ele.equals(roleArg))) {
log.error(ErrorResponse.ROLE_NOT_FOUND.getDescription());
throw new ApplicationException(Response.Status.BAD_REQUEST.getStatusCode(), ErrorResponse.ROLE_NOT_FOUND.getDescription());
}
roles.removeIf(ele -> ele.equals(roleArg));
roles.add(roleArg);
adminConf.getDynamic().setRoles(roles);
entryManager.merge(adminConf);
return adminConf.getDynamic().getRoles();
} catch (ApplicationException e) {
log.error(ErrorResponse.EDIT_ADMIUI_ROLES_ERROR.getDescription());
throw e;
} catch (Exception e) {
log.error(ErrorResponse.EDIT_ADMIUI_ROLES_ERROR.getDescription(), e);
throw new ApplicationException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ErrorResponse.EDIT_ADMIUI_ROLES_ERROR.getDescription());
}
}
use of io.jans.as.model.config.adminui.AdminRole in project jans by JanssenProject.
the class UserManagementService method getRoleObjByName.
private AdminRole getRoleObjByName(String role) throws ApplicationException {
try {
AdminConf adminConf = entryManager.find(AdminConf.class, CONFIG_DN);
List<AdminRole> roles = adminConf.getDynamic().getRoles().stream().filter(ele -> ele.getRole().equals(role)).collect(Collectors.toList());
if (roles.isEmpty()) {
log.error(ErrorResponse.ROLE_NOT_FOUND.getDescription());
throw new ApplicationException(Response.Status.BAD_REQUEST.getStatusCode(), ErrorResponse.ROLE_NOT_FOUND.getDescription());
}
return roles.stream().findFirst().get();
} catch (ApplicationException e) {
log.error(ErrorResponse.GET_ADMIUI_ROLES_ERROR.getDescription());
throw e;
} catch (Exception e) {
log.error(ErrorResponse.GET_ADMIUI_ROLES_ERROR.getDescription(), e);
throw new ApplicationException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ErrorResponse.GET_ADMIUI_ROLES_ERROR.getDescription());
}
}
Aggregations