From 96d121bcae0f7925c6077c2299473a03ae6b8514 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Mon, 19 Nov 2018 00:04:52 +0530 Subject: [PATCH 1/2] [BAEL-9712] - Created spring-5-security-oauth module --- pom.xml | 4 ++ spring-5-security-oauth/README.md | 3 + spring-5-security-oauth/pom.xml | 68 +++++++++++++++++++ .../com/baeldung/oauth2/LoginController.java | 0 .../java/com/baeldung/oauth2/MvcConfig.java | 0 .../com/baeldung/oauth2/SecurityConfig.java | 4 +- .../oauth2/SpringOAuthApplication.java | 0 .../ExtractorsApplication.java | 0 .../configuration/SecurityConfig.java | 0 .../custom/BaeldungAuthoritiesExtractor.java | 0 .../custom/BaeldungPrincipalExtractor.java | 0 .../github/GithubAuthoritiesExtractor.java | 0 .../github/GithubPrincipalExtractor.java | 0 ...tion-oauth2-extractors-baeldung.properties | 0 ...cation-oauth2-extractors-github.properties | 0 .../resources/application-oauth2.properties | 0 .../src/main/resources/application.properties | 5 ++ .../src/main/resources/logback.xml | 13 ++++ .../src/main/resources/static/css/main.css | 8 +++ .../src/main/resources/templates/index.html | 11 +++ .../resources/templates/loginFailure.html | 0 .../resources/templates/loginSuccess.html | 0 .../templates/oauth2_extractors.html | 0 .../main/resources/templates/oauth_login.html | 0 .../main/resources/templates/securedPage.html | 0 .../oauth2extractors/ExtractorsUnitTest.java | 0 spring-5-security/README.md | 1 - spring-5-security/pom.xml | 15 ---- 28 files changed, 114 insertions(+), 18 deletions(-) create mode 100644 spring-5-security-oauth/README.md create mode 100644 spring-5-security-oauth/pom.xml rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/LoginController.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/MvcConfig.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/SecurityConfig.java (95%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/application-oauth2-extractors-baeldung.properties (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/application-oauth2-extractors-github.properties (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/application-oauth2.properties (100%) create mode 100644 spring-5-security-oauth/src/main/resources/application.properties create mode 100644 spring-5-security-oauth/src/main/resources/logback.xml create mode 100644 spring-5-security-oauth/src/main/resources/static/css/main.css create mode 100644 spring-5-security-oauth/src/main/resources/templates/index.html rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/loginFailure.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/loginSuccess.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/oauth2_extractors.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/oauth_login.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/main/resources/templates/securedPage.html (100%) rename {spring-5-security => spring-5-security-oauth}/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java (100%) diff --git a/pom.xml b/pom.xml index 5ebf7ba4f3..0997d7ce88 100644 --- a/pom.xml +++ b/pom.xml @@ -466,6 +466,7 @@ spring-5-reactive-client spring-5-mvc spring-5-security + spring-5-security-oauth spring-5-reactive-oauth spring-activiti spring-akka @@ -768,6 +769,7 @@ spring-5-reactive-client spring-5-reactive-security spring-5-security + spring-5-security-oauth spring-activiti spring-akka spring-all @@ -994,6 +996,7 @@ spring-5-reactive-client spring-5-mvc spring-5-security + spring-5-security-oauth spring-activiti spring-akka spring-amqp @@ -1385,6 +1388,7 @@ spring-5-reactive-client spring-5-mvc spring-5-security + spring-5-security-oauth spring-activiti spring-akka spring-amqp diff --git a/spring-5-security-oauth/README.md b/spring-5-security-oauth/README.md new file mode 100644 index 0000000000..81d95c07d7 --- /dev/null +++ b/spring-5-security-oauth/README.md @@ -0,0 +1,3 @@ +## Relevant articles: + +- [Spring Security 5 -OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login) \ No newline at end of file diff --git a/spring-5-security-oauth/pom.xml b/spring-5-security-oauth/pom.xml new file mode 100644 index 0000000000..a741daaa18 --- /dev/null +++ b/spring-5-security-oauth/pom.xml @@ -0,0 +1,68 @@ + + 4.0.0 + com.baeldung + spring-5-security-oauth + 0.0.1-SNAPSHOT + jar + spring-5-security-oauth + spring 5 security oauth sample project + + + com.baeldung + parent-boot-2 + 0.0.1-SNAPSHOT + ../parent-boot-2 + + + + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + org.thymeleaf.extras + thymeleaf-extras-springsecurity5 + + + + + org.springframework.security.oauth.boot + spring-security-oauth2-autoconfigure + ${oauth-auto.version} + + + org.springframework.security + spring-security-oauth2-client + + + org.springframework.security + spring-security-oauth2-jose + + + + org.springframework + spring-test + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/LoginController.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LoginController.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2/LoginController.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/LoginController.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/MvcConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/MvcConfig.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2/MvcConfig.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/MvcConfig.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java similarity index 95% rename from spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java index b45f325767..e08057d92f 100644 --- a/spring-5-security/src/main/java/com/baeldung/oauth2/SecurityConfig.java +++ b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SecurityConfig.java @@ -12,7 +12,7 @@ import org.springframework.core.env.Environment; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.oauth2.client.CommonOAuth2Provider; -import org.springframework.security.oauth2.client.endpoint.NimbusAuthorizationCodeTokenResponseClient; +import org.springframework.security.oauth2.client.endpoint.DefaultAuthorizationCodeTokenResponseClient; import org.springframework.security.oauth2.client.endpoint.OAuth2AccessTokenResponseClient; import org.springframework.security.oauth2.client.endpoint.OAuth2AuthorizationCodeGrantRequest; import org.springframework.security.oauth2.client.registration.ClientRegistration; @@ -54,7 +54,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter { @Bean public OAuth2AccessTokenResponseClient accessTokenResponseClient() { - return new NimbusAuthorizationCodeTokenResponseClient(); + return new DefaultAuthorizationCodeTokenResponseClient(); } diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2/SpringOAuthApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/ExtractorsApplication.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/configuration/SecurityConfig.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungAuthoritiesExtractor.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/custom/BaeldungPrincipalExtractor.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubAuthoritiesExtractor.java diff --git a/spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java b/spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java similarity index 100% rename from spring-5-security/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java rename to spring-5-security-oauth/src/main/java/com/baeldung/oauth2extractors/extractor/github/GithubPrincipalExtractor.java diff --git a/spring-5-security/src/main/resources/application-oauth2-extractors-baeldung.properties b/spring-5-security-oauth/src/main/resources/application-oauth2-extractors-baeldung.properties similarity index 100% rename from spring-5-security/src/main/resources/application-oauth2-extractors-baeldung.properties rename to spring-5-security-oauth/src/main/resources/application-oauth2-extractors-baeldung.properties diff --git a/spring-5-security/src/main/resources/application-oauth2-extractors-github.properties b/spring-5-security-oauth/src/main/resources/application-oauth2-extractors-github.properties similarity index 100% rename from spring-5-security/src/main/resources/application-oauth2-extractors-github.properties rename to spring-5-security-oauth/src/main/resources/application-oauth2-extractors-github.properties diff --git a/spring-5-security/src/main/resources/application-oauth2.properties b/spring-5-security-oauth/src/main/resources/application-oauth2.properties similarity index 100% rename from spring-5-security/src/main/resources/application-oauth2.properties rename to spring-5-security-oauth/src/main/resources/application-oauth2.properties diff --git a/spring-5-security-oauth/src/main/resources/application.properties b/spring-5-security-oauth/src/main/resources/application.properties new file mode 100644 index 0000000000..5912b0f755 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/application.properties @@ -0,0 +1,5 @@ +server.port=8081 + +logging.level.root=INFO + +logging.level.com.baeldung.dsl.ClientErrorLoggingFilter=DEBUG \ No newline at end of file diff --git a/spring-5-security-oauth/src/main/resources/logback.xml b/spring-5-security-oauth/src/main/resources/logback.xml new file mode 100644 index 0000000000..7d900d8ea8 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/logback.xml @@ -0,0 +1,13 @@ + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + + \ No newline at end of file diff --git a/spring-5-security-oauth/src/main/resources/static/css/main.css b/spring-5-security-oauth/src/main/resources/static/css/main.css new file mode 100644 index 0000000000..febc353af7 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/static/css/main.css @@ -0,0 +1,8 @@ +p.error { + font-weight: bold; + color: red; +} + +div.logout { + margin-right: 2em;; +} diff --git a/spring-5-security-oauth/src/main/resources/templates/index.html b/spring-5-security-oauth/src/main/resources/templates/index.html new file mode 100644 index 0000000000..4216d74037 --- /dev/null +++ b/spring-5-security-oauth/src/main/resources/templates/index.html @@ -0,0 +1,11 @@ + + + + Home + + + + Home + Welcome! + + \ No newline at end of file diff --git a/spring-5-security/src/main/resources/templates/loginFailure.html b/spring-5-security-oauth/src/main/resources/templates/loginFailure.html similarity index 100% rename from spring-5-security/src/main/resources/templates/loginFailure.html rename to spring-5-security-oauth/src/main/resources/templates/loginFailure.html diff --git a/spring-5-security/src/main/resources/templates/loginSuccess.html b/spring-5-security-oauth/src/main/resources/templates/loginSuccess.html similarity index 100% rename from spring-5-security/src/main/resources/templates/loginSuccess.html rename to spring-5-security-oauth/src/main/resources/templates/loginSuccess.html diff --git a/spring-5-security/src/main/resources/templates/oauth2_extractors.html b/spring-5-security-oauth/src/main/resources/templates/oauth2_extractors.html similarity index 100% rename from spring-5-security/src/main/resources/templates/oauth2_extractors.html rename to spring-5-security-oauth/src/main/resources/templates/oauth2_extractors.html diff --git a/spring-5-security/src/main/resources/templates/oauth_login.html b/spring-5-security-oauth/src/main/resources/templates/oauth_login.html similarity index 100% rename from spring-5-security/src/main/resources/templates/oauth_login.html rename to spring-5-security-oauth/src/main/resources/templates/oauth_login.html diff --git a/spring-5-security/src/main/resources/templates/securedPage.html b/spring-5-security-oauth/src/main/resources/templates/securedPage.html similarity index 100% rename from spring-5-security/src/main/resources/templates/securedPage.html rename to spring-5-security-oauth/src/main/resources/templates/securedPage.html diff --git a/spring-5-security/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java b/spring-5-security-oauth/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java similarity index 100% rename from spring-5-security/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java rename to spring-5-security-oauth/src/test/java/com/baeldung/oauth2extractors/ExtractorsUnitTest.java diff --git a/spring-5-security/README.md b/spring-5-security/README.md index 55fa7ab042..6e094e928f 100644 --- a/spring-5-security/README.md +++ b/spring-5-security/README.md @@ -1,6 +1,5 @@ ## Relevant articles: -- [Spring Security 5 -OAuth2 Login](http://www.baeldung.com/spring-security-5-oauth2-login) - [Extra Login Fields with Spring Security](http://www.baeldung.com/spring-security-extra-login-fields) - [A Custom Spring SecurityConfigurer](http://www.baeldung.com/spring-security-custom-configurer) - [New Password Storage In Spring Security 5](http://www.baeldung.com/spring-security-5-password-storage) diff --git a/spring-5-security/pom.xml b/spring-5-security/pom.xml index da62f39fa9..51ce822dc4 100644 --- a/spring-5-security/pom.xml +++ b/spring-5-security/pom.xml @@ -34,21 +34,6 @@ thymeleaf-extras-springsecurity5 - - - org.springframework.security.oauth.boot - spring-security-oauth2-autoconfigure - ${oauth-auto.version} - - - org.springframework.security - spring-security-oauth2-client - - - org.springframework.security - spring-security-oauth2-jose - - org.springframework spring-test From 27ec13ea96cf876ba159babd9ec4e4a67c0877ca Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 25 Nov 2018 00:23:51 +0530 Subject: [PATCH 2/2] [BAEL-9712] - Modifed oauth version --- spring-5-security-oauth/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-5-security-oauth/pom.xml b/spring-5-security-oauth/pom.xml index 13359ae84a..33a0677724 100644 --- a/spring-5-security-oauth/pom.xml +++ b/spring-5-security-oauth/pom.xml @@ -66,7 +66,7 @@ - 2.0.5.RELEASE + 2.0.1.RELEASE