Search in sources :

Example 1 with WellKnownProvider

use of org.keycloak.wellknown.WellKnownProvider in project keycloak by keycloak.

the class UmaConfiguration method create.

public static final UmaConfiguration create(KeycloakSession session) {
    WellKnownProvider oidcProvider = session.getProvider(WellKnownProvider.class, OIDCWellKnownProviderFactory.PROVIDER_ID);
    OIDCConfigurationRepresentation oidcConfig = OIDCConfigurationRepresentation.class.cast(oidcProvider.getConfig());
    UmaConfiguration configuration = new UmaConfiguration();
    configuration.setIssuer(oidcConfig.getIssuer());
    configuration.setAuthorizationEndpoint(oidcConfig.getAuthorizationEndpoint());
    configuration.setTokenEndpoint(oidcConfig.getTokenEndpoint());
    configuration.setJwksUri(oidcConfig.getJwksUri());
    configuration.setRegistrationEndpoint(oidcConfig.getRegistrationEndpoint());
    configuration.setScopesSupported(oidcConfig.getScopesSupported());
    configuration.setResponseTypesSupported(oidcConfig.getResponseTypesSupported());
    configuration.setResponseModesSupported(oidcConfig.getResponseModesSupported());
    configuration.setGrantTypesSupported(oidcConfig.getGrantTypesSupported());
    configuration.setTokenEndpointAuthMethodsSupported(oidcConfig.getTokenEndpointAuthMethodsSupported());
    configuration.setTokenEndpointAuthSigningAlgValuesSupported(oidcConfig.getTokenEndpointAuthSigningAlgValuesSupported());
    configuration.setIntrospectionEndpoint(oidcConfig.getIntrospectionEndpoint());
    configuration.setLogoutEndpoint(oidcConfig.getLogoutEndpoint());
    UriBuilder uriBuilder = session.getContext().getUri().getBaseUriBuilder();
    RealmModel realm = session.getContext().getRealm();
    configuration.setPermissionEndpoint(uriBuilder.clone().path(RealmsResource.class).path(RealmsResource.class, "getAuthorizationService").path(AuthorizationService.class, "getProtectionService").path(ProtectionService.class, "permission").build(realm.getName()).toString());
    configuration.setResourceRegistrationEndpoint(uriBuilder.clone().path(RealmsResource.class).path(RealmsResource.class, "getAuthorizationService").path(AuthorizationService.class, "getProtectionService").path(ProtectionService.class, "resource").build(realm.getName()).toString());
    configuration.setPolicyEndpoint(uriBuilder.clone().path(RealmsResource.class).path(RealmsResource.class, "getAuthorizationService").path(AuthorizationService.class, "getProtectionService").path(ProtectionService.class, "policy").build(realm.getName()).toString());
    return configuration;
}
Also used : RealmModel(org.keycloak.models.RealmModel) WellKnownProvider(org.keycloak.wellknown.WellKnownProvider) RealmsResource(org.keycloak.services.resources.RealmsResource) ProtectionService(org.keycloak.authorization.protection.ProtectionService) UriBuilder(javax.ws.rs.core.UriBuilder) OIDCConfigurationRepresentation(org.keycloak.protocol.oidc.representations.OIDCConfigurationRepresentation)

Example 2 with WellKnownProvider

use of org.keycloak.wellknown.WellKnownProvider in project keycloak by keycloak.

the class RealmsResource method getWellKnown.

@GET
@Path("{realm}/.well-known/{alias}")
@Produces(MediaType.APPLICATION_JSON)
public Response getWellKnown(@PathParam("realm") final String name, @PathParam("alias") final String alias) {
    RealmModel realm = init(name);
    checkSsl(realm);
    WellKnownProviderFactory wellKnownProviderFactoryFound = session.getKeycloakSessionFactory().getProviderFactoriesStream(WellKnownProvider.class).map(providerFactory -> (WellKnownProviderFactory) providerFactory).filter(wellKnownProviderFactory -> alias.equals(wellKnownProviderFactory.getAlias())).sorted(Comparator.comparingInt(WellKnownProviderFactory::getPriority)).findFirst().orElseThrow(NotFoundException::new);
    logger.tracef("Use provider with ID '%s' for well-known alias '%s'", wellKnownProviderFactoryFound.getId(), alias);
    WellKnownProvider wellKnown = session.getProvider(WellKnownProvider.class, wellKnownProviderFactoryFound.getId());
    if (wellKnown != null) {
        ResponseBuilder responseBuilder = Response.ok(wellKnown.getConfig()).cacheControl(CacheControlUtil.noCache());
        return Cors.add(request, responseBuilder).allowedOrigins("*").auth().build();
    }
    throw new NotFoundException();
}
Also used : RealmModel(org.keycloak.models.RealmModel) ClientModel(org.keycloak.models.ClientModel) PathParam(javax.ws.rs.PathParam) Profile(org.keycloak.common.Profile) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) RealmManager(org.keycloak.services.managers.RealmManager) Logger(org.jboss.logging.Logger) Path(javax.ws.rs.Path) CacheControlUtil(org.keycloak.services.util.CacheControlUtil) LoginProtocolFactory(org.keycloak.protocol.LoginProtocolFactory) ResolveRelative(org.keycloak.services.util.ResolveRelative) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) OAuthErrorException(org.keycloak.OAuthErrorException) MediaType(javax.ws.rs.core.MediaType) EventBuilder(org.keycloak.events.EventBuilder) RealmResourceProvider(org.keycloak.services.resource.RealmResourceProvider) ClientConnection(org.keycloak.common.ClientConnection) UriBuilder(javax.ws.rs.core.UriBuilder) WellKnownProviderFactory(org.keycloak.wellknown.WellKnownProviderFactory) URI(java.net.URI) AuthorizationProvider(org.keycloak.authorization.AuthorizationProvider) ProfileHelper(org.keycloak.utils.ProfileHelper) AuthorizationService(org.keycloak.authorization.AuthorizationService) ProviderFactory(org.keycloak.provider.ProviderFactory) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) RealmModel(org.keycloak.models.RealmModel) Context(javax.ws.rs.core.Context) KeycloakUriBuilder(org.keycloak.common.util.KeycloakUriBuilder) KeycloakSession(org.keycloak.models.KeycloakSession) HttpRequest(org.jboss.resteasy.spi.HttpRequest) OPTIONS(javax.ws.rs.OPTIONS) CorsErrorResponseException(org.keycloak.services.CorsErrorResponseException) NotFoundException(javax.ws.rs.NotFoundException) AccountLoader(org.keycloak.services.resources.account.AccountLoader) Response(javax.ws.rs.core.Response) WellKnownProvider(org.keycloak.wellknown.WellKnownProvider) Optional(java.util.Optional) UriInfo(javax.ws.rs.core.UriInfo) ClientRegistrationService(org.keycloak.services.clientregistration.ClientRegistrationService) Comparator(java.util.Comparator) LoginProtocol(org.keycloak.protocol.LoginProtocol) WellKnownProvider(org.keycloak.wellknown.WellKnownProvider) WellKnownProviderFactory(org.keycloak.wellknown.WellKnownProviderFactory) NotFoundException(javax.ws.rs.NotFoundException) ResponseBuilder(javax.ws.rs.core.Response.ResponseBuilder) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

UriBuilder (javax.ws.rs.core.UriBuilder)2 RealmModel (org.keycloak.models.RealmModel)2 WellKnownProvider (org.keycloak.wellknown.WellKnownProvider)2 URI (java.net.URI)1 Comparator (java.util.Comparator)1 Optional (java.util.Optional)1 GET (javax.ws.rs.GET)1 NotFoundException (javax.ws.rs.NotFoundException)1 OPTIONS (javax.ws.rs.OPTIONS)1 Path (javax.ws.rs.Path)1 PathParam (javax.ws.rs.PathParam)1 Produces (javax.ws.rs.Produces)1 Context (javax.ws.rs.core.Context)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1 ResponseBuilder (javax.ws.rs.core.Response.ResponseBuilder)1 UriInfo (javax.ws.rs.core.UriInfo)1 Logger (org.jboss.logging.Logger)1 HttpRequest (org.jboss.resteasy.spi.HttpRequest)1 ResteasyProviderFactory (org.jboss.resteasy.spi.ResteasyProviderFactory)1