use of org.keycloak.services.clientregistration.policy.ClientRegistrationPolicyException in project keycloak by keycloak.
the class ProtocolMappersClientRegistrationPolicy method testMappers.
protected void testMappers(ClientRegistrationContext context) throws ClientRegistrationPolicyException {
List<ProtocolMapperRepresentation> protocolMappers = context.getClient().getProtocolMappers();
if (protocolMappers == null) {
return;
}
List<String> allowedMapperProviders = getAllowedMapperProviders();
for (ProtocolMapperRepresentation mapper : protocolMappers) {
String mapperType = mapper.getProtocolMapper();
if (!allowedMapperProviders.contains(mapperType)) {
ServicesLogger.LOGGER.clientRegistrationMapperNotAllowed(mapper.getName(), mapperType);
throw new ClientRegistrationPolicyException("ProtocolMapper type not allowed");
}
}
}
use of org.keycloak.services.clientregistration.policy.ClientRegistrationPolicyException in project keycloak by keycloak.
the class ClientRegistrationAuth method requireUpdate.
public RegistrationAuth requireUpdate(ClientRegistrationContext context, ClientModel client) {
RegistrationAuth regAuth = requireUpdateAuth(client);
try {
session.clientPolicy().triggerOnEvent(new DynamicClientUpdateContext(context, client, jwt, realm));
ClientRegistrationPolicyManager.triggerBeforeUpdate(context, regAuth, client);
} catch (ClientRegistrationPolicyException | ClientPolicyException crpe) {
throw forbidden(crpe.getMessage());
}
return regAuth;
}
use of org.keycloak.services.clientregistration.policy.ClientRegistrationPolicyException in project keycloak by keycloak.
the class MaxClientsClientRegistrationPolicy method beforeRegister.
@Override
public void beforeRegister(ClientRegistrationContext context) throws ClientRegistrationPolicyException {
RealmModel realm = session.getContext().getRealm();
long currentCount = realm.getClientsCount();
int maxCount = componentModel.get(MaxClientsClientRegistrationPolicyFactory.MAX_CLIENTS, MaxClientsClientRegistrationPolicyFactory.DEFAULT_MAX_CLIENTS);
if (currentCount >= maxCount) {
throw new ClientRegistrationPolicyException("It's allowed to have max " + maxCount + " clients per realm");
}
}
use of org.keycloak.services.clientregistration.policy.ClientRegistrationPolicyException in project keycloak by keycloak.
the class ClientRegistrationAuth method requireDelete.
public void requireDelete(ClientModel client) {
RegistrationAuth chainType = requireUpdateAuth(client);
try {
session.clientPolicy().triggerOnEvent(new DynamicClientUnregisterContext(session, client, jwt, realm));
ClientRegistrationPolicyManager.triggerBeforeRemove(session, provider, chainType, client);
} catch (ClientRegistrationPolicyException | ClientPolicyException crpe) {
throw forbidden(crpe.getMessage());
}
}
use of org.keycloak.services.clientregistration.policy.ClientRegistrationPolicyException in project keycloak by keycloak.
the class ClientRegistrationAuth method requireView.
public void requireView(ClientModel client, boolean allowPublicClient) {
RegistrationAuth authType = null;
boolean authenticated = false;
init();
if (isBearerToken()) {
checkClientProtocol();
if (hasRole(AdminRoles.MANAGE_CLIENTS, AdminRoles.VIEW_CLIENTS)) {
if (client == null) {
throw notFound();
}
authenticated = true;
authType = RegistrationAuth.AUTHENTICATED;
} else {
throw forbidden();
}
} else if (isRegistrationAccessToken()) {
if (client != null && client.getRegistrationToken() != null && client.getRegistrationToken().equals(jwt.getId())) {
checkClientProtocol(client);
authenticated = true;
authType = getRegistrationAuth();
}
} else if (isInitialAccessToken()) {
throw unauthorized("Not initial access token allowed");
} else if (allowPublicClient && authenticatePublicClient(client)) {
authenticated = true;
authType = RegistrationAuth.AUTHENTICATED;
}
if (authenticated) {
try {
session.clientPolicy().triggerOnEvent(new DynamicClientViewContext(session, client, jwt, realm));
ClientRegistrationPolicyManager.triggerBeforeView(session, provider, authType, client);
} catch (ClientRegistrationPolicyException | ClientPolicyException crpe) {
throw forbidden(crpe.getMessage());
}
} else {
throw unauthorized("Not authorized to view client. Not valid token or client credentials provided.");
}
}
Aggregations