use of org.keycloak.services.clientpolicy.context.DynamicClientViewContext 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