Multi-tenancy Sample AuthenticationManagers

Fixes gh-7272
This commit is contained in:
Josh Cummings 2019-08-17 00:13:34 -06:00
parent efe8205985
commit 0ecffb0840
No known key found for this signature in database
GPG Key ID: 49EF60DD7FF83443
3 changed files with 22 additions and 32 deletions

View File

@ -128,33 +128,20 @@ _In order to use this sample, your Authorization Server must support JWTs that e
To change the sample to point at your Authorization Server, simply find these properties in the `application.yml`: To change the sample to point at your Authorization Server, simply find these properties in the `application.yml`:
```yaml ```yaml
spring: tenantOne.jwk-set-uri: ${mockwebserver.url}/.well-known/jwks.json
security: tenantTwo.introspection-uri: ${mockwebserver.url}/introspect
oauth2: tenantTwo.introspection-client-id: client
resourceserver: tenantTwo.introspection-client-secret: secret
jwt:
jwk-set-uri: ${mockwebserver.url}/.well-known/jwks.json
opaque:
introspection-uri: ${mockwebserver.url}/introspect
introspection-client-id: client
introspection-client-secret: secret
``` ```
And change the properties to your Authorization Server's JWK set endpoint and And change the properties to your Authorization Server's JWK set endpoint and
introspection endpoint, including its client id and secret introspection endpoint, including its client id and secret
```yaml ```yaml
spring: tenantOne.jwk-set-uri: https://dev-123456.oktapreview.com/oauth2/default/v1/keys
security: tenantTwo.introspection-uri: https://dev-123456.oktapreview.com/oauth2/default/v1/introspect
oauth2: tenantTwo.introspection-client-id: client
resourceserver: tenantTwo.introspection-client-secret: secret
jwt:
jwk-set-uri: https://dev-123456.oktapreview.com/oauth2/default/v1/keys
opaque:
introspection-uri: https://dev-123456.oktapreview.com/oauth2/default/v1/introspect
introspection-client-id: client
introspection-client-secret: secret
``` ```
And then you can run the app the same as before: And then you can run the app the same as before:

View File

@ -40,12 +40,18 @@ import org.springframework.security.oauth2.server.resource.introspection.OpaqueT
@EnableWebSecurity @EnableWebSecurity
public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter { public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfigurerAdapter {
@Value("${spring.security.oauth2.resourceserver.jwt.jwk-set-uri}") @Value("${tenantOne.jwk-set-uri}")
String jwkSetUri; String jwkSetUri;
@Value("${spring.security.oauth2.resourceserver.opaque.introspection-uri}") @Value("${tenantTwo.introspection-uri}")
String introspectionUri; String introspectionUri;
@Value("${tenantTwo.introspection-client-id}")
String introspectionClientId;
@Value("${tenantTwo.introspection-client-secret}")
String introspectionClientSecret;
@Override @Override
protected void configure(HttpSecurity http) throws Exception { protected void configure(HttpSecurity http) throws Exception {
// @formatter:off // @formatter:off
@ -83,7 +89,8 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
AuthenticationManager opaque() { AuthenticationManager opaque() {
OpaqueTokenIntrospector introspectionClient = OpaqueTokenIntrospector introspectionClient =
new NimbusOpaqueTokenIntrospector(this.introspectionUri, "client", "secret"); new NimbusOpaqueTokenIntrospector(this.introspectionUri,
this.introspectionClientId, this.introspectionClientSecret);
return new OAuth2IntrospectionAuthenticationProvider(introspectionClient)::authenticate; return new OAuth2IntrospectionAuthenticationProvider(introspectionClient)::authenticate;
} }
} }

View File

@ -1,8 +1,4 @@
spring: tenantOne.jwk-set-uri: ${mockwebserver.url}/.well-known/jwks.json
security: tenantTwo.introspection-uri: ${mockwebserver.url}/introspect
oauth2: tenantTwo.introspection-client-id: client
resourceserver: tenantTwo.introspection-client-secret: secret
jwt:
jwk-set-uri: ${mockwebserver.url}/.well-known/jwks.json
opaque:
introspection-uri: ${mockwebserver.url}/introspect