Search in sources :

Example 1 with WellKnownProviderFactory

use of org.keycloak.wellknown.WellKnownProviderFactory 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

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 UriBuilder (javax.ws.rs.core.UriBuilder)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 OAuthErrorException (org.keycloak.OAuthErrorException)1 AuthorizationProvider (org.keycloak.authorization.AuthorizationProvider)1