Search in sources :

Example 1 with JSONArray

use of com.nimbusds.jose.shaded.json.JSONArray in project openbanking-aspsp by OpenBankingToolkit.

the class DirectorySoftwareStatementFactory method getOrgContacts.

private List<OrganisationContact> getOrgContacts(RegistrationRequestJWTClaims softwareStatementClaims) {
    List<OrganisationContact> contacts = new ArrayList<>();
    JSONArray contactsJsonArray = (JSONArray) softwareStatementClaims.getClaim(SSAClaims.ORG_CONTACTS);
    if (contactsJsonArray != null) {
        for (Object contactJson : contactsJsonArray) {
            JSONObject contactJsonObject = ((JSONObject) contactJson);
            OrganisationContact orgContact = OrganisationContact.builder().name(getContactField(contactJsonObject, "name")).email(getContactField(contactJsonObject, "email")).type(getContactField(contactJsonObject, "type")).phone(getContactField(contactJsonObject, "phone")).build();
            contacts.add(orgContact);
        }
    } else {
        String errorString = "No " + SSAClaims.ORG_CONTACTS + " field available from Software Statement";
        log.info("getOrgContacts() {}", errorString);
    }
    return contacts;
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(com.nimbusds.jose.shaded.json.JSONArray) JSONObject(com.nimbusds.jose.shaded.json.JSONObject)

Example 2 with JSONArray

use of com.nimbusds.jose.shaded.json.JSONArray in project openbanking-aspsp by OpenBankingToolkit.

the class DirectorySoftwareStatementFactory method getAuthorizations.

private List<AuthorisationClaim> getAuthorizations(JSONObject contactsJsonArray) throws ParseException {
    List<AuthorisationClaim> authClaims = new ArrayList<>();
    JSONArray authorityClaims = (JSONArray) contactsJsonArray.get(SSAClaims.OCAC_AUTHORISATIONS);
    for (Object authorityClaim : authorityClaims) {
        JSONObject authorityClaimJson = (JSONObject) authorityClaim;
        AuthorisationClaim authClaim = AuthorisationClaim.builder().member_state(JSONObjectUtils.getString(authorityClaimJson, SSAClaims.OCAC_MEMBER_STATE)).roles(JSONObjectUtils.getStringList(authorityClaimJson, SSAClaims.OCAC_ROLES)).build();
        authClaims.add(authClaim);
    }
    return authClaims;
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject) ArrayList(java.util.ArrayList) JSONArray(com.nimbusds.jose.shaded.json.JSONArray) JSONObject(com.nimbusds.jose.shaded.json.JSONObject)

Example 3 with JSONArray

use of com.nimbusds.jose.shaded.json.JSONArray in project oauth2-server by gw2auth.

the class TestHelper method createSubtokenJWT.

public static String createSubtokenJWT(UUID sub, Set<Gw2ApiPermission> permissions, Instant issuedAt, Duration expiresIn) {
    final JSONArray jsonPermissions = new JSONArray();
    permissions.stream().map(Gw2ApiPermission::gw2).forEach(jsonPermissions::add);
    JWTClaimsSet claims = new JWTClaimsSet.Builder().subject(sub.toString()).jwtID(UUID.randomUUID().toString()).issueTime(new Date(issuedAt.toEpochMilli())).expirationTime(new Date(issuedAt.plus(expiresIn).toEpochMilli())).claim("permissions", jsonPermissions).build();
    final SignedJWT signedJWT = new SignedJWT(new JWSHeader(JWSAlgorithm.HS256, JOSEObjectType.JWT, null, null, null, null, null, null, null, null, null, true, null, null), claims);
    try {
        signedJWT.sign(new MACSigner(new byte[32]));
    } catch (JOSEException e) {
        throw new RuntimeException(e);
    }
    return signedJWT.serialize();
}
Also used : MACSigner(com.nimbusds.jose.crypto.MACSigner) JWTClaimsSet(com.nimbusds.jwt.JWTClaimsSet) JSONArray(com.nimbusds.jose.shaded.json.JSONArray) SignedJWT(com.nimbusds.jwt.SignedJWT) JOSEException(com.nimbusds.jose.JOSEException) JWSHeader(com.nimbusds.jose.JWSHeader)

Example 4 with JSONArray

use of com.nimbusds.jose.shaded.json.JSONArray in project spring-addons by ch4mpy.

the class SpringAddonsSecurityProperties method getRoles.

private static Stream<String> getRoles(Map<String, Object> claims, String rolesPath) {
    final var claimsToWalk = rolesPath.split("\\.");
    var i = 0;
    var obj = Optional.of(claims);
    while (i++ < claimsToWalk.length) {
        final var claimName = claimsToWalk[i - 1];
        if (i == claimsToWalk.length) {
            return obj.map(o -> (JSONArray) o.get(claimName)).orElse(new JSONArray()).stream().map(Object::toString);
        }
        obj = obj.map(o -> (JSONObject) o.get(claimName));
    }
    return Stream.empty();
}
Also used : OidcServletApiSecurityConfig(com.c4_soft.springaddons.security.oauth2.config.synchronised.OidcServletApiSecurityConfig) JSONObject(com.nimbusds.jose.shaded.json.JSONObject) OidcReactiveApiSecurityConfig(com.c4_soft.springaddons.security.oauth2.config.reactive.OidcReactiveApiSecurityConfig) SimpleGrantedAuthority(org.springframework.security.core.authority.SimpleGrantedAuthority) ConfigurationProperties(org.springframework.boot.context.properties.ConfigurationProperties) StandardCharsets(java.nio.charset.StandardCharsets) GrantedAuthority(org.springframework.security.core.GrantedAuthority) Configuration(org.springframework.context.annotation.Configuration) Stream(java.util.stream.Stream) Charset(java.nio.charset.Charset) Map(java.util.Map) Data(lombok.Data) Optional(java.util.Optional) JSONArray(com.nimbusds.jose.shaded.json.JSONArray) JSONObject(com.nimbusds.jose.shaded.json.JSONObject) JSONArray(com.nimbusds.jose.shaded.json.JSONArray) JSONObject(com.nimbusds.jose.shaded.json.JSONObject)

Example 5 with JSONArray

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

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)

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