Search in sources :

Example 51 with JSONObject

use of com.nimbusds.jose.shaded.json.JSONObject in project spring-security by spring-projects.

the class ClaimConversionServiceTests method convertMapStringObjectWhenJsonObjectThenConverts.

@Test
public void convertMapStringObjectWhenJsonObjectThenConverts() {
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("1", "value1");
    jsonObject.put("2", "value2");
    Map<String, Object> mapStringObject = new HashMap<String, Object>() {

        {
            put("1", "value1");
            put("2", "value2");
        }
    };
    assertThat(this.conversionService.convert(jsonObject, Map.class)).isNotInstanceOf(JSONObject.class).isEqualTo(mapStringObject);
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject) HashMap(java.util.HashMap) JSONObject(com.nimbusds.jose.shaded.json.JSONObject) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 52 with JSONObject

use of com.nimbusds.jose.shaded.json.JSONObject in project spring-security by spring-projects.

the class ClaimTypeConverterTests method convertWhenAllClaimsRequireConversionThenConvertAll.

@Test
public void convertWhenAllClaimsRequireConversionThenConvertAll() throws Exception {
    Instant instant = Instant.now();
    URL url = new URL("https://localhost");
    List<Number> listNumber = Lists.list(1, 2, 3, 4);
    List<String> listString = Lists.list("1", "2", "3", "4");
    Map<Integer, Object> mapIntegerObject = new HashMap<>();
    mapIntegerObject.put(1, "value1");
    Map<String, Object> mapStringObject = new HashMap<>();
    mapStringObject.put("1", "value1");
    JSONArray jsonArray = new JSONArray();
    jsonArray.add("1");
    List<String> jsonArrayListString = Lists.list("1");
    JSONObject jsonObject = new JSONObject();
    jsonObject.put("1", "value1");
    Map<String, Object> jsonObjectMap = Maps.newHashMap("1", "value1");
    Map<String, Object> claims = new HashMap<>();
    claims.put(STRING_CLAIM, Boolean.TRUE);
    claims.put(BOOLEAN_CLAIM, "true");
    claims.put(INSTANT_CLAIM, instant.toString());
    claims.put(URL_CLAIM, url.toExternalForm());
    claims.put(COLLECTION_STRING_CLAIM, listNumber);
    claims.put(LIST_STRING_CLAIM, listNumber);
    claims.put(MAP_STRING_OBJECT_CLAIM, mapIntegerObject);
    claims.put(JSON_ARRAY_CLAIM, jsonArray);
    claims.put(JSON_OBJECT_CLAIM, jsonObject);
    claims = this.claimTypeConverter.convert(claims);
    assertThat(claims.get(STRING_CLAIM)).isEqualTo("true");
    assertThat(claims.get(BOOLEAN_CLAIM)).isEqualTo(Boolean.TRUE);
    assertThat(claims.get(INSTANT_CLAIM)).isEqualTo(instant);
    assertThat(claims.get(URL_CLAIM)).isEqualTo(url);
    assertThat(claims.get(COLLECTION_STRING_CLAIM)).isEqualTo(listString);
    assertThat(claims.get(LIST_STRING_CLAIM)).isEqualTo(listString);
    assertThat(claims.get(MAP_STRING_OBJECT_CLAIM)).isEqualTo(mapStringObject);
    assertThat(claims.get(JSON_ARRAY_CLAIM)).isEqualTo(jsonArrayListString);
    assertThat(claims.get(JSON_OBJECT_CLAIM)).isEqualTo(jsonObjectMap);
}
Also used : HashMap(java.util.HashMap) Instant(java.time.Instant) JSONArray(com.nimbusds.jose.shaded.json.JSONArray) URL(java.net.URL) JSONObject(com.nimbusds.jose.shaded.json.JSONObject) 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