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;
}
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"));
}
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());
}
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);
}
}
}
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);
}
Aggregations