Search in sources :

Example 31 with JSONObject

use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.

the class FenceResourceDeprecated method getAuthClient.

@GetMapping("/auth-client")
public Mono<JSONObject> getAuthClient(@RequestParam("fence") String fenceKey) throws IllegalArgumentException {
    val fence = fenceService.getFence(fenceKey);
    // No UserID check - no auth required
    val body = new JSONObject();
    body.put("client_id", fence.getClientId());
    body.put("redirect_uri", fence.getRedirectUri());
    body.put("scope", fence.getScope());
    return Mono.just(body);
}
Also used : lombok.val(lombok.val) JSONObject(com.nimbusds.jose.shaded.json.JSONObject)

Example 32 with JSONObject

use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.

the class FenceResourceDeprecated method refresh.

@PostMapping("/refresh")
public Mono<ResponseEntity<JSONObject>> refresh(@RequestParam("fence") String fenceKey, JwtAuthenticationToken authentication) {
    val userId = authentication.getTokenAttributes().get("sub").toString();
    val fence = fenceService.getFence(fenceKey);
    val storedRefresh = secretService.fetchRefreshToken(fence, userId);
    return storedRefresh.flatMap(refresh -> fenceService.refreshTokens(refresh, fence)).flatMap(tokens -> {
        val body = new JSONObject();
        body.put("access_token", tokens.getAccessToken().getValue());
        body.put("refresh_token", tokens.getRefreshToken().getValue());
        return secretService.persistTokens(fence, userId, tokens).then(Mono.just(ResponseEntity.ok().body(body)));
    }).defaultIfEmpty(ResponseEntity.notFound().build());
}
Also used : lombok.val(lombok.val) JwtAuthenticationToken(org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken) FenceService(io.kidsfirst.core.service.FenceService) Flux(reactor.core.publisher.Flux) Slf4j(lombok.extern.slf4j.Slf4j) JSONObject(com.nimbusds.jose.shaded.json.JSONObject) SecretService(io.kidsfirst.core.service.SecretService) lombok.val(lombok.val) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) Tuple2(reactor.util.function.Tuple2) ResponseEntity(org.springframework.http.ResponseEntity) Mono(reactor.core.publisher.Mono) JSONObject(com.nimbusds.jose.shaded.json.JSONObject)

Example 33 with JSONObject

use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.

the class FenceResourceDeprecated method requestTokens.

@PostMapping("/token")
public Mono<ResponseEntity<JSONObject>> requestTokens(@RequestParam("code") String authCode, @RequestParam("fence") String fenceKey, JwtAuthenticationToken authentication) {
    val userId = authentication.getTokenAttributes().get("sub").toString();
    val fence = fenceService.getFence(fenceKey);
    return fenceService.requestTokens(authCode, fence).flatMap(t -> {
        val body = new JSONObject();
        body.put("access_token", t.getAccessToken().getValue());
        body.put("refresh_token", t.getRefreshToken().getValue());
        val response = ResponseEntity.ok().body(body);
        return secretService.persistTokens(fence, userId, t, true).then(Mono.just(response));
    }).defaultIfEmpty(ResponseEntity.notFound().build());
}
Also used : lombok.val(lombok.val) JwtAuthenticationToken(org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken) FenceService(io.kidsfirst.core.service.FenceService) Flux(reactor.core.publisher.Flux) Slf4j(lombok.extern.slf4j.Slf4j) JSONObject(com.nimbusds.jose.shaded.json.JSONObject) SecretService(io.kidsfirst.core.service.SecretService) lombok.val(lombok.val) org.springframework.web.bind.annotation(org.springframework.web.bind.annotation) Tuple2(reactor.util.function.Tuple2) ResponseEntity(org.springframework.http.ResponseEntity) Mono(reactor.core.publisher.Mono) JSONObject(com.nimbusds.jose.shaded.json.JSONObject)

Example 34 with JSONObject

use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.

the class FenceResourceDeprecated method getTokens.

@GetMapping("/token")
public Mono<ResponseEntity<JSONObject>> getTokens(@RequestParam("fence") String fenceKey, JwtAuthenticationToken authentication) {
    val userId = authentication.getTokenAttributes().get("sub").toString();
    val fence = fenceService.getFence(fenceKey);
    val accessToken = secretService.fetchAccessToken(fence, userId);
    val refreshToken = secretService.fetchRefreshToken(fence, userId);
    return accessToken.zipWith(refreshToken).map(Tuple2::getT1).map(token -> {
        val body = new JSONObject();
        body.put("access_token", token);
        return ResponseEntity.ok(body);
    }).defaultIfEmpty(ResponseEntity.notFound().build()).onErrorReturn(ResponseEntity.notFound().build());
}
Also used : lombok.val(lombok.val) JSONObject(com.nimbusds.jose.shaded.json.JSONObject)

Example 35 with JSONObject

use of com.nimbusds.jose.shaded.json.JSONObject in project kf-key-management by kids-first.

the class CavaticaTests method testCavaticaPostWithoutBody.

@Test
void testCavaticaPostWithoutBody() {
    JSONObject content = new JSONObject();
    content.put("path", "/user");
    content.put("method", "GET");
    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);
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject) Test(org.junit.jupiter.api.Test)

Aggregations

JSONObject (com.nimbusds.jose.shaded.json.JSONObject)52 lombok.val (lombok.val)22 Test (org.junit.jupiter.api.Test)21 Secret (io.kidsfirst.core.model.Secret)10 JSONArray (com.nimbusds.jose.shaded.json.JSONArray)9 Map (java.util.Map)5 Slf4j (lombok.extern.slf4j.Slf4j)5 JWSObject (com.nimbusds.jose.JWSObject)4 FenceService (io.kidsfirst.core.service.FenceService)4 SecretService (io.kidsfirst.core.service.SecretService)4 ResponseEntity (org.springframework.http.ResponseEntity)4 JwtAuthenticationToken (org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken)4 org.springframework.web.bind.annotation (org.springframework.web.bind.annotation)4 IOException (java.io.IOException)3 ECPublicKey (java.security.interfaces.ECPublicKey)3 Flux (reactor.core.publisher.Flux)3 Mono (reactor.core.publisher.Mono)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)2 URI (java.net.URI)2