From 80f17ae566df9631f1439738f410f8cd4736dcdd Mon Sep 17 00:00:00 2001 From: Rob Winch Date: Thu, 27 Aug 2020 14:19:55 -0500 Subject: [PATCH] Fix muti-tenancy whitespace --- ...OAuth2ResourceServerApplicationITests.java | 27 ++++++++----------- .../OAuth2ResourceServerApplication.java | 2 ++ .../OAuth2ResourceServerController.java | 5 +++- ...h2ResourceServerSecurityConfiguration.java | 7 ++--- ...MockWebServerEnvironmentPostProcessor.java | 8 +++--- .../boot/env/MockWebServerPropertySource.java | 4 +-- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/integTest/java/example/OAuth2ResourceServerApplicationITests.java b/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/integTest/java/example/OAuth2ResourceServerApplicationITests.java index 929e3a6..205acd3 100644 --- a/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/integTest/java/example/OAuth2ResourceServerApplicationITests.java +++ b/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/integTest/java/example/OAuth2ResourceServerApplicationITests.java @@ -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; } + } + } diff --git a/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/example/OAuth2ResourceServerApplication.java b/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/example/OAuth2ResourceServerApplication.java index 77dbb2f..af55f05 100644 --- a/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/example/OAuth2ResourceServerApplication.java +++ b/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/example/OAuth2ResourceServerApplication.java @@ -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); } + } diff --git a/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/example/OAuth2ResourceServerController.java b/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/example/OAuth2ResourceServerController.java index 06676ef..5388654 100644 --- a/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/example/OAuth2ResourceServerController.java +++ b/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/example/OAuth2ResourceServerController.java @@ -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); } + } diff --git a/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/example/OAuth2ResourceServerSecurityConfiguration.java b/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/example/OAuth2ResourceServerSecurityConfiguration.java index 09dfb7a..bc00c44 100644 --- a/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/example/OAuth2ResourceServerSecurityConfiguration.java +++ b/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/example/OAuth2ResourceServerSecurityConfiguration.java @@ -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; } + } diff --git a/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/org/springframework/boot/env/MockWebServerEnvironmentPostProcessor.java b/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/org/springframework/boot/env/MockWebServerEnvironmentPostProcessor.java index 635a770..09ae36f 100644 --- a/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/org/springframework/boot/env/MockWebServerEnvironmentPostProcessor.java +++ b/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/org/springframework/boot/env/MockWebServerEnvironmentPostProcessor.java @@ -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(); } + } diff --git a/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/org/springframework/boot/env/MockWebServerPropertySource.java b/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/org/springframework/boot/env/MockWebServerPropertySource.java index 53221ab..2297f02 100644 --- a/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/org/springframework/boot/env/MockWebServerPropertySource.java +++ b/servlet/spring-boot/java/oauth2/resource-server/multi-tenancy/src/main/java/org/springframework/boot/env/MockWebServerPropertySource.java @@ -38,10 +38,10 @@ import org.springframework.http.MediaType; /** * Adds the mock server url. + * * @author Rob Winch */ -public class MockWebServerPropertySource extends PropertySource implements - DisposableBean { +public class MockWebServerPropertySource extends PropertySource implements DisposableBean { // introspection endpoint