@Test public void testExtractAudiencesFromTokenScopes() { Jwt token = new JwtGenerator() .addScopes("test1!t1.read", "test2!t1.read", "test2!t1.write", ".scopeWithoutAppId").getToken(); Set<String> audiences = XsuaaAudienceValidator.getAllowedAudiences(token); Assert.assertThat(audiences.size(), is(2)); Assert.assertThat(audiences, hasItem("test1!t1")); Assert.assertThat(audiences, hasItem("test2!t1")); }
static Set<String> getAllowedAudiences(Jwt token) { final Set<String> allAudiences = new HashSet<>(); final List<String> tokenAudiences = token.getAudience(); if (tokenAudiences != null) { for (String audience : tokenAudiences) { final String aud = audience.contains(".") ? audience.substring(0, audience.indexOf('.')) : audience; allAudiences.add(aud); } } if (allAudiences.isEmpty()) { for (String scope : getScopes(token)) { if (scope.contains(".")) { final String aud = scope.substring(0, scope.indexOf('.')); allAudiences.add(aud); } } } allAudiences.remove(""); return allAudiences; }
XsuaaAudienceValidator implements OAuth2TokenValidator<Jwt> { static Set<String> getAllowedAudiences(Jwt token) { final Set<String> allAudiences = new HashSet<>(); final List<String> tokenAudiences = token.getAudience(); if (tokenAudiences != null) { for (String audience : tokenAudiences) { final String aud = audience.contains(".") ? audience.substring(0, audience.indexOf('.')) : audience; allAudiences.add(aud); } } if (allAudiences.isEmpty()) { for (String scope : getScopes(token)) { if (scope.contains(".")) { final String aud = scope.substring(0, scope.indexOf('.')); allAudiences.add(aud); } } } allAudiences.remove(""); return allAudiences; } }
XsuaaAudienceValidator implements OAuth2TokenValidator<Jwt> { static Set<String> getAllowedAudiences(Jwt token) { final Set<String> allAudiences = new HashSet<>(); final List<String> tokenAudiences = token.getAudience(); if (tokenAudiences != null) { for (String audience : tokenAudiences) { final String aud = audience.contains(".") ? audience.substring(0, audience.indexOf('.')) : audience; allAudiences.add(aud); } } if (allAudiences.isEmpty()) { for (String scope : getScopes(token)) { if (scope.contains(".")) { final String aud = scope.substring(0, scope.indexOf('.')); allAudiences.add(aud); } } } allAudiences.remove(""); return allAudiences; } XsuaaAudienceValidator(XsuaaServiceConfiguration xsuaaServiceConfiguration); }
XsuaaAudienceValidator implements OAuth2TokenValidator<Jwt> { static Set<String> getAllowedAudiences(Jwt token) { final Set<String> allAudiences = new HashSet<>(); final List<String> tokenAudiences = token.getAudience(); if (tokenAudiences != null) { for (String audience : tokenAudiences) { final String aud = audience.contains(".") ? audience.substring(0, audience.indexOf('.')) : audience; allAudiences.add(aud); } } if (allAudiences.isEmpty()) { for (String scope : getScopes(token)) { if (scope.contains(".")) { final String aud = scope.substring(0, scope.indexOf('.')); allAudiences.add(aud); } } } allAudiences.remove(""); return allAudiences; } XsuaaAudienceValidator(XsuaaServiceConfiguration xsuaaServiceConfiguration); void configureAnotherXsuaaInstance(String appId, String clientId); @Override OAuth2TokenValidatorResult validate(Jwt token); }
XsuaaAudienceValidator implements OAuth2TokenValidator<Jwt> { static Set<String> getAllowedAudiences(Jwt token) { final Set<String> allAudiences = new HashSet<>(); final List<String> tokenAudiences = token.getAudience(); if (tokenAudiences != null) { for (String audience : tokenAudiences) { final String aud = audience.contains(".") ? audience.substring(0, audience.indexOf('.')) : audience; allAudiences.add(aud); } } if (allAudiences.isEmpty()) { for (String scope : getScopes(token)) { if (scope.contains(".")) { final String aud = scope.substring(0, scope.indexOf('.')); allAudiences.add(aud); } } } allAudiences.remove(""); return allAudiences; } XsuaaAudienceValidator(XsuaaServiceConfiguration xsuaaServiceConfiguration); void configureAnotherXsuaaInstance(String appId, String clientId); @Override OAuth2TokenValidatorResult validate(Jwt token);  }