use of com.nimbusds.jose.shaded.json.JSONObject in project platform by elveahuang.
the class JwtUtils method createJwsToken.
// -----------------------------------------------------------------------------------------------------------------
// JWS
// -----------------------------------------------------------------------------------------------------------------
public static String createJwsToken(byte[] secretKey, Map<String, Object> payloadMap) throws JOSEException {
JWSHeader header = new JWSHeader(DEFAULT_JWT_ALGORITHM);
JWSSigner signer = new MACSigner(secretKey);
Payload payload = new Payload(new JSONObject(payloadMap));
JWSObject object = new JWSObject(header, payload);
object.sign(signer);
return object.serialize();
}
use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.
the class FenceResource method getAuthClient.
@GetMapping("/{fence}/authenticated")
public Mono<ResponseEntity<JSONObject>> getAuthClient(@PathVariable("fence") String fenceKey, JwtAuthenticationToken authentication) throws IllegalArgumentException {
val userId = authentication.getTokenAttributes().get("sub").toString();
val fence = fenceService.getFence(fenceKey);
val defaultResponse = new JSONObject();
defaultResponse.put("authenticated", false);
Mono<Optional<Long>> refreshExpiration = secretService.getSecret(fence.keyRefreshToken(), userId).filter(Secret::notExpired).map(Secret::getExpiration).map(Optional::of).defaultIfEmpty(Optional.empty());
Mono<Optional<Long>> accessExpiration = secretService.getSecret(fence.keyAccessToken(), userId).filter(Secret::notExpired).map(Secret::getExpiration).map(Optional::of).defaultIfEmpty(Optional.empty());
Mono<Long> expiration = Mono.zip(refreshExpiration, accessExpiration).flatMap(t -> {
val refreshOpt = t.getT1();
val accessOpt = t.getT2();
if (refreshOpt.isPresent() && accessOpt.isPresent()) {
val exp = accessOpt.get().compareTo(refreshOpt.get()) > 0 ? accessOpt : refreshOpt;
return Mono.just(exp.get());
} else
return refreshOpt.map(Mono::just).orElseGet(() -> accessOpt.map(Mono::just).orElseGet(Mono::empty));
});
return expiration.map(e -> {
val body = new JSONObject();
body.put("authenticated", true);
body.put("expiration", e);
return ResponseEntity.ok(body);
}).defaultIfEmpty(ResponseEntity.ok(defaultResponse));
}
use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.
the class CavaticaTests method testCavaticaPostWithoutToken.
@Test
void testCavaticaPostWithoutToken() {
JSONObject content = new JSONObject();
content.put("path", "/user");
content.put("method", "GET");
JSONObject body = new JSONObject();
body.put("key1", "value1");
body.put("key2", "value2");
content.put("body", body);
webClient.post().uri(cavaticaURI).bodyValue(content.toJSONString()).accept(MediaType.APPLICATION_JSON).exchange().expectStatus().isUnauthorized();
}
use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.
the class CavaticaTests method testCavaticaUnsupported.
@Test
void testCavaticaUnsupported() {
JSONObject content = new JSONObject();
content.put("path", "/user");
content.put("method", "UNSUPORTED");
cavaticaWM.stubFor(get("/user").willReturn(ok(cavaticaResponseBody)));
webClient.post().uri("/cavatica").contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + defaultAccessToken).bodyValue(content.toJSONString()).exchange().expectStatus().isEqualTo(400);
}
use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.
the class CavaticaTests method testCavaticaPostWithBody.
@Test
void testCavaticaPostWithBody() {
JSONObject content = new JSONObject();
content.put("path", "/user");
content.put("method", "GET");
JSONObject body = new JSONObject();
body.put("key1", "value1");
body.put("key2", "value2");
content.put("body", body);
cavaticaWM.stubFor(get("/user").willReturn(ok(cavaticaResponseBody)));
webClient.post().uri("/cavatica").contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).header("Authorization", "Bearer " + defaultAccessToken).bodyValue(content.toJSONString()).exchange().expectStatus().isOk().expectBody().json(cavaticaResponseBody);
}
Aggregations