Search in sources :

Example 6 with JSONArray

use of com.nimbusds.jose.shaded.json.JSONArray in project PowerNukkitX by PowerNukkitX.

the class Metrics method getPluginData.

/**
 * Gets the plugin specific data.
 *
 * @return The plugin specific data.
 */
private JSONObject getPluginData() {
    JSONObject data = new JSONObject();
    // Append the name of the server software
    data.put("pluginName", name);
    JSONArray customCharts = new JSONArray();
    for (CustomChart customChart : charts) {
        // Add the data of the custom charts
        JSONObject chart = customChart.getRequestJsonObject();
        if (chart == null) {
            // If the chart is null, we skip it
            continue;
        }
        customCharts.add(chart);
    }
    data.put("customCharts", customCharts);
    return data;
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject) JSONArray(com.nimbusds.jose.shaded.json.JSONArray)

Example 7 with JSONArray

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

the class ClaimConversionServiceTests method convertListStringWhenJsonArrayThenConverts.

@Test
public void convertListStringWhenJsonArrayThenConverts() {
    JSONArray jsonArray = new JSONArray();
    jsonArray.add("1");
    jsonArray.add("2");
    jsonArray.add("3");
    jsonArray.add(null);
    assertThat(this.conversionService.convert(jsonArray, List.class)).isNotInstanceOf(JSONArray.class).isEqualTo(Lists.list("1", "2", "3"));
}
Also used : JSONArray(com.nimbusds.jose.shaded.json.JSONArray) List(java.util.List) Test(org.junit.jupiter.api.Test)

Example 8 with JSONArray

use of com.nimbusds.jose.shaded.json.JSONArray in project flow by vaadin.

the class JwtSecurityContextRepositoryTest method saveContext_doesSaveJwt_when_trustResolverIsAnonymousReturnsFalse.

@Test
public void saveContext_doesSaveJwt_when_trustResolverIsAnonymousReturnsFalse() throws JOSEException, BadJOSEException, ParseException {
    AnonymousAuthenticationToken anonymousAuthenticationToken = new AnonymousAuthenticationToken("key", "anonymous", AuthorityUtils.createAuthorityList("ROLE_ANONYMOUS"));
    SecurityContext securityContext = SecurityContextHolder.createEmptyContext();
    Mockito.doReturn(anonymousAuthenticationToken).when(securityContext).getAuthentication();
    AuthenticationTrustResolver trustResolver = Mockito.mock(AuthenticationTrustResolver.class);
    Mockito.doReturn(false).when(trustResolver).isAnonymous(anonymousAuthenticationToken);
    jwtSecurityContextRepository.setTrustResolver(trustResolver);
    jwtSecurityContextRepository.saveContext(securityContext, request, response);
    String serializedJwt = getSavedSerializedJwt();
    JWTClaimsSet decodedClaimsSet = decodeSerializedJwt(serializedJwt, jwtProcessor);
    assertClaims(decodedClaimsSet, "anonymous", new JSONArray().appendElement("ANONYMOUS"), 1800);
    Assert.assertEquals(null, decodedClaimsSet.getIssuer());
}
Also used : JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) SecurityContext(org.springframework.security.core.context.SecurityContext) JSONArray(com.nimbusds.jose.shaded.json.JSONArray) AuthenticationTrustResolver(org.springframework.security.authentication.AuthenticationTrustResolver) AnonymousAuthenticationToken(org.springframework.security.authentication.AnonymousAuthenticationToken) Test(org.junit.Test)

Example 9 with JSONArray

use of com.nimbusds.jose.shaded.json.JSONArray in project PowerNukkitX by BlocklyNukkit.

the class Metrics method submitData.

/**
 * Collects the data and sends it afterwards.
 */
private void submitData() {
    final JSONObject data = getServerData();
    JSONArray pluginData = new JSONArray();
    pluginData.add(getPluginData());
    data.put("plugins", pluginData);
    try {
        // We are still in the Thread of the timer, so nothing get blocked :)
        sendData(data);
    } catch (Exception e) {
        // Something went wrong! :(
        if (logFailedRequests) {
            log.warn("Could not submit stats of {}", name, e);
        }
    }
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject) JSONArray(com.nimbusds.jose.shaded.json.JSONArray) IOException(java.io.IOException)

Example 10 with JSONArray

use of com.nimbusds.jose.shaded.json.JSONArray in project pac4j by pac4j.

the class KeycloakRolesAuthorizationGenerator method generate.

@Override
public Optional<UserProfile> generate(final WebContext context, final SessionStore sessionStore, final UserProfile profile) {
    if (profile instanceof KeycloakOidcProfile) {
        try {
            final JWT jwt = SignedJWT.parse(((KeycloakOidcProfile) profile).getAccessToken().getValue());
            final var jwtClaimsSet = jwt.getJWTClaimsSet();
            final var realmRolesJsonObject = jwtClaimsSet.getJSONObjectClaim("realm_access");
            if (realmRolesJsonObject != null) {
                final var realmRolesJsonArray = (JSONArray) realmRolesJsonObject.get("roles");
                if (realmRolesJsonArray != null) {
                    realmRolesJsonArray.forEach(role -> profile.addRole((String) role));
                }
            }
            if (clientId != null) {
                final var resourceAccess = jwtClaimsSet.getJSONObjectClaim("resource_access");
                if (resourceAccess != null) {
                    final var clientRolesJsonObject = (JSONObject) resourceAccess.get(clientId);
                    if (clientRolesJsonObject != null) {
                        final var clientRolesJsonArray = (JSONArray) clientRolesJsonObject.get("roles");
                        if (clientRolesJsonArray != null) {
                            clientRolesJsonArray.forEach(role -> profile.addRole((String) role));
                        }
                    }
                }
            }
        } catch (final Exception e) {
            LOGGER.warn("Cannot parse Keycloak roles", e);
        }
    }
    return Optional.of(profile);
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject) JWT(com.nimbusds.jwt.JWT) SignedJWT(com.nimbusds.jwt.SignedJWT) JSONArray(com.nimbusds.jose.shaded.json.JSONArray) KeycloakOidcProfile(org.pac4j.oidc.profile.keycloak.KeycloakOidcProfile)

Aggregations

JSONArray (com.nimbusds.jose.shaded.json.JSONArray)14 JSONObject (com.nimbusds.jose.shaded.json.JSONObject)9 JWTClaimsSet (com.nimbusds.jwt.JWTClaimsSet)3 SignedJWT (com.nimbusds.jwt.SignedJWT)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 JOSEException (com.nimbusds.jose.JOSEException)2 JWSHeader (com.nimbusds.jose.JWSHeader)2 MACSigner (com.nimbusds.jose.crypto.MACSigner)2 Instant (java.time.Instant)2 List (java.util.List)2 Optional (java.util.Optional)2 Test (org.junit.jupiter.api.Test)2 OidcReactiveApiSecurityConfig (com.c4_soft.springaddons.security.oauth2.config.reactive.OidcReactiveApiSecurityConfig)1 OidcServletApiSecurityConfig (com.c4_soft.springaddons.security.oauth2.config.synchronised.OidcServletApiSecurityConfig)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectReader (com.fasterxml.jackson.databind.ObjectReader)1 JWSAlgorithm (com.nimbusds.jose.JWSAlgorithm)1 JWSObject (com.nimbusds.jose.JWSObject)1 JWSSigner (com.nimbusds.jose.JWSSigner)1