Search in sources :

Example 1 with AccountRestApiVersion

use of org.keycloak.common.enums.AccountRestApiVersion in project keycloak by keycloak.

the class AccountLoader method getAccountRestService.

private AccountRestService getAccountRestService(ClientModel client, String versionStr) {
    AuthenticationManager.AuthResult authResult = new AppAuthManager.BearerTokenAuthenticator(session).setAudience(client.getClientId()).authenticate();
    if (authResult == null) {
        throw new NotAuthorizedException("Bearer token required");
    }
    Auth auth = new Auth(session.getContext().getRealm(), authResult.getToken(), authResult.getUser(), client, authResult.getSession(), false);
    Cors.add(request).allowedOrigins(auth.getToken()).allowedMethods("GET", "PUT", "POST", "DELETE").auth().build(response);
    if (authResult.getUser().getServiceAccountClientLink() != null) {
        throw new NotAuthorizedException("Service accounts are not allowed to access this service");
    }
    AccountRestApiVersion version;
    if (versionStr == null) {
        version = AccountRestApiVersion.DEFAULT;
    } else {
        version = AccountRestApiVersion.get(versionStr);
        if (version == null) {
            throw new NotFoundException("API version not found");
        }
    }
    AccountRestService accountRestService = new AccountRestService(session, auth, client, event, version);
    ResteasyProviderFactory.getInstance().injectProperties(accountRestService);
    accountRestService.init();
    return accountRestService;
}
Also used : AuthenticationManager(org.keycloak.services.managers.AuthenticationManager) Auth(org.keycloak.services.managers.Auth) AccountRestApiVersion(org.keycloak.common.enums.AccountRestApiVersion) NotFoundException(javax.ws.rs.NotFoundException) NotAuthorizedException(javax.ws.rs.NotAuthorizedException)

Aggregations

NotAuthorizedException (javax.ws.rs.NotAuthorizedException)1 NotFoundException (javax.ws.rs.NotFoundException)1 AccountRestApiVersion (org.keycloak.common.enums.AccountRestApiVersion)1 Auth (org.keycloak.services.managers.Auth)1 AuthenticationManager (org.keycloak.services.managers.AuthenticationManager)1