use of com.nimbusds.jose.shaded.json.JSONArray in project PowerNukkitX by BlocklyNukkit.
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 GeyserConnect by GeyserMC.
the class PacketHandler method handle.
@Override
public boolean handle(LoginPacket packet) {
masterServer.getLogger().debug("Login: " + packet.toString());
BedrockPacketCodec packetCodec = MinecraftProtocol.getBedrockCodec(packet.getProtocolVersion());
if (packetCodec == null) {
session.setPacketCodec(MinecraftProtocol.DEFAULT_BEDROCK_CODEC);
String message = "disconnectionScreen.internalError.cantConnect";
PlayStatusPacket status = new PlayStatusPacket();
if (packet.getProtocolVersion() > MinecraftProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()) {
status.setStatus(PlayStatusPacket.Status.LOGIN_FAILED_SERVER_OLD);
message = "disconnectionScreen.outdatedServer";
} else if (packet.getProtocolVersion() < MinecraftProtocol.DEFAULT_BEDROCK_CODEC.getProtocolVersion()) {
status.setStatus(PlayStatusPacket.Status.LOGIN_FAILED_CLIENT_OLD);
message = "disconnectionScreen.outdatedClient";
}
session.sendPacket(status);
session.disconnect(message);
return false;
}
// Set the session codec
session.setPacketCodec(packetCodec);
// Read the raw chain data
JsonNode rawChainData;
try {
rawChainData = OBJECT_MAPPER.readTree(packet.getChainData().toByteArray());
} catch (IOException e) {
throw new AssertionError("Unable to read chain data!");
}
// Get the parsed chain data
JsonNode chainData = rawChainData.get("chain");
if (chainData.getNodeType() != JsonNodeType.ARRAY) {
throw new AssertionError("Invalid chain data!");
}
try {
// Convert the chainData to a JSONArray
ObjectReader reader = OBJECT_MAPPER.readerFor(new TypeReference<List<String>>() {
});
JSONArray array = new JSONArray();
array.addAll(reader.readValue(chainData));
// Verify the chain data
if (!EncryptionUtils.verifyChain(array)) {
// Disconnect the client
session.disconnect("disconnectionScreen.internalError.cantConnect");
throw new AssertionError("Failed to login, due to invalid chain data!");
}
// Parse the signed jws object
JWSObject jwsObject;
jwsObject = JWSObject.parse(chainData.get(chainData.size() - 1).asText());
// Read the JWS payload
JsonNode payload = OBJECT_MAPPER.readTree(jwsObject.getPayload().toBytes());
// Check the identityPublicKey is there
if (payload.get("identityPublicKey").getNodeType() != JsonNodeType.STRING) {
throw new AssertionError("Missing identity public key!");
}
// Create an ECPublicKey from the identityPublicKey
ECPublicKey identityPublicKey = EncryptionUtils.generateKey(payload.get("identityPublicKey").textValue());
// Get the skin data to validate the JWS token
JWSObject skinData = JWSObject.parse(packet.getSkinData().toString());
if (skinData.verify(new DefaultJWSVerifierFactory().createJWSVerifier(skinData.getHeader(), identityPublicKey))) {
// Make sure the client sent over the username, xuid and other info
if (payload.get("extraData").getNodeType() != JsonNodeType.OBJECT) {
throw new AssertionError("Missing client data");
}
// Fetch the client data
JsonNode extraData = payload.get("extraData");
AuthData authData = new AuthData(extraData.get("displayName").asText(), UUID.fromString(extraData.get("identity").asText()), extraData.get("XUID").asText());
// Create a new player and add it to the players list
player = new Player(authData, session);
masterServer.getPlayers().add(player);
player.setChainData(chainData);
// Store the full client data
player.setClientData(OBJECT_MAPPER.convertValue(OBJECT_MAPPER.readTree(skinData.getPayload().toBytes()), BedrockClientData.class));
player.getClientData().setOriginalString(packet.getSkinData().toString());
// Tell the client we have logged in successfully
PlayStatusPacket playStatusPacket = new PlayStatusPacket();
playStatusPacket.setStatus(PlayStatusPacket.Status.LOGIN_SUCCESS);
session.sendPacket(playStatusPacket);
// Tell the client there are no resourcepacks
ResourcePacksInfoPacket resourcePacksInfo = new ResourcePacksInfoPacket();
session.sendPacket(resourcePacksInfo);
} else {
throw new AssertionError("Invalid identity public key!");
}
} catch (Exception e) {
// Disconnect the client
session.disconnect("disconnectionScreen.internalError.cantConnect");
throw new AssertionError("Failed to login", e);
}
return false;
}
use of com.nimbusds.jose.shaded.json.JSONArray 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);
}
use of com.nimbusds.jose.shaded.json.JSONArray in project itpark2021 by vitr1988.
the class JwtHelper method parseToken.
@SneakyThrows
public AuthorizedUser parseToken(String token) {
if (StringUtils.isEmpty(token)) {
return null;
}
final JWTClaimsSet jwtClaims;
final SignedJWT decodedJWT = SignedJWT.parse(token);
if (decodedJWT.verify(jwsVerifier) && isValid(jwtClaims = decodedJWT.getJWTClaimsSet())) {
final String login = this.<String>getClaim(jwtClaims, "login").filter(StringUtils::isNotEmpty).orElseThrow();
final String[] userRights = this.<JSONArray>getClaim(jwtClaims, "rights").map(list -> list.stream().toArray(String[]::new)).orElse(new String[] {});
return new AuthorizedUser(login, userRights);
}
throw new IllegalArgumentException();
}
Aggregations