diff --git a/samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/OAuth2AuthorizationServerApplication.java b/samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/authorizationserver/OAuth2AuthorizationServerApplication.java similarity index 96% rename from samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/OAuth2AuthorizationServerApplication.java rename to samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/authorizationserver/OAuth2AuthorizationServerApplication.java index 3bdedcc3..44080f41 100644 --- a/samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/OAuth2AuthorizationServerApplication.java +++ b/samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/authorizationserver/OAuth2AuthorizationServerApplication.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package sample; +package sample.authorizationserver; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/config/AuthorizationServerConfig.java b/samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/authorizationserver/config/AuthorizationServerConfig.java similarity index 98% rename from samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/config/AuthorizationServerConfig.java rename to samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/authorizationserver/config/AuthorizationServerConfig.java index 6a95cebf..95529057 100644 --- a/samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/config/AuthorizationServerConfig.java +++ b/samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/authorizationserver/config/AuthorizationServerConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package sample.config; +package sample.authorizationserver.config; import java.util.UUID; diff --git a/samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/config/DefaultSecurityConfig.java b/samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/authorizationserver/config/DefaultSecurityConfig.java similarity index 97% rename from samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/config/DefaultSecurityConfig.java rename to samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/authorizationserver/config/DefaultSecurityConfig.java index 9d569197..27cadbf7 100644 --- a/samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/config/DefaultSecurityConfig.java +++ b/samples/boot/oauth2-integration/authorizationserver/src/main/java/sample/authorizationserver/config/DefaultSecurityConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package sample.config; +package sample.authorizationserver.config; import org.springframework.context.annotation.Bean; import org.springframework.security.config.annotation.web.builders.HttpSecurity; diff --git a/samples/boot/oauth2-integration/client/spring-security-samples-boot-oauth2-integrated-client.gradle b/samples/boot/oauth2-integration/client/spring-security-samples-boot-oauth2-integrated-client.gradle index 4758bd08..55c389df 100644 --- a/samples/boot/oauth2-integration/client/spring-security-samples-boot-oauth2-integrated-client.gradle +++ b/samples/boot/oauth2-integration/client/spring-security-samples-boot-oauth2-integrated-client.gradle @@ -11,4 +11,7 @@ dependencies { compile 'org.webjars:webjars-locator-core' compile 'org.webjars:bootstrap:3.4.1' compile 'org.webjars:jquery:3.4.1' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation project(':spring-security-samples-boot-oauth2-integrated-authorizationserver') + testImplementation project(':spring-security-samples-boot-oauth2-integrated-resourceserver') } diff --git a/samples/boot/oauth2-integration/client/src/main/java/sample/OAuth2ClientApplication.java b/samples/boot/oauth2-integration/client/src/main/java/sample/client/OAuth2ClientApplication.java similarity index 97% rename from samples/boot/oauth2-integration/client/src/main/java/sample/OAuth2ClientApplication.java rename to samples/boot/oauth2-integration/client/src/main/java/sample/client/OAuth2ClientApplication.java index 5b0dc8c9..982da5bc 100644 --- a/samples/boot/oauth2-integration/client/src/main/java/sample/OAuth2ClientApplication.java +++ b/samples/boot/oauth2-integration/client/src/main/java/sample/client/OAuth2ClientApplication.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package sample; +package sample.client; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/samples/boot/oauth2-integration/client/src/main/java/sample/config/SecurityConfig.java b/samples/boot/oauth2-integration/client/src/main/java/sample/client/config/SecurityConfig.java similarity index 98% rename from samples/boot/oauth2-integration/client/src/main/java/sample/config/SecurityConfig.java rename to samples/boot/oauth2-integration/client/src/main/java/sample/client/config/SecurityConfig.java index f08964cc..2d12c06e 100644 --- a/samples/boot/oauth2-integration/client/src/main/java/sample/config/SecurityConfig.java +++ b/samples/boot/oauth2-integration/client/src/main/java/sample/client/config/SecurityConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package sample.config; +package sample.client.config; import org.springframework.context.annotation.Bean; import org.springframework.security.config.annotation.web.builders.HttpSecurity; diff --git a/samples/boot/oauth2-integration/client/src/main/java/sample/config/WebClientConfig.java b/samples/boot/oauth2-integration/client/src/main/java/sample/client/config/WebClientConfig.java similarity index 98% rename from samples/boot/oauth2-integration/client/src/main/java/sample/config/WebClientConfig.java rename to samples/boot/oauth2-integration/client/src/main/java/sample/client/config/WebClientConfig.java index a03d2d13..68b69171 100644 --- a/samples/boot/oauth2-integration/client/src/main/java/sample/config/WebClientConfig.java +++ b/samples/boot/oauth2-integration/client/src/main/java/sample/client/config/WebClientConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package sample.config; +package sample.client.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; diff --git a/samples/boot/oauth2-integration/client/src/main/java/sample/web/AuthorizationController.java b/samples/boot/oauth2-integration/client/src/main/java/sample/client/web/AuthorizationController.java similarity index 99% rename from samples/boot/oauth2-integration/client/src/main/java/sample/web/AuthorizationController.java rename to samples/boot/oauth2-integration/client/src/main/java/sample/client/web/AuthorizationController.java index 7a5d39b4..57611d04 100644 --- a/samples/boot/oauth2-integration/client/src/main/java/sample/web/AuthorizationController.java +++ b/samples/boot/oauth2-integration/client/src/main/java/sample/client/web/AuthorizationController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package sample.web; +package sample.client.web; import org.springframework.beans.factory.annotation.Value; import org.springframework.security.oauth2.client.OAuth2AuthorizedClient; diff --git a/samples/boot/oauth2-integration/client/src/main/java/sample/web/DefaultController.java b/samples/boot/oauth2-integration/client/src/main/java/sample/client/web/DefaultController.java similarity index 97% rename from samples/boot/oauth2-integration/client/src/main/java/sample/web/DefaultController.java rename to samples/boot/oauth2-integration/client/src/main/java/sample/client/web/DefaultController.java index 5661a75d..f9244b7e 100644 --- a/samples/boot/oauth2-integration/client/src/main/java/sample/web/DefaultController.java +++ b/samples/boot/oauth2-integration/client/src/main/java/sample/client/web/DefaultController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package sample.web; +package sample.client.web; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; diff --git a/samples/boot/oauth2-integration/client/src/test/java/sample/client/OAuth2ClientApplicationTest.java b/samples/boot/oauth2-integration/client/src/test/java/sample/client/OAuth2ClientApplicationTest.java new file mode 100644 index 00000000..5ce091a0 --- /dev/null +++ b/samples/boot/oauth2-integration/client/src/test/java/sample/client/OAuth2ClientApplicationTest.java @@ -0,0 +1,70 @@ +package sample.client; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.builder.SpringApplicationBuilder; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.context.junit4.SpringRunner; +import org.springframework.test.web.servlet.MockMvc; +import sample.authorizationserver.OAuth2AuthorizationServerApplication; +import sample.resourceserver.OAuth2ResourceServerApplication; + +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = OAuth2ClientApplication.class) +@AutoConfigureMockMvc +public class OAuth2ClientApplicationTest { + + private ConfigurableApplicationContext authorizationServer; + + @Autowired + private MockMvc mockMvc; + private ConfigurableApplicationContext resourceServer; + + @Before + public void setUp() { + authorizationServer = new SpringApplicationBuilder(OAuth2AuthorizationServerApplication.class) + .properties("spring.config.name:embeddedauthorizationserver") + .properties("server.port:9000") + .application() + .run(); + + resourceServer = new SpringApplicationBuilder(OAuth2ResourceServerApplication.class) + .properties("spring.config.name:embeddedresourceserver") + .properties("spring.security.oauth2.resourceserver.jwt.jwk-set-uri:http://auth-server:9000/oauth2/jwks") + .properties("server.port:8090") + .application() + .run(); + } + + @After + public void tearDown() { + authorizationServer.stop(); + resourceServer.stop(); + } + + @Test + public void index() throws Exception { + mockMvc + .perform(get("/index")) + .andExpect(status().isOk()) + .andExpect(content().string(containsString("Client Credentials"))); + } + + @Test + public void authorize() throws Exception { + mockMvc + .perform(get("/authorize?grant_type=client_credentials")) + .andExpect(status().isOk()) + .andExpect(content().string(containsString("Message 1"))); + } +} diff --git a/samples/boot/oauth2-integration/resourceserver/src/main/java/sample/OAuth2ResourceServerApplication.java b/samples/boot/oauth2-integration/resourceserver/src/main/java/sample/resourceserver/OAuth2ResourceServerApplication.java similarity index 96% rename from samples/boot/oauth2-integration/resourceserver/src/main/java/sample/OAuth2ResourceServerApplication.java rename to samples/boot/oauth2-integration/resourceserver/src/main/java/sample/resourceserver/OAuth2ResourceServerApplication.java index c102de37..26d38c77 100644 --- a/samples/boot/oauth2-integration/resourceserver/src/main/java/sample/OAuth2ResourceServerApplication.java +++ b/samples/boot/oauth2-integration/resourceserver/src/main/java/sample/resourceserver/OAuth2ResourceServerApplication.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package sample; +package sample.resourceserver; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; diff --git a/samples/boot/oauth2-integration/resourceserver/src/main/java/sample/config/ResourceServerConfig.java b/samples/boot/oauth2-integration/resourceserver/src/main/java/sample/resourceserver/config/ResourceServerConfig.java similarity index 97% rename from samples/boot/oauth2-integration/resourceserver/src/main/java/sample/config/ResourceServerConfig.java rename to samples/boot/oauth2-integration/resourceserver/src/main/java/sample/resourceserver/config/ResourceServerConfig.java index 5759f284..88fe4262 100644 --- a/samples/boot/oauth2-integration/resourceserver/src/main/java/sample/config/ResourceServerConfig.java +++ b/samples/boot/oauth2-integration/resourceserver/src/main/java/sample/resourceserver/config/ResourceServerConfig.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package sample.config; +package sample.resourceserver.config; import org.springframework.context.annotation.Bean; import org.springframework.security.config.annotation.web.builders.HttpSecurity; diff --git a/samples/boot/oauth2-integration/resourceserver/src/main/java/sample/web/MessagesController.java b/samples/boot/oauth2-integration/resourceserver/src/main/java/sample/resourceserver/web/MessagesController.java similarity index 96% rename from samples/boot/oauth2-integration/resourceserver/src/main/java/sample/web/MessagesController.java rename to samples/boot/oauth2-integration/resourceserver/src/main/java/sample/resourceserver/web/MessagesController.java index 501fb2d5..c0f26971 100644 --- a/samples/boot/oauth2-integration/resourceserver/src/main/java/sample/web/MessagesController.java +++ b/samples/boot/oauth2-integration/resourceserver/src/main/java/sample/resourceserver/web/MessagesController.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package sample.web; +package sample.resourceserver.web; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController;