Fix muti-tenancy whitespace
This commit is contained in:
parent
14b32590e9
commit
80f17ae566
|
@ -55,8 +55,7 @@ public class OAuth2ResourceServerApplicationITests {
|
|||
MockMvc mvc;
|
||||
|
||||
@Test
|
||||
void tenantOnePerformWhenValidBearerTokenThenAllows()
|
||||
throws Exception {
|
||||
void tenantOnePerformWhenValidBearerTokenThenAllows() throws Exception {
|
||||
|
||||
// @formatter:off
|
||||
this.mvc.perform(get("/tenantOne").with(bearerToken(this.tenantOneNoScopesToken)))
|
||||
|
@ -66,8 +65,7 @@ public class OAuth2ResourceServerApplicationITests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void tenantOnePerformWhenValidBearerTokenWithServletPathThenAllows()
|
||||
throws Exception {
|
||||
void tenantOnePerformWhenValidBearerTokenWithServletPathThenAllows() throws Exception {
|
||||
|
||||
// @formatter:off
|
||||
this.mvc.perform(get("/tenantOne").servletPath("/tenantOne").with(bearerToken(this.tenantOneNoScopesToken)))
|
||||
|
@ -79,8 +77,7 @@ public class OAuth2ResourceServerApplicationITests {
|
|||
// -- tests with scopes
|
||||
|
||||
@Test
|
||||
void tenantOnePerformWhenValidBearerTokenThenScopedRequestsAlsoWork()
|
||||
throws Exception {
|
||||
void tenantOnePerformWhenValidBearerTokenThenScopedRequestsAlsoWork() throws Exception {
|
||||
|
||||
// @formatter:off
|
||||
this.mvc.perform(get("/tenantOne/message").with(bearerToken(this.tenantOneMessageReadToken)))
|
||||
|
@ -90,8 +87,7 @@ public class OAuth2ResourceServerApplicationITests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void tenantOnePerformWhenInsufficientlyScopedBearerTokenThenDeniesScopedMethodAccess()
|
||||
throws Exception {
|
||||
void tenantOnePerformWhenInsufficientlyScopedBearerTokenThenDeniesScopedMethodAccess() throws Exception {
|
||||
|
||||
// @formatter:off
|
||||
this.mvc.perform(get("/tenantOne/message").with(bearerToken(this.tenantOneNoScopesToken)))
|
||||
|
@ -102,8 +98,7 @@ public class OAuth2ResourceServerApplicationITests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void tenantTwoPerformWhenValidBearerTokenThenAllows()
|
||||
throws Exception {
|
||||
void tenantTwoPerformWhenValidBearerTokenThenAllows() throws Exception {
|
||||
|
||||
// @formatter:off
|
||||
this.mvc.perform(get("/tenantTwo").with(bearerToken(this.tenantTwoNoScopesToken)))
|
||||
|
@ -115,8 +110,7 @@ public class OAuth2ResourceServerApplicationITests {
|
|||
// -- tests with scopes
|
||||
|
||||
@Test
|
||||
void tenantTwoPerformWhenValidBearerTokenThenScopedRequestsAlsoWork()
|
||||
throws Exception {
|
||||
void tenantTwoPerformWhenValidBearerTokenThenScopedRequestsAlsoWork() throws Exception {
|
||||
|
||||
// @formatter:off
|
||||
this.mvc.perform(get("/tenantTwo/message").with(bearerToken(this.tenantTwoMessageReadToken)))
|
||||
|
@ -126,8 +120,7 @@ public class OAuth2ResourceServerApplicationITests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void tenantTwoPerformWhenInsufficientlyScopedBearerTokenThenDeniesScopedMethodAccess()
|
||||
throws Exception {
|
||||
void tenantTwoPerformWhenInsufficientlyScopedBearerTokenThenDeniesScopedMethodAccess() throws Exception {
|
||||
|
||||
// @formatter:off
|
||||
this.mvc.perform(get("/tenantTwo/message").with(bearerToken(this.tenantTwoNoScopesToken)))
|
||||
|
@ -138,8 +131,7 @@ public class OAuth2ResourceServerApplicationITests {
|
|||
}
|
||||
|
||||
@Test
|
||||
void invalidTenantPerformWhenValidBearerTokenThenThrowsException()
|
||||
throws Exception {
|
||||
void invalidTenantPerformWhenValidBearerTokenThenThrowsException() throws Exception {
|
||||
|
||||
// @formatter:off
|
||||
assertThatIllegalArgumentException()
|
||||
|
@ -155,6 +147,7 @@ public class OAuth2ResourceServerApplicationITests {
|
|||
}
|
||||
|
||||
private static class BearerTokenRequestPostProcessor implements RequestPostProcessor {
|
||||
|
||||
private String token;
|
||||
|
||||
BearerTokenRequestPostProcessor(String token) {
|
||||
|
@ -166,5 +159,7 @@ public class OAuth2ResourceServerApplicationITests {
|
|||
request.addHeader("Authorization", "Bearer " + this.token);
|
||||
return request;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||
|
||||
/**
|
||||
* OAuth Resource Server application.
|
||||
*
|
||||
* @author Josh Cummings
|
||||
*/
|
||||
@SpringBootApplication
|
||||
|
@ -28,4 +29,5 @@ public class OAuth2ResourceServerApplication {
|
|||
public static void main(String[] args) {
|
||||
SpringApplication.run(OAuth2ResourceServerApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -23,13 +23,15 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
|
||||
/**
|
||||
* A controller demonstrating OAuth2 Resource server.
|
||||
*
|
||||
* @author Josh Cummings
|
||||
*/
|
||||
@RestController
|
||||
public class OAuth2ResourceServerController {
|
||||
|
||||
@GetMapping("/{tenantId}")
|
||||
public String index(@AuthenticationPrincipal OAuth2AuthenticatedPrincipal token, @PathVariable("tenantId") String tenantId) {
|
||||
public String index(@AuthenticationPrincipal OAuth2AuthenticatedPrincipal token,
|
||||
@PathVariable("tenantId") String tenantId) {
|
||||
String subject = token.getAttribute("sub");
|
||||
return String.format("Hello, %s for %s!", subject, tenantId);
|
||||
}
|
||||
|
@ -38,4 +40,5 @@ public class OAuth2ResourceServerController {
|
|||
public String message(@PathVariable("tenantId") String tenantId) {
|
||||
return String.format("secret message for %s", tenantId);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,6 +38,7 @@ import org.springframework.security.oauth2.server.resource.introspection.OpaqueT
|
|||
|
||||
/**
|
||||
* OAuth Resource Security configuration.
|
||||
*
|
||||
* @author Josh Cummings
|
||||
*/
|
||||
@EnableWebSecurity
|
||||
|
@ -93,9 +94,9 @@ public class OAuth2ResourceServerSecurityConfiguration extends WebSecurityConfig
|
|||
}
|
||||
|
||||
AuthenticationManager opaque() {
|
||||
OpaqueTokenIntrospector introspectionClient =
|
||||
new NimbusOpaqueTokenIntrospector(this.introspectionUri,
|
||||
this.introspectionClientId, this.introspectionClientSecret);
|
||||
OpaqueTokenIntrospector introspectionClient = new NimbusOpaqueTokenIntrospector(this.introspectionUri,
|
||||
this.introspectionClientId, this.introspectionClientSecret);
|
||||
return new OpaqueTokenAuthenticationProvider(introspectionClient)::authenticate;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -22,16 +22,15 @@ import org.springframework.core.env.ConfigurableEnvironment;
|
|||
|
||||
/**
|
||||
* Adds {@link MockWebServerPropertySource} to the environment.
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
public class MockWebServerEnvironmentPostProcessor
|
||||
implements EnvironmentPostProcessor, DisposableBean {
|
||||
public class MockWebServerEnvironmentPostProcessor implements EnvironmentPostProcessor, DisposableBean {
|
||||
|
||||
private final MockWebServerPropertySource propertySource = new MockWebServerPropertySource();
|
||||
|
||||
@Override
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment,
|
||||
SpringApplication application) {
|
||||
public void postProcessEnvironment(ConfigurableEnvironment environment, SpringApplication application) {
|
||||
environment.getPropertySources().addFirst(this.propertySource);
|
||||
}
|
||||
|
||||
|
@ -39,4 +38,5 @@ public class MockWebServerEnvironmentPostProcessor
|
|||
public void destroy() throws Exception {
|
||||
this.propertySource.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,10 +38,10 @@ import org.springframework.http.MediaType;
|
|||
|
||||
/**
|
||||
* Adds the mock server url.
|
||||
*
|
||||
* @author Rob Winch
|
||||
*/
|
||||
public class MockWebServerPropertySource extends PropertySource<MockWebServer> implements
|
||||
DisposableBean {
|
||||
public class MockWebServerPropertySource extends PropertySource<MockWebServer> implements DisposableBean {
|
||||
|
||||
// introspection endpoint
|
||||
|
||||
|
|
Loading…
Reference in New Issue