Fix OAuth2 multitenancy sample

Allowing requests with valid tokens, and fixed documentation.

Fixes: gh-6834
This commit is contained in:
Eleftheria Stein
2019-05-02 16:21:10 -04:00
committed by Josh Cummings
parent 5aa50500cf
commit c4b6cdea3f
3 changed files with 86 additions and 12 deletions

View File

@@ -65,8 +65,10 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
authenticationManagers.put("tenantOne", jwt());
authenticationManagers.put("tenantTwo", opaque());
return request -> {
String tenantId = request.getPathInfo().split("/")[1];
return Optional.ofNullable(authenticationManagers.get(tenantId))
String[] pathParts = request.getRequestURI().split("/");
String tenantId = pathParts.length > 0 ? pathParts[1] : null;
return Optional.ofNullable(tenantId)
.map(authenticationManagers::get)
.orElseThrow(() -> new IllegalArgumentException("unknown tenant"));
};
}