Search in sources :

Example 1 with ApplicationException

use of io.jans.ca.plugin.adminui.model.exception.ApplicationException in project jans by JanssenProject.

the class OAuth2Resource method getUserInfo.

@POST
@Path(OAUTH2_API_USER_INFO)
@Produces(MediaType.APPLICATION_JSON)
public Response getUserInfo(@Valid @NotNull UserInfoRequest userInfoRequest) {
    try {
        log.info("Get User-Info request to Auth Server.");
        UserInfoResponse userInfoResponse = oAuth2Service.getUserInfo(userInfoRequest);
        log.info("Get User-Info received from Auth Server.");
        return Response.ok(userInfoResponse).build();
    } catch (ApplicationException e) {
        log.error(ErrorResponse.GET_USER_INFO_ERROR.getDescription(), e);
        return Response.status(e.getErrorCode()).entity(e.getMessage()).build();
    } catch (Exception e) {
        log.error(ErrorResponse.GET_USER_INFO_ERROR.getDescription(), e);
        return Response.serverError().entity(e.getMessage()).build();
    }
}
Also used : ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) UserInfoResponse(io.jans.ca.plugin.adminui.model.auth.UserInfoResponse) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException)

Example 2 with ApplicationException

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

Example 3 with ApplicationException

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

Example 4 with ApplicationException

use of io.jans.ca.plugin.adminui.model.exception.ApplicationException 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 5 with ApplicationException

use of io.jans.ca.plugin.adminui.model.exception.ApplicationException 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)

Aggregations

ApplicationException (io.jans.ca.plugin.adminui.model.exception.ApplicationException)18 AdminConf (io.jans.as.model.config.adminui.AdminConf)10 AdminPermission (io.jans.as.model.config.adminui.AdminPermission)6 AdminRole (io.jans.as.model.config.adminui.AdminRole)5 RolePermissionMapping (io.jans.as.model.config.adminui.RolePermissionMapping)5 TokenResponse (io.jans.ca.plugin.adminui.model.auth.TokenResponse)5 AUIConfiguration (io.jans.ca.plugin.adminui.model.config.AUIConfiguration)4 ErrorResponse (io.jans.ca.plugin.adminui.utils.ErrorResponse)4 Response (javax.ws.rs.core.Response)4 Lists (com.google.api.client.util.Lists)3 PersistenceEntryManager (io.jans.orm.PersistenceEntryManager)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 java.util (java.util)3 Collectors (java.util.stream.Collectors)3 Inject (javax.inject.Inject)3 Singleton (javax.inject.Singleton)3 CollectionUtils (org.apache.commons.collections.CollectionUtils)3 Logger (org.slf4j.Logger)3 TokenRequest (io.jans.as.client.TokenRequest)2 Jwt (io.jans.as.model.jwt.Jwt)2