Search in sources :

Example 11 with ApplicationException

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

use of io.jans.ca.plugin.adminui.model.exception.ApplicationException 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());
    }
}
Also used : java.util(java.util) Logger(org.slf4j.Logger) AdminPermission(io.jans.as.model.config.adminui.AdminPermission) Singleton(javax.inject.Singleton) PersistenceEntryManager(io.jans.orm.PersistenceEntryManager) Collectors(java.util.stream.Collectors) AdminRole(io.jans.as.model.config.adminui.AdminRole) ErrorResponse(io.jans.ca.plugin.adminui.utils.ErrorResponse) AdminConf(io.jans.as.model.config.adminui.AdminConf) Inject(javax.inject.Inject) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) Response(javax.ws.rs.core.Response) CollectionUtils(org.apache.commons.collections.CollectionUtils) RolePermissionMapping(io.jans.as.model.config.adminui.RolePermissionMapping) Lists(com.google.api.client.util.Lists) 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 13 with ApplicationException

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

the class UserManagementService method removePermissionsFromRole.

public List<RolePermissionMapping> removePermissionsFromRole(RolePermissionMapping rolePermissionMappingArg) throws ApplicationException {
    try {
        AdminConf adminConf = entryManager.find(AdminConf.class, CONFIG_DN);
        if (isFalse(getRoleObjByName(rolePermissionMappingArg.getRole()).getDeletable())) {
            log.error(ErrorResponse.ROLE_MARKED_UNDELETABLE.getDescription());
            throw new ApplicationException(Response.Status.BAD_REQUEST.getStatusCode(), ErrorResponse.ROLE_MARKED_UNDELETABLE.getDescription());
        }
        List<RolePermissionMapping> roleScopeMapping = adminConf.getDynamic().getRolePermissionMapping().stream().filter(ele -> !ele.getRole().equalsIgnoreCase(rolePermissionMappingArg.getRole())).collect(Collectors.toList());
        adminConf.getDynamic().setRolePermissionMapping(roleScopeMapping);
        entryManager.merge(adminConf);
        return adminConf.getDynamic().getRolePermissionMapping();
    } catch (ApplicationException e) {
        log.error(ErrorResponse.ERROR_IN_DELETING_ROLE_PERMISSION.getDescription());
        throw e;
    } catch (Exception e) {
        log.error(ErrorResponse.ERROR_IN_DELETING_ROLE_PERMISSION.getDescription(), e);
        throw new ApplicationException(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), ErrorResponse.ERROR_IN_DELETING_ROLE_PERMISSION.getDescription());
    }
}
Also used : java.util(java.util) Logger(org.slf4j.Logger) AdminPermission(io.jans.as.model.config.adminui.AdminPermission) Singleton(javax.inject.Singleton) PersistenceEntryManager(io.jans.orm.PersistenceEntryManager) Collectors(java.util.stream.Collectors) AdminRole(io.jans.as.model.config.adminui.AdminRole) ErrorResponse(io.jans.ca.plugin.adminui.utils.ErrorResponse) AdminConf(io.jans.as.model.config.adminui.AdminConf) Inject(javax.inject.Inject) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) Response(javax.ws.rs.core.Response) CollectionUtils(org.apache.commons.collections.CollectionUtils) RolePermissionMapping(io.jans.as.model.config.adminui.RolePermissionMapping) Lists(com.google.api.client.util.Lists) 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 14 with ApplicationException

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

the class OAuth2Resource method getApiProtectionToken.

@GET
@Path(OAUTH2_API_PROTECTION_TOKEN)
@Produces(MediaType.APPLICATION_JSON)
public Response getApiProtectionToken(@QueryParam("ujwt") String ujwt) {
    try {
        log.info("Api protection token request to Auth Server.");
        TokenResponse tokenResponse = oAuth2Service.getApiProtectionToken(ujwt);
        log.info("Api protection token received from Auth Server.");
        return Response.ok(tokenResponse).build();
    } catch (ApplicationException e) {
        log.error(ErrorResponse.GET_API_PROTECTION_TOKEN_ERROR.getDescription(), e);
        return Response.status(e.getErrorCode()).entity(e.getMessage()).build();
    } catch (Exception e) {
        log.error(ErrorResponse.GET_API_PROTECTION_TOKEN_ERROR.getDescription(), e);
        return Response.serverError().entity(e.getMessage()).build();
    }
}
Also used : ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) TokenResponse(io.jans.ca.plugin.adminui.model.auth.TokenResponse) ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException)

Example 15 with ApplicationException

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

the class OAuth2Resource method getAccessToken.

@GET
@Path(OAUTH2_ACCESS_TOKEN)
@Produces(MediaType.APPLICATION_JSON)
public Response getAccessToken(@QueryParam("code") String code) {
    try {
        log.info("Access token request to Auth Server.");
        TokenResponse tokenResponse = oAuth2Service.getAccessToken(code);
        log.info("Access token received from Auth Server.");
        return Response.ok(tokenResponse).build();
    } catch (ApplicationException e) {
        log.error(ErrorResponse.GET_ACCESS_TOKEN_ERROR.getDescription(), e);
        return Response.status(e.getErrorCode()).entity(e.getMessage()).build();
    } catch (Exception e) {
        log.error(ErrorResponse.GET_ACCESS_TOKEN_ERROR.getDescription(), e);
        return Response.serverError().entity(e.getMessage()).build();
    }
}
Also used : ApplicationException(io.jans.ca.plugin.adminui.model.exception.ApplicationException) TokenResponse(io.jans.ca.plugin.adminui.model.auth.TokenResponse) 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