Search in sources :

Example 1 with AdminPermission

use of io.jans.as.model.config.adminui.AdminPermission 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());
    }
}
Also used : ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) AdminPermission(io.jans.as.model.config.adminui.AdminPermission) AdminConf(io.jans.as.model.config.adminui.AdminConf) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException)

Example 2 with AdminPermission

use of io.jans.as.model.config.adminui.AdminPermission 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());
    }
}
Also used : ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) AdminPermission(io.jans.as.model.config.adminui.AdminPermission) AdminConf(io.jans.as.model.config.adminui.AdminConf) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException)

Example 3 with AdminPermission

use of io.jans.as.model.config.adminui.AdminPermission 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());
    }
}
Also used : ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) AdminPermission(io.jans.as.model.config.adminui.AdminPermission) AdminConf(io.jans.as.model.config.adminui.AdminConf) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException)

Aggregations

AdminConf (io.jans.as.model.config.adminui.AdminConf)3 AdminPermission (io.jans.as.model.config.adminui.AdminPermission)3 ApplicationException (io.jans.ca.plugin.adminui.model.exception.ApplicationException)3