@Test public void encodeDecodeUrlSafe() { byte[] bytes = new byte[] { (byte) 0xfb, (byte) 0xf0 }; assertArrayEquals("-_A=".getBytes(), Base64Utils.encodeUrlSafe(bytes)); assertArrayEquals(bytes, Base64Utils.decodeUrlSafe(Base64Utils.encodeUrlSafe(bytes))); assertEquals("-_A=", Base64Utils.encodeToUrlSafeString(bytes)); assertArrayEquals(bytes, Base64Utils.decodeFromUrlSafeString(Base64Utils.encodeToUrlSafeString(bytes))); }
public byte[] getSignature() { return Base64Utils.decodeFromUrlSafeString(this.signature); }
public UaaUser(ObjectMapper objectMapper, String jwtAccessToken) { String payload = jwtAccessToken.split("\\.")[1]; try { JsonNode json = objectMapper.readValue( Base64Utils.decodeFromUrlSafeString(payload), JsonNode.class); log.debug("Payload of accessToken = {}", json); this.userId = json.get("user_id").asText(); this.email = json.get("email").asText(); this.displayName = json.get("display_name").asText(); Set<String> scope = new LinkedHashSet<>(); if (json.has("scope")) { for (JsonNode node : json.get("scope")) { scope.add(node.asText()); } } this.scope = Collections.unmodifiableSet(scope); Set<String> authorities = new LinkedHashSet<>(); if (json.has("authorities")) { for (JsonNode node : json.get("authorities")) { authorities.add(node.asText()); } } this.authorities = Collections.unmodifiableSet(authorities); } catch (IOException e) { throw new UncheckedIOException(e); } }
private Map<String, Object> parseJson(String base64) { try { byte[] bytes = Base64Utils.decodeFromUrlSafeString(base64); return JsonParserFactory.getJsonParser() .parseMap(new String(bytes, StandardCharsets.UTF_8)); } catch (RuntimeException ex) { throw new CloudFoundryAuthorizationException(Reason.INVALID_TOKEN, "Token could not be parsed", ex); } }