Search in sources :

Example 1 with JWKBuilder

use of org.keycloak.jose.jwk.JWKBuilder in project keycloak by keycloak.

the class OIDCLoginProtocolService method certs.

@GET
@Path("certs")
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public Response certs() {
    checkSsl();
    JWK[] jwks = session.keys().getKeysStream(realm).filter(k -> k.getStatus().isEnabled() && k.getPublicKey() != null).map(k -> {
        JWKBuilder b = JWKBuilder.create().kid(k.getKid()).algorithm(k.getAlgorithmOrDefault());
        List<X509Certificate> certificates = Optional.ofNullable(k.getCertificateChain()).filter(certs -> !certs.isEmpty()).orElseGet(() -> Collections.singletonList(k.getCertificate()));
        if (k.getType().equals(KeyType.RSA)) {
            return b.rsa(k.getPublicKey(), certificates, k.getUse());
        } else if (k.getType().equals(KeyType.EC)) {
            return b.ec(k.getPublicKey());
        }
        return null;
    }).filter(Objects::nonNull).toArray(JWK[]::new);
    JSONWebKeySet keySet = new JSONWebKeySet();
    keySet.setKeys(jwks);
    Response.ResponseBuilder responseBuilder = Response.ok(keySet).cacheControl(CacheControlUtil.getDefaultCacheControl());
    return Cors.add(request, responseBuilder).allowedOrigins("*").auth().build();
}
Also used : X509Certificate(java.security.cert.X509Certificate) JSONWebKeySet(org.keycloak.jose.jwk.JSONWebKeySet) PathParam(javax.ws.rs.PathParam) RealmsResource(org.keycloak.services.resources.RealmsResource) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) Logger(org.jboss.logging.Logger) Constants(org.keycloak.models.Constants) Path(javax.ws.rs.Path) TokenRevocationEndpoint(org.keycloak.protocol.oidc.endpoints.TokenRevocationEndpoint) CacheControlUtil(org.keycloak.services.util.CacheControlUtil) KeyType(org.keycloak.crypto.KeyType) Messages(org.keycloak.services.messages.Messages) ResteasyProviderFactory(org.jboss.resteasy.spi.ResteasyProviderFactory) AuthorizationEndpoint(org.keycloak.protocol.oidc.endpoints.AuthorizationEndpoint) OAuthErrorException(org.keycloak.OAuthErrorException) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) AuthenticationManager(org.keycloak.services.managers.AuthenticationManager) EventBuilder(org.keycloak.events.EventBuilder) LoginStatusIframeEndpoint(org.keycloak.protocol.oidc.endpoints.LoginStatusIframeEndpoint) ClientConnection(org.keycloak.common.ClientConnection) UriBuilder(javax.ws.rs.core.UriBuilder) Cors(org.keycloak.services.resources.Cors) TokenEndpoint(org.keycloak.protocol.oidc.endpoints.TokenEndpoint) LogoutEndpoint(org.keycloak.protocol.oidc.endpoints.LogoutEndpoint) RealmModel(org.keycloak.models.RealmModel) Context(javax.ws.rs.core.Context) JWK(org.keycloak.jose.jwk.JWK) KeycloakSession(org.keycloak.models.KeycloakSession) UserInfoEndpoint(org.keycloak.protocol.oidc.endpoints.UserInfoEndpoint) OIDCExtProvider(org.keycloak.protocol.oidc.ext.OIDCExtProvider) HttpRequest(org.jboss.resteasy.spi.HttpRequest) ThirdPartyCookiesIframeEndpoint(org.keycloak.protocol.oidc.endpoints.ThirdPartyCookiesIframeEndpoint) OPTIONS(javax.ws.rs.OPTIONS) CorsErrorResponseException(org.keycloak.services.CorsErrorResponseException) NotFoundException(javax.ws.rs.NotFoundException) JWKBuilder(org.keycloak.jose.jwk.JWKBuilder) Objects(java.util.Objects) List(java.util.List) HttpHeaders(javax.ws.rs.core.HttpHeaders) NoCache(org.jboss.resteasy.annotations.cache.NoCache) KeyUse(org.keycloak.crypto.KeyUse) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) LoginFormsProvider(org.keycloak.forms.login.LoginFormsProvider) UriInfo(javax.ws.rs.core.UriInfo) Collections(java.util.Collections) Response(javax.ws.rs.core.Response) JSONWebKeySet(org.keycloak.jose.jwk.JSONWebKeySet) JWKBuilder(org.keycloak.jose.jwk.JWKBuilder) X509Certificate(java.security.cert.X509Certificate) JWK(org.keycloak.jose.jwk.JWK) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Aggregations

X509Certificate (java.security.cert.X509Certificate)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)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 QueryParam (javax.ws.rs.QueryParam)1 Context (javax.ws.rs.core.Context)1 HttpHeaders (javax.ws.rs.core.HttpHeaders)1 MediaType (javax.ws.rs.core.MediaType)1 Response (javax.ws.rs.core.Response)1 UriBuilder (javax.ws.rs.core.UriBuilder)1 UriInfo (javax.ws.rs.core.UriInfo)1 Logger (org.jboss.logging.Logger)1 NoCache (org.jboss.resteasy.annotations.cache.NoCache)1