Search in sources :

Example 6 with JSONObject

use of com.nimbusds.jose.shaded.json.JSONObject in project Protocol by CloudburstMC.

the class SerializedSkin method validateSkinResourcePatch.

private static boolean validateSkinResourcePatch(String skinResourcePatch) {
    try {
        JSONObject object = (JSONObject) JSONValue.parse(skinResourcePatch);
        JSONObject geometry = (JSONObject) object.get("geometry");
        return geometry.containsKey("default") && geometry.get("default") instanceof String;
    } catch (ClassCastException | NullPointerException e) {
        return false;
    }
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject)

Example 7 with JSONObject

use of com.nimbusds.jose.shaded.json.JSONObject 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 8 with JSONObject

use of com.nimbusds.jose.shaded.json.JSONObject 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)

Example 9 with JSONObject

use of com.nimbusds.jose.shaded.json.JSONObject 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 10 with JSONObject

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

the class Skin method isValidResourcePatch.

private boolean isValidResourcePatch() {
    if (skinResourcePatch == null || skinResourcePatch.length() > 1000) {
        return false;
    }
    try {
        JSONObject object = (JSONObject) JSONValue.parse(skinResourcePatch);
        JSONObject geometry = (JSONObject) object.get("geometry");
        return geometry.containsKey("default") && geometry.get("default") instanceof String;
    } catch (ClassCastException | NullPointerException e) {
        return false;
    }
}
Also used : JSONObject(com.nimbusds.jose.shaded.json.JSONObject) ToString(lombok.ToString)

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