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;
}
Aggregations