use of io.jans.as.model.config.adminui.AdminConf in project jans by JanssenProject.
the class UserManagementService method addPermissionsToRole.
public List<RolePermissionMapping> addPermissionsToRole(RolePermissionMapping rolePermissionMappingArg) throws ApplicationException {
try {
AdminConf adminConf = entryManager.find(AdminConf.class, CONFIG_DN);
List<RolePermissionMapping> roleScopeMappingList = getRolePermMapByRole(adminConf, rolePermissionMappingArg);
if (CollectionUtils.isNotEmpty(roleScopeMappingList)) {
log.warn(ErrorResponse.ROLE_PERMISSION_MAPPING_PRESENT.getDescription());
throw new ApplicationException(Response.Status.BAD_REQUEST.getStatusCode(), ErrorResponse.ROLE_PERMISSION_MAPPING_PRESENT.getDescription());
}
// create new RolePermissionMapping
RolePermissionMapping rolePermissionMapping = new RolePermissionMapping();
// add role to it
rolePermissionMapping.setRole(rolePermissionMappingArg.getRole());
// remove duplicate permissions
Set<String> scopesSet = new LinkedHashSet<>(rolePermissionMappingArg.getPermissions());
List<String> combinedScopes = new ArrayList<>(scopesSet);
rolePermissionMapping.setPermissions(combinedScopes);
// add permission
roleScopeMappingList.add(rolePermissionMapping);
adminConf.getDynamic().getRolePermissionMapping().addAll(roleScopeMappingList);
entryManager.merge(adminConf);
return adminConf.getDynamic().getRolePermissionMapping();
} catch (ApplicationException e) {
log.error(ErrorResponse.ERROR_IN_MAPPING_ROLE_PERMISSION.getDescription());
throw e;
} catch (Exception e) {
log.error(ErrorResponse.ERROR_IN_MAPPING_ROLE_PERMISSION.getDescription(), e);
throw new ApplicationException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ErrorResponse.ERROR_IN_MAPPING_ROLE_PERMISSION.getDescription());
}
}
use of io.jans.as.model.config.adminui.AdminConf 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.AdminConf in project jans by JanssenProject.
the class UserManagementService method editPermission.
public List<AdminPermission> editPermission(AdminPermission permissionArg) throws ApplicationException {
try {
AdminConf adminConf = entryManager.find(AdminConf.class, CONFIG_DN);
List<AdminPermission> permissions = adminConf.getDynamic().getPermissions();
if (permissions.stream().noneMatch(ele -> ele.equals(permissionArg))) {
log.error(ErrorResponse.PERMISSION_NOT_FOUND.getDescription());
throw new ApplicationException(Response.Status.BAD_REQUEST.getStatusCode(), ErrorResponse.PERMISSION_NOT_FOUND.getDescription());
}
permissions.removeIf(ele -> ele.equals(permissionArg));
permissions.add(permissionArg);
adminConf.getDynamic().setPermissions(permissions);
entryManager.merge(adminConf);
return adminConf.getDynamic().getPermissions();
} catch (ApplicationException e) {
log.error(ErrorResponse.EDIT_ADMIUI_PERMISSIONS_ERROR.getDescription());
throw e;
} catch (Exception e) {
log.error(ErrorResponse.EDIT_ADMIUI_PERMISSIONS_ERROR.getDescription(), e);
throw new ApplicationException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ErrorResponse.EDIT_ADMIUI_PERMISSIONS_ERROR.getDescription());
}
}
use of io.jans.as.model.config.adminui.AdminConf in project jans by JanssenProject.
the class UserManagementService method deletePermission.
public List<AdminPermission> deletePermission(String permission) throws ApplicationException {
try {
AdminConf adminConf = entryManager.find(AdminConf.class, CONFIG_DN);
boolean anyPermissionMapped = adminConf.getDynamic().getRolePermissionMapping().stream().anyMatch(ele -> ele.getPermissions().contains(permission));
if (anyPermissionMapped) {
log.error(ErrorResponse.UNABLE_TO_DELETE_PERMISSION_MAPPED_TO_ROLE.getDescription());
throw new ApplicationException(Response.Status.BAD_REQUEST.getStatusCode(), ErrorResponse.UNABLE_TO_DELETE_PERMISSION_MAPPED_TO_ROLE.getDescription());
}
List<AdminPermission> permissions = adminConf.getDynamic().getPermissions();
permissions.removeIf(ele -> ele.getPermission().equals(permission));
adminConf.getDynamic().setPermissions(permissions);
entryManager.merge(adminConf);
return adminConf.getDynamic().getPermissions();
} catch (ApplicationException e) {
log.error(ErrorResponse.DELETE_ADMIUI_PERMISSIONS_ERROR.getDescription());
throw e;
} catch (Exception e) {
log.error(ErrorResponse.DELETE_ADMIUI_PERMISSIONS_ERROR.getDescription(), e);
throw new ApplicationException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ErrorResponse.DELETE_ADMIUI_PERMISSIONS_ERROR.getDescription());
}
}
use of io.jans.as.model.config.adminui.AdminConf in project jans by JanssenProject.
the class UserManagementService method addPermission.
public List<AdminPermission> addPermission(AdminPermission permissionArg) throws ApplicationException {
try {
AdminConf adminConf = entryManager.find(AdminConf.class, CONFIG_DN);
List<AdminPermission> permissions = adminConf.getDynamic().getPermissions();
if (permissions.contains(permissionArg)) {
return adminConf.getDynamic().getPermissions();
}
permissions.add(permissionArg);
adminConf.getDynamic().setPermissions(permissions);
entryManager.merge(adminConf);
return adminConf.getDynamic().getPermissions();
} catch (Exception e) {
log.error(ErrorResponse.SAVE_ADMIUI_PERMISSIONS_ERROR.getDescription(), e);
throw new ApplicationException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ErrorResponse.SAVE_ADMIUI_PERMISSIONS_ERROR.getDescription());
}
}
Aggregations