Search in sources :

Example 26 with JWT

use of io.gravitee.am.common.jwt.JWT in project gravitee-access-management by gravitee-io.

the class DynamicClientRegistrationServiceImpl method applyRegistrationAccessToken.

private Single<Client> applyRegistrationAccessToken(String basePath, Client client) {
    OpenIDProviderMetadata openIDProviderMetadata = openIDDiscoveryService.getConfiguration(basePath);
    JWT jwt = new JWT();
    jwt.setIss(openIDProviderMetadata.getIssuer());
    jwt.setSub(client.getClientId());
    jwt.setAud(client.getClientId());
    jwt.setDomain(client.getDomain());
    jwt.setIat(new Date().getTime() / 1000l);
    jwt.setExp(Date.from(new Date().toInstant().plusSeconds(3600 * 24 * 365 * 2)).getTime() / 1000l);
    jwt.setScope(Scope.DCR.getKey());
    jwt.setJti(SecureRandomString.generate());
    return jwtService.encode(jwt, client).map(token -> {
        client.setRegistrationAccessToken(token);
        client.setRegistrationClientUri(openIDProviderMetadata.getRegistrationEndpoint() + "/" + client.getClientId());
        return client;
    });
}
Also used : SignedJWT(com.nimbusds.jwt.SignedJWT) JWT(io.gravitee.am.common.jwt.JWT) OpenIDProviderMetadata(io.gravitee.am.gateway.handler.oidc.service.discovery.OpenIDProviderMetadata)

Example 27 with JWT

use of io.gravitee.am.common.jwt.JWT in project gravitee-access-management by gravitee-io.

the class PermissionEndpoint method handle.

@Override
public void handle(RoutingContext context) {
    JWT accessToken = context.get(ConstantKeys.TOKEN_CONTEXT_KEY);
    Client client = context.get(ConstantKeys.CLIENT_CONTEXT_KEY);
    this.extractRequest(context).flatMap(this::bodyValidation).map(this::toPermissionRequest).flatMap(permissionRequests -> permissionTicketService.create(permissionRequests, domain.getId(), client.getId())).map(PermissionTicketResponse::from).subscribe(permission -> context.response().putHeader(HttpHeaders.CACHE_CONTROL, "no-store").putHeader(HttpHeaders.PRAGMA, "no-cache").putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).setStatusCode(HttpStatusCode.CREATED_201).end(Json.encodePrettily(permission)), error -> context.fail(error));
}
Also used : JWT(io.gravitee.am.common.jwt.JWT) Client(io.gravitee.am.model.oidc.Client)

Example 28 with JWT

use of io.gravitee.am.common.jwt.JWT in project gravitee-access-management by gravitee-io.

the class ResourceAccessPoliciesEndpoint method list.

public void list(RoutingContext context) {
    final JWT accessToken = context.get(ConstantKeys.TOKEN_CONTEXT_KEY);
    final Client client = context.get(ConstantKeys.CLIENT_CONTEXT_KEY);
    final String resource = context.request().getParam(RESOURCE_ID);
    resourceService.findAccessPolicies(domain.getId(), client.getId(), accessToken.getSub(), resource).map(AccessPolicy::getId).toList().subscribe(response -> context.response().putHeader(HttpHeaders.CACHE_CONTROL, "no-store").putHeader(HttpHeaders.PRAGMA, "no-cache").putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).setStatusCode(response.isEmpty() ? HttpStatusCode.NO_CONTENT_204 : HttpStatusCode.OK_200).end(Json.encodePrettily(response)), error -> context.fail(error));
}
Also used : JWT(io.gravitee.am.common.jwt.JWT) Client(io.gravitee.am.model.oidc.Client) AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy)

Example 29 with JWT

use of io.gravitee.am.common.jwt.JWT in project gravitee-access-management by gravitee-io.

the class ResourceAccessPoliciesEndpoint method create.

public void create(RoutingContext context) {
    final JWT accessToken = context.get(ConstantKeys.TOKEN_CONTEXT_KEY);
    final Client client = context.get(ConstantKeys.CLIENT_CONTEXT_KEY);
    final String resource = context.request().getParam(RESOURCE_ID);
    final String basePath = UriBuilderRequest.resolveProxyRequest(context);
    // extract access policy payload
    AccessPolicy accessPolicy = extractRequest(context);
    // store the access policy
    resourceService.createAccessPolicy(accessPolicy, domain.getId(), client.getId(), accessToken.getSub(), resource).subscribe(p -> context.response().putHeader(HttpHeaders.CACHE_CONTROL, "no-store").putHeader(HttpHeaders.PRAGMA, "no-cache").putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).putHeader(HttpHeaders.LOCATION, resourceLocation(basePath, p)).setStatusCode(HttpStatusCode.CREATED_201).end(Json.encodePrettily(p)), error -> context.fail(error));
}
Also used : JWT(io.gravitee.am.common.jwt.JWT) Client(io.gravitee.am.model.oidc.Client) AccessPolicy(io.gravitee.am.model.uma.policy.AccessPolicy)

Example 30 with JWT

use of io.gravitee.am.common.jwt.JWT in project gravitee-access-management by gravitee-io.

the class ResourceAccessPoliciesEndpoint method get.

public void get(RoutingContext context) {
    final JWT accessToken = context.get(ConstantKeys.TOKEN_CONTEXT_KEY);
    final Client client = context.get(ConstantKeys.CLIENT_CONTEXT_KEY);
    final String resource = context.request().getParam(RESOURCE_ID);
    final String accessPolicyId = context.request().getParam(POLICY_ID);
    resourceService.findAccessPolicy(domain.getId(), client.getId(), accessToken.getSub(), resource, accessPolicyId).switchIfEmpty(Single.error(new AccessPolicyNotFoundException(accessPolicyId))).subscribe(response -> context.response().putHeader(HttpHeaders.CACHE_CONTROL, "no-store").putHeader(HttpHeaders.PRAGMA, "no-cache").putHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON).end(Json.encodePrettily(response)), error -> context.fail(error));
}
Also used : JWT(io.gravitee.am.common.jwt.JWT) AccessPolicyNotFoundException(io.gravitee.am.service.exception.AccessPolicyNotFoundException) Client(io.gravitee.am.model.oidc.Client)

Aggregations

JWT (io.gravitee.am.common.jwt.JWT)130 Test (org.junit.Test)76 Client (io.gravitee.am.model.oidc.Client)72 User (io.gravitee.am.model.User)35 Maybe (io.reactivex.Maybe)27 Json (io.vertx.core.json.Json)26 HttpHeaders (io.gravitee.common.http.HttpHeaders)23 MediaType (io.gravitee.common.http.MediaType)23 Single (io.reactivex.Single)22 ConstantKeys (io.gravitee.am.common.utils.ConstantKeys)19 InvalidTokenException (io.gravitee.am.common.exception.oauth2.InvalidTokenException)17 JWTService (io.gravitee.am.gateway.handler.common.jwt.JWTService)17 Handler (io.vertx.core.Handler)16 RxWebTestBase (io.gravitee.am.gateway.handler.common.vertx.RxWebTestBase)14 HttpMethod (io.vertx.core.http.HttpMethod)14 BodyHandler (io.vertx.reactivex.ext.web.handler.BodyHandler)14 RunWith (org.junit.runner.RunWith)14 InjectMocks (org.mockito.InjectMocks)14 Mock (org.mockito.Mock)14 OAuth2Request (io.gravitee.am.gateway.handler.oauth2.service.request.OAuth2Request)11