Search in sources :

Example 6 with ResourceServerStore

use of org.keycloak.authorization.store.ResourceServerStore in project keycloak by keycloak.

the class AuthorizationTokenService method getResourceServer.

private ResourceServer getResourceServer(PermissionTicketToken ticket, KeycloakAuthorizationRequest request) {
    AuthorizationProvider authorization = request.getAuthorization();
    StoreFactory storeFactory = authorization.getStoreFactory();
    ResourceServerStore resourceServerStore = storeFactory.getResourceServerStore();
    String issuedFor = ticket.getIssuedFor();
    if (issuedFor == null) {
        CorsErrorResponseException missingIssuedForException = new CorsErrorResponseException(request.getCors(), OAuthErrorException.INVALID_REQUEST, "You must provide the issuedFor", Status.BAD_REQUEST);
        fireErrorEvent(request.getEvent(), Errors.INVALID_REQUEST, missingIssuedForException);
        throw missingIssuedForException;
    }
    ClientModel clientModel = request.getRealm().getClientByClientId(issuedFor);
    if (clientModel == null) {
        CorsErrorResponseException unknownServerIdException = new CorsErrorResponseException(request.getCors(), OAuthErrorException.INVALID_REQUEST, "Unknown resource server id: [" + issuedFor + "]", Status.BAD_REQUEST);
        fireErrorEvent(request.getEvent(), Errors.INVALID_REQUEST, unknownServerIdException);
        throw unknownServerIdException;
    }
    ResourceServer resourceServer = resourceServerStore.findByClient(clientModel);
    if (resourceServer == null) {
        CorsErrorResponseException unsupportedPermissionsException = new CorsErrorResponseException(request.getCors(), OAuthErrorException.INVALID_REQUEST, "Client does not support permissions", Status.BAD_REQUEST);
        fireErrorEvent(request.getEvent(), Errors.INVALID_REQUEST, unsupportedPermissionsException);
        throw unsupportedPermissionsException;
    }
    return resourceServer;
}
Also used : ClientModel(org.keycloak.models.ClientModel) ResourceServerStore(org.keycloak.authorization.store.ResourceServerStore) AuthorizationProvider(org.keycloak.authorization.AuthorizationProvider) CorsErrorResponseException(org.keycloak.services.CorsErrorResponseException) StoreFactory(org.keycloak.authorization.store.StoreFactory) ResourceServer(org.keycloak.authorization.model.ResourceServer)

Example 7 with ResourceServerStore

use of org.keycloak.authorization.store.ResourceServerStore in project keycloak by keycloak.

the class MgmtPermissions method realmResourceServer.

@Override
public ResourceServer realmResourceServer() {
    if (!Profile.isFeatureEnabled(Profile.Feature.AUTHORIZATION))
        return null;
    if (realmResourceServer != null)
        return realmResourceServer;
    ClientModel client = getRealmManagementClient();
    if (client == null)
        return null;
    ResourceServerStore resourceServerStore = authz.getStoreFactory().getResourceServerStore();
    realmResourceServer = resourceServerStore.findByClient(client);
    return realmResourceServer;
}
Also used : ClientModel(org.keycloak.models.ClientModel) ResourceServerStore(org.keycloak.authorization.store.ResourceServerStore)

Aggregations

ResourceServerStore (org.keycloak.authorization.store.ResourceServerStore)7 StoreFactory (org.keycloak.authorization.store.StoreFactory)5 AuthorizationProvider (org.keycloak.authorization.AuthorizationProvider)4 ResourceServer (org.keycloak.authorization.model.ResourceServer)4 ClientModel (org.keycloak.models.ClientModel)4 KeycloakSession (org.keycloak.models.KeycloakSession)3 PolicyStore (org.keycloak.authorization.store.PolicyStore)2 RealmModel (org.keycloak.models.RealmModel)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 EnumMap (java.util.EnumMap)1 Policy (org.keycloak.authorization.model.Policy)1 PolicyProviderFactory (org.keycloak.authorization.policy.provider.PolicyProviderFactory)1 ClientRemovedEvent (org.keycloak.models.ClientModel.ClientRemovedEvent)1 RoleContainerModel (org.keycloak.models.RoleContainerModel)1 RoleRemovedEvent (org.keycloak.models.RoleContainerModel.RoleRemovedEvent)1 RoleModel (org.keycloak.models.RoleModel)1 UserModel (org.keycloak.models.UserModel)1 ClientScopeRepresentation (org.keycloak.representations.idm.ClientScopeRepresentation)1 ClientPolicyRepresentation (org.keycloak.representations.idm.authorization.ClientPolicyRepresentation)1