Search in sources :

Example 6 with ClientRegistrationPolicyException

use of org.keycloak.services.clientregistration.policy.ClientRegistrationPolicyException in project keycloak by keycloak.

the class ClientRegistrationAuth method requireCreate.

public RegistrationAuth requireCreate(ClientRegistrationContext context) {
    init();
    RegistrationAuth registrationAuth = RegistrationAuth.ANONYMOUS;
    if (isBearerToken()) {
        checkClientProtocol();
        if (hasRole(AdminRoles.MANAGE_CLIENTS, AdminRoles.CREATE_CLIENT)) {
            registrationAuth = RegistrationAuth.AUTHENTICATED;
        } else {
            throw forbidden();
        }
    } else if (isInitialAccessToken()) {
        if (initialAccessModel.getRemainingCount() > 0) {
            if (initialAccessModel.getExpiration() == 0 || (initialAccessModel.getTimestamp() + initialAccessModel.getExpiration()) > Time.currentTime()) {
                registrationAuth = RegistrationAuth.AUTHENTICATED;
            } else {
                throw unauthorized("Expired initial access token");
            }
        } else {
            throw unauthorized("No remaining count on initial access token");
        }
    }
    try {
        session.clientPolicy().triggerOnEvent(new DynamicClientRegisterContext(context, jwt, realm));
        ClientRegistrationPolicyManager.triggerBeforeRegister(context, registrationAuth);
    } catch (ClientRegistrationPolicyException | ClientPolicyException crpe) {
        throw forbidden(crpe.getMessage());
    }
    return registrationAuth;
}
Also used : RegistrationAuth(org.keycloak.services.clientregistration.policy.RegistrationAuth) DynamicClientRegisterContext(org.keycloak.services.clientpolicy.context.DynamicClientRegisterContext) ClientRegistrationPolicyException(org.keycloak.services.clientregistration.policy.ClientRegistrationPolicyException) ClientPolicyException(org.keycloak.services.clientpolicy.ClientPolicyException)

Aggregations

ClientRegistrationPolicyException (org.keycloak.services.clientregistration.policy.ClientRegistrationPolicyException)6 ClientPolicyException (org.keycloak.services.clientpolicy.ClientPolicyException)4 RegistrationAuth (org.keycloak.services.clientregistration.policy.RegistrationAuth)4 RealmModel (org.keycloak.models.RealmModel)1 ProtocolMapperRepresentation (org.keycloak.representations.idm.ProtocolMapperRepresentation)1 DynamicClientRegisterContext (org.keycloak.services.clientpolicy.context.DynamicClientRegisterContext)1 DynamicClientUnregisterContext (org.keycloak.services.clientpolicy.context.DynamicClientUnregisterContext)1 DynamicClientUpdateContext (org.keycloak.services.clientpolicy.context.DynamicClientUpdateContext)1 DynamicClientViewContext (org.keycloak.services.clientpolicy.context.DynamicClientViewContext)1