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;
});
}
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));
}
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));
}
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));
}
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));
}
Aggregations