From 2bb03452c25202826b30ab9890b070d140a2fc04 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Fri, 24 May 2019 00:46:42 +0530 Subject: [PATCH 1/3] [BAEL-14776] - Upgraded to spring boot 2 --- spring-security-mvc-session/pom.xml | 27 +++---------------- .../java/org/baeldung/spring/MvcConfig.java | 5 ++-- .../baeldung/spring/SecSecurityConfig.java | 11 ++++++-- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/spring-security-mvc-session/pom.xml b/spring-security-mvc-session/pom.xml index c0e1527a24..c1fbda0f98 100644 --- a/spring-security-mvc-session/pom.xml +++ b/spring-security-mvc-session/pom.xml @@ -8,10 +8,10 @@ war - com.baeldung - parent-spring-4 - 0.0.1-SNAPSHOT - ../parent-spring-4 + parent-boot-2 + com.baeldung + 0.0.1-SNAPSHOT + ../parent-boot-2 @@ -21,17 +21,14 @@ org.springframework.security spring-security-web - ${org.springframework.security.version} org.springframework.security spring-security-config - ${org.springframework.security.version} org.springframework.security spring-security-taglibs - ${org.springframework.security.version} @@ -39,7 +36,6 @@ org.springframework spring-core - ${spring.version} commons-logging @@ -50,43 +46,34 @@ org.springframework spring-context - ${spring.version} org.springframework spring-jdbc - ${spring.version} org.springframework spring-beans - ${spring.version} org.springframework spring-aop - ${spring.version} org.springframework spring-tx - ${spring.version} org.springframework spring-expression - ${spring.version} - org.springframework spring-web - ${spring.version} org.springframework spring-webmvc - ${spring.version} @@ -94,14 +81,12 @@ javax.servlet javax.servlet-api - ${javax.servlet-api.version} provided javax.servlet jstl - ${jstl.version} runtime @@ -117,7 +102,6 @@ org.springframework.boot spring-boot-starter-test - 1.5.10.RELEASE test @@ -166,9 +150,6 @@ - - 4.2.6.RELEASE - 3.0.2 diff --git a/spring-security-mvc-session/src/main/java/org/baeldung/spring/MvcConfig.java b/spring-security-mvc-session/src/main/java/org/baeldung/spring/MvcConfig.java index 9e9c240181..b9f50ded73 100644 --- a/spring-security-mvc-session/src/main/java/org/baeldung/spring/MvcConfig.java +++ b/spring-security-mvc-session/src/main/java/org/baeldung/spring/MvcConfig.java @@ -5,13 +5,13 @@ import org.springframework.context.annotation.Configuration; import org.springframework.web.servlet.ViewResolver; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; -import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; +import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; import org.springframework.web.servlet.view.InternalResourceViewResolver; import org.springframework.web.servlet.view.JstlView; @EnableWebMvc @Configuration -public class MvcConfig extends WebMvcConfigurerAdapter { +public class MvcConfig implements WebMvcConfigurer { public MvcConfig() { super(); @@ -21,7 +21,6 @@ public class MvcConfig extends WebMvcConfigurerAdapter { @Override public void addViewControllers(final ViewControllerRegistry registry) { - super.addViewControllers(registry); registry.addViewController("/anonymous.html"); diff --git a/spring-security-mvc-session/src/main/java/org/baeldung/spring/SecSecurityConfig.java b/spring-security-mvc-session/src/main/java/org/baeldung/spring/SecSecurityConfig.java index deeea78e4e..b7996ebf18 100644 --- a/spring-security-mvc-session/src/main/java/org/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-mvc-session/src/main/java/org/baeldung/spring/SecSecurityConfig.java @@ -8,6 +8,8 @@ import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.http.SessionCreationPolicy; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.session.HttpSessionEventPublisher; @@ -24,9 +26,9 @@ public class SecSecurityConfig extends WebSecurityConfigurerAdapter { protected void configure(final AuthenticationManagerBuilder auth) throws Exception { // @formatter:off auth.inMemoryAuthentication() - .withUser("user1").password("user1Pass").roles("USER") + .withUser("user1").password(passwordEncoder().encode("user1Pass")).roles("USER") .and() - .withUser("admin1").password("admin1Pass").roles("ADMIN"); + .withUser("admin1").password(passwordEncoder().encode("admin1Pass")).roles("ADMIN"); // @formatter:on } @@ -68,5 +70,10 @@ public class SecSecurityConfig extends WebSecurityConfigurerAdapter { public HttpSessionEventPublisher httpSessionEventPublisher() { return new HttpSessionEventPublisher(); } + + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } } From 2d0eeabcd88f83a8e56ae3eb6d02e9275e1085f4 Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 16 Jun 2019 00:28:58 +0530 Subject: [PATCH 2/3] [BAEL-14776] - Converted to boot project and added starters inn pom.xml --- core-java-modules/core-java-lambdas/README.MD | 2 +- spring-security-mvc-session/pom.xml | 51 +++---------------- .../baeldung/SpringSessionApplication.java | 12 +++++ 3 files changed, 21 insertions(+), 44 deletions(-) create mode 100644 spring-security-mvc-session/src/main/java/org/baeldung/SpringSessionApplication.java diff --git a/core-java-modules/core-java-lambdas/README.MD b/core-java-modules/core-java-lambdas/README.MD index 31790ffbb1..10b876735e 100644 --- a/core-java-modules/core-java-lambdas/README.MD +++ b/core-java-modules/core-java-lambdas/README.MD @@ -1,3 +1,3 @@ -### Relevant Articles +## Relevant articles: - [Why Do Local Variables Used in Lambdas Have to Be Final or Effectively Final?](https://www.baeldung.com/java-lambda-effectively-final-local-variables) diff --git a/spring-security-mvc-session/pom.xml b/spring-security-mvc-session/pom.xml index c1fbda0f98..276f651436 100644 --- a/spring-security-mvc-session/pom.xml +++ b/spring-security-mvc-session/pom.xml @@ -19,12 +19,8 @@ - org.springframework.security - spring-security-web - - - org.springframework.security - spring-security-config + org.springframework.boot + spring-boot-starter-security org.springframework.security @@ -32,48 +28,17 @@ - - org.springframework - spring-core - - - commons-logging - commons-logging - - + org.springframework.boot + spring-boot-starter-web - org.springframework - spring-context + org.apache.tomcat.embed + tomcat-embed-jasper - org.springframework - spring-jdbc - - - org.springframework - spring-beans - - - org.springframework - spring-aop - - - org.springframework - spring-tx - - - org.springframework - spring-expression - - - org.springframework - spring-web - - - org.springframework - spring-webmvc + org.springframework.boot + spring-boot-starter-tomcat diff --git a/spring-security-mvc-session/src/main/java/org/baeldung/SpringSessionApplication.java b/spring-security-mvc-session/src/main/java/org/baeldung/SpringSessionApplication.java new file mode 100644 index 0000000000..9e52f0430a --- /dev/null +++ b/spring-security-mvc-session/src/main/java/org/baeldung/SpringSessionApplication.java @@ -0,0 +1,12 @@ +package org.baeldung; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class SpringSessionApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringSessionApplication.class, args); + } +} From 112fed951642dcdade2e0c617c4dba285a8afa4c Mon Sep 17 00:00:00 2001 From: amit2103 Date: Sun, 16 Jun 2019 21:32:47 +0530 Subject: [PATCH 3/3] [BAEL-14776] - Removed explicit version mention from xml config file --- .../src/main/resources/webSecurityConfig.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spring-security-mvc-session/src/main/resources/webSecurityConfig.xml b/spring-security-mvc-session/src/main/resources/webSecurityConfig.xml index e8aa2f76bc..42ff4c2186 100644 --- a/spring-security-mvc-session/src/main/resources/webSecurityConfig.xml +++ b/spring-security-mvc-session/src/main/resources/webSecurityConfig.xml @@ -2,9 +2,9 @@