Search in sources :

Example 31 with NoCache

use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.

the class TestingOIDCEndpointsApplicationResource method requestAuthenticationChannel.

@POST
@Path("/request-authentication-channel")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public Response requestAuthenticationChannel(@Context HttpHeaders headers, AuthenticationChannelRequest request) {
    String rawBearerToken = AppAuthManager.extractAuthorizationHeaderToken(headers);
    AccessToken bearerToken;
    try {
        bearerToken = new JWSInput(rawBearerToken).readJsonContent(AccessToken.class);
    } catch (JWSInputException e) {
        throw new RuntimeException("Failed to parse bearer token", e);
    }
    // required
    String authenticationChannelId = bearerToken.getId();
    if (authenticationChannelId == null)
        throw new BadRequestException("missing parameter : " + HttpAuthenticationChannelProvider.AUTHENTICATION_CHANNEL_ID);
    String loginHint = request.getLoginHint();
    if (loginHint == null)
        throw new BadRequestException("missing parameter : " + CibaGrantType.LOGIN_HINT);
    if (request.getConsentRequired() == null)
        throw new BadRequestException("missing parameter : " + CibaGrantType.IS_CONSENT_REQUIRED);
    String scope = request.getScope();
    if (scope == null)
        throw new BadRequestException("missing parameter : " + OAuth2Constants.SCOPE);
    // optional
    // for testing purpose
    String bindingMessage = request.getBindingMessage();
    if (bindingMessage != null && bindingMessage.equals("GODOWN"))
        throw new BadRequestException("intentional error : GODOWN");
    // only one CIBA flow without binding_message can be accepted per test method by this test mechanism.
    if (bindingMessage == null)
        bindingMessage = ChannelRequestDummyKey;
    authenticationChannelRequests.put(bindingMessage, new TestAuthenticationChannelRequest(request, rawBearerToken));
    return Response.status(Status.CREATED).build();
}
Also used : AccessToken(org.keycloak.representations.AccessToken) JWSInputException(org.keycloak.jose.jws.JWSInputException) BadRequestException(javax.ws.rs.BadRequestException) JWSInput(org.keycloak.jose.jws.JWSInput) TestAuthenticationChannelRequest(org.keycloak.testsuite.rest.representation.TestAuthenticationChannelRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 32 with NoCache

use of org.jboss.resteasy.annotations.cache.NoCache 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)

Example 33 with NoCache

use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.

the class PolicyService method findByName.

@Path("/search")
@GET
@Produces(MediaType.APPLICATION_JSON)
@NoCache
public Response findByName(@QueryParam("name") String name, @QueryParam("fields") String fields) {
    if (auth != null) {
        this.auth.realm().requireViewAuthorization();
    }
    StoreFactory storeFactory = authorization.getStoreFactory();
    if (name == null) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    Policy model = storeFactory.getPolicyStore().findByName(name, this.resourceServer.getId());
    if (model == null) {
        return Response.noContent().build();
    }
    return Response.ok(toRepresentation(model, fields, authorization)).build();
}
Also used : Policy(org.keycloak.authorization.model.Policy) StoreFactory(org.keycloak.authorization.store.StoreFactory) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 34 with NoCache

use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.

the class ResourceSetService method getScopes.

@Path("{id}/scopes")
@GET
@NoCache
@Produces("application/json")
public Response getScopes(@PathParam("id") String id) {
    requireView();
    StoreFactory storeFactory = authorization.getStoreFactory();
    Resource model = storeFactory.getResourceStore().findById(id, resourceServer.getId());
    if (model == null) {
        return Response.status(Status.NOT_FOUND).build();
    }
    List<ScopeRepresentation> scopes = model.getScopes().stream().map(scope -> {
        ScopeRepresentation representation = new ScopeRepresentation();
        representation.setId(scope.getId());
        representation.setName(scope.getName());
        return representation;
    }).collect(Collectors.toList());
    if (model.getType() != null && !model.getOwner().equals(resourceServer.getId())) {
        ResourceStore resourceStore = authorization.getStoreFactory().getResourceStore();
        for (Resource typed : resourceStore.findByType(model.getType(), resourceServer.getId())) {
            if (typed.getOwner().equals(resourceServer.getId()) && !typed.getId().equals(model.getId())) {
                scopes.addAll(typed.getScopes().stream().map(model1 -> {
                    ScopeRepresentation scope = new ScopeRepresentation();
                    scope.setId(model1.getId());
                    scope.setName(model1.getName());
                    String iconUri = model1.getIconUri();
                    if (iconUri != null) {
                        scope.setIconUri(iconUri);
                    }
                    return scope;
                }).filter(scopeRepresentation -> !scopes.contains(scopeRepresentation)).collect(Collectors.toList()));
            }
        }
    }
    return Response.ok(scopes).build();
}
Also used : ResourceRepresentation(org.keycloak.representations.idm.authorization.ResourceRepresentation) ResourceType(org.keycloak.events.admin.ResourceType) Produces(javax.ws.rs.Produces) BiFunction(java.util.function.BiFunction) Path(javax.ws.rs.Path) OAuthErrorException(org.keycloak.OAuthErrorException) QueryParam(javax.ws.rs.QueryParam) Consumes(javax.ws.rs.Consumes) ErrorResponseException(org.keycloak.services.ErrorResponseException) ModelToRepresentation.toRepresentation(org.keycloak.models.utils.ModelToRepresentation.toRepresentation) Map(java.util.Map) ResourceOwnerRepresentation(org.keycloak.representations.idm.authorization.ResourceOwnerRepresentation) AuthorizationProvider(org.keycloak.authorization.AuthorizationProvider) DELETE(javax.ws.rs.DELETE) RealmModel(org.keycloak.models.RealmModel) EnumMap(java.util.EnumMap) Collection(java.util.Collection) Set(java.util.Set) PolicyStore(org.keycloak.authorization.store.PolicyStore) ResourceStore(org.keycloak.authorization.store.ResourceStore) Collectors(java.util.stream.Collectors) List(java.util.List) Response(javax.ws.rs.core.Response) RepresentationToModel.toModel(org.keycloak.models.utils.RepresentationToModel.toModel) ClientModel(org.keycloak.models.ClientModel) OperationType(org.keycloak.events.admin.OperationType) PathParam(javax.ws.rs.PathParam) Scope(org.keycloak.authorization.model.Scope) GET(javax.ws.rs.GET) StoreFactory(org.keycloak.authorization.store.StoreFactory) Constants(org.keycloak.models.Constants) HashMap(java.util.HashMap) Function(java.util.function.Function) PolicyRepresentation(org.keycloak.representations.idm.authorization.PolicyRepresentation) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) UserModel(org.keycloak.models.UserModel) ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) Status(javax.ws.rs.core.Response.Status) PathMatcher(org.keycloak.common.util.PathMatcher) ResourceServer(org.keycloak.authorization.model.ResourceServer) POST(javax.ws.rs.POST) AdminPermissionEvaluator(org.keycloak.services.resources.admin.permissions.AdminPermissionEvaluator) KeycloakSession(org.keycloak.models.KeycloakSession) Policy(org.keycloak.authorization.model.Policy) NoCache(org.jboss.resteasy.annotations.cache.NoCache) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) Resource(org.keycloak.authorization.model.Resource) AdminEventBuilder(org.keycloak.services.resources.admin.AdminEventBuilder) Resource(org.keycloak.authorization.model.Resource) ScopeRepresentation(org.keycloak.representations.idm.authorization.ScopeRepresentation) ResourceStore(org.keycloak.authorization.store.ResourceStore) StoreFactory(org.keycloak.authorization.store.StoreFactory) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Example 35 with NoCache

use of org.jboss.resteasy.annotations.cache.NoCache in project keycloak by keycloak.

the class ScopeService method create.

@POST
@NoCache
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response create(ScopeRepresentation scope) {
    this.auth.realm().requireManageAuthorization();
    Scope model = toModel(scope, this.resourceServer, authorization);
    scope.setId(model.getId());
    audit(scope, scope.getId(), OperationType.CREATE);
    return Response.status(Status.CREATED).entity(scope).build();
}
Also used : Scope(org.keycloak.authorization.model.Scope) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) NoCache(org.jboss.resteasy.annotations.cache.NoCache)

Aggregations

NoCache (org.jboss.resteasy.annotations.cache.NoCache)152 Path (javax.ws.rs.Path)128 Produces (javax.ws.rs.Produces)100 GET (javax.ws.rs.GET)82 NotFoundException (javax.ws.rs.NotFoundException)67 POST (javax.ws.rs.POST)49 Consumes (javax.ws.rs.Consumes)48 PUT (javax.ws.rs.PUT)24 DELETE (javax.ws.rs.DELETE)23 HashMap (java.util.HashMap)20 RoleModel (org.keycloak.models.RoleModel)18 UserModel (org.keycloak.models.UserModel)18 BadRequestException (javax.ws.rs.BadRequestException)17 Response (javax.ws.rs.core.Response)16 ErrorResponseException (org.keycloak.services.ErrorResponseException)16 ClientModel (org.keycloak.models.ClientModel)15 AuthenticationFlowModel (org.keycloak.models.AuthenticationFlowModel)14 RealmModel (org.keycloak.models.RealmModel)14 List (java.util.List)12 Map (java.util.Map)12