diff --git a/spring-security-mvc-login/src/main/java/com/baeldung/AppInitializer.java b/spring-security-mvc-login/src/main/java/com/baeldung/AppInitializer.java new file mode 100644 index 0000000000..4f38d190eb --- /dev/null +++ b/spring-security-mvc-login/src/main/java/com/baeldung/AppInitializer.java @@ -0,0 +1,33 @@ +package com.baeldung; + +import javax.servlet.ServletContext; +import javax.servlet.ServletException; +import javax.servlet.ServletRegistration; + +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.ContextLoaderListener; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; +import org.springframework.web.context.support.GenericWebApplicationContext; +import org.springframework.web.filter.DelegatingFilterProxy; +import org.springframework.web.servlet.DispatcherServlet; + +public class AppInitializer implements WebApplicationInitializer { + + @Override + public void onStartup(final ServletContext sc) throws ServletException { + + AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext(); + + root.scan("com.baeldung"); + sc.addListener(new ContextLoaderListener(root)); + + ServletRegistration.Dynamic appServlet = sc.addServlet("mvc", new DispatcherServlet(new GenericWebApplicationContext())); + appServlet.setLoadOnStartup(1); + appServlet.addMapping("/"); + + sc.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain")) + .addMappingForUrlPatterns(null, false, "/*"); + + } + +} diff --git a/spring-security-mvc-login/src/main/java/org/baeldung/controller/SecuredResourceController.java b/spring-security-mvc-login/src/main/java/com/baeldung/controller/SecuredResourceController.java similarity index 93% rename from spring-security-mvc-login/src/main/java/org/baeldung/controller/SecuredResourceController.java rename to spring-security-mvc-login/src/main/java/com/baeldung/controller/SecuredResourceController.java index 4b68eee983..a458a5aeac 100644 --- a/spring-security-mvc-login/src/main/java/org/baeldung/controller/SecuredResourceController.java +++ b/spring-security-mvc-login/src/main/java/com/baeldung/controller/SecuredResourceController.java @@ -1,4 +1,4 @@ -package org.baeldung.controller; +package com.baeldung.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; diff --git a/spring-security-mvc-login/src/main/java/org/baeldung/security/CustomAccessDeniedHandler.java b/spring-security-mvc-login/src/main/java/com/baeldung/security/CustomAccessDeniedHandler.java similarity index 97% rename from spring-security-mvc-login/src/main/java/org/baeldung/security/CustomAccessDeniedHandler.java rename to spring-security-mvc-login/src/main/java/com/baeldung/security/CustomAccessDeniedHandler.java index 64698072bc..9d9fa81dc0 100644 --- a/spring-security-mvc-login/src/main/java/org/baeldung/security/CustomAccessDeniedHandler.java +++ b/spring-security-mvc-login/src/main/java/com/baeldung/security/CustomAccessDeniedHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import java.io.IOException; diff --git a/spring-security-mvc-login/src/main/java/org/baeldung/security/CustomAuthenticationFailureHandler.java b/spring-security-mvc-login/src/main/java/com/baeldung/security/CustomAuthenticationFailureHandler.java similarity index 96% rename from spring-security-mvc-login/src/main/java/org/baeldung/security/CustomAuthenticationFailureHandler.java rename to spring-security-mvc-login/src/main/java/com/baeldung/security/CustomAuthenticationFailureHandler.java index 5eddf3883e..410d3f1ce9 100644 --- a/spring-security-mvc-login/src/main/java/org/baeldung/security/CustomAuthenticationFailureHandler.java +++ b/spring-security-mvc-login/src/main/java/com/baeldung/security/CustomAuthenticationFailureHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import org.springframework.http.HttpStatus; import org.springframework.security.core.AuthenticationException; diff --git a/spring-security-mvc-login/src/main/java/org/baeldung/security/CustomLogoutSuccessHandler.java b/spring-security-mvc-login/src/main/java/com/baeldung/security/CustomLogoutSuccessHandler.java similarity index 96% rename from spring-security-mvc-login/src/main/java/org/baeldung/security/CustomLogoutSuccessHandler.java rename to spring-security-mvc-login/src/main/java/com/baeldung/security/CustomLogoutSuccessHandler.java index 7360b4e03f..7949eee69a 100644 --- a/spring-security-mvc-login/src/main/java/org/baeldung/security/CustomLogoutSuccessHandler.java +++ b/spring-security-mvc-login/src/main/java/com/baeldung/security/CustomLogoutSuccessHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import java.io.IOException; diff --git a/spring-security-mvc-login/src/main/java/org/baeldung/security/RefererAuthenticationSuccessHandler.java b/spring-security-mvc-login/src/main/java/com/baeldung/security/RefererAuthenticationSuccessHandler.java similarity index 93% rename from spring-security-mvc-login/src/main/java/org/baeldung/security/RefererAuthenticationSuccessHandler.java rename to spring-security-mvc-login/src/main/java/com/baeldung/security/RefererAuthenticationSuccessHandler.java index 5b025d9fd1..05a2463699 100644 --- a/spring-security-mvc-login/src/main/java/org/baeldung/security/RefererAuthenticationSuccessHandler.java +++ b/spring-security-mvc-login/src/main/java/com/baeldung/security/RefererAuthenticationSuccessHandler.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import org.springframework.security.web.authentication.AuthenticationSuccessHandler; import org.springframework.security.web.authentication.SimpleUrlAuthenticationSuccessHandler; diff --git a/spring-security-mvc-login/src/main/java/org/baeldung/spring/ChannelSecSecurityConfig.java b/spring-security-mvc-login/src/main/java/com/baeldung/spring/ChannelSecSecurityConfig.java similarity index 96% rename from spring-security-mvc-login/src/main/java/org/baeldung/spring/ChannelSecSecurityConfig.java rename to spring-security-mvc-login/src/main/java/com/baeldung/spring/ChannelSecSecurityConfig.java index 4f736360b9..e9a6a9e120 100644 --- a/spring-security-mvc-login/src/main/java/org/baeldung/spring/ChannelSecSecurityConfig.java +++ b/spring-security-mvc-login/src/main/java/com/baeldung/spring/ChannelSecSecurityConfig.java @@ -1,6 +1,5 @@ -package org.baeldung.spring; +package com.baeldung.spring; -import org.baeldung.security.CustomLogoutSuccessHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @@ -10,6 +9,8 @@ import org.springframework.security.config.annotation.web.configuration.EnableWe import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; +import com.baeldung.security.CustomLogoutSuccessHandler; + @Configuration // @ImportResource({ "classpath:channelWebSecurityConfig.xml" }) @EnableWebSecurity diff --git a/spring-security-mvc-login/src/main/java/org/baeldung/spring/MvcConfig.java b/spring-security-mvc-login/src/main/java/com/baeldung/spring/MvcConfig.java similarity index 97% rename from spring-security-mvc-login/src/main/java/org/baeldung/spring/MvcConfig.java rename to spring-security-mvc-login/src/main/java/com/baeldung/spring/MvcConfig.java index b529048685..a9c7e0cf15 100644 --- a/spring-security-mvc-login/src/main/java/org/baeldung/spring/MvcConfig.java +++ b/spring-security-mvc-login/src/main/java/com/baeldung/spring/MvcConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; diff --git a/spring-security-mvc-login/src/main/java/org/baeldung/spring/RedirectionSecurityConfig.java b/spring-security-mvc-login/src/main/java/com/baeldung/spring/RedirectionSecurityConfig.java similarity index 97% rename from spring-security-mvc-login/src/main/java/org/baeldung/spring/RedirectionSecurityConfig.java rename to spring-security-mvc-login/src/main/java/com/baeldung/spring/RedirectionSecurityConfig.java index 1472a1f89c..3516438a6e 100644 --- a/spring-security-mvc-login/src/main/java/org/baeldung/spring/RedirectionSecurityConfig.java +++ b/spring-security-mvc-login/src/main/java/com/baeldung/spring/RedirectionSecurityConfig.java @@ -1,4 +1,4 @@ -package org.baeldung.spring; +package com.baeldung.spring; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; diff --git a/spring-security-mvc-login/src/main/java/org/baeldung/spring/SecSecurityConfig.java b/spring-security-mvc-login/src/main/java/com/baeldung/spring/SecSecurityConfig.java similarity index 94% rename from spring-security-mvc-login/src/main/java/org/baeldung/spring/SecSecurityConfig.java rename to spring-security-mvc-login/src/main/java/com/baeldung/spring/SecSecurityConfig.java index 97ce6b5bc2..08a83f8633 100644 --- a/spring-security-mvc-login/src/main/java/org/baeldung/spring/SecSecurityConfig.java +++ b/spring-security-mvc-login/src/main/java/com/baeldung/spring/SecSecurityConfig.java @@ -1,8 +1,5 @@ -package org.baeldung.spring; +package com.baeldung.spring; -import org.baeldung.security.CustomAccessDeniedHandler; -import org.baeldung.security.CustomAuthenticationFailureHandler; -import org.baeldung.security.CustomLogoutSuccessHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @@ -16,6 +13,10 @@ import org.springframework.security.web.access.AccessDeniedHandler; import org.springframework.security.web.authentication.AuthenticationFailureHandler; import org.springframework.security.web.authentication.logout.LogoutSuccessHandler; +import com.baeldung.security.CustomAccessDeniedHandler; +import com.baeldung.security.CustomAuthenticationFailureHandler; +import com.baeldung.security.CustomLogoutSuccessHandler; + @Configuration // @ImportResource({ "classpath:webSecurityConfig.xml" }) @EnableWebSecurity diff --git a/spring-security-mvc-login/src/main/webapp/WEB-INF/web.xml b/spring-security-mvc-login/src/main/webapp/WEB-INF/web-old.xml similarity index 97% rename from spring-security-mvc-login/src/main/webapp/WEB-INF/web.xml rename to spring-security-mvc-login/src/main/webapp/WEB-INF/web-old.xml index eef48ec9b3..bc6f310147 100644 --- a/spring-security-mvc-login/src/main/webapp/WEB-INF/web.xml +++ b/spring-security-mvc-login/src/main/webapp/WEB-INF/web-old.xml @@ -15,7 +15,7 @@ contextConfigLocation - org.baeldung.spring + com.baeldung.spring diff --git a/spring-security-mvc-login/src/test/java/org/baeldung/SpringContextIntegrationTest.java b/spring-security-mvc-login/src/test/java/com/baeldung/SpringContextIntegrationTest.java similarity index 95% rename from spring-security-mvc-login/src/test/java/org/baeldung/SpringContextIntegrationTest.java rename to spring-security-mvc-login/src/test/java/com/baeldung/SpringContextIntegrationTest.java index 1d7f9ae497..20de02d5c5 100644 --- a/spring-security-mvc-login/src/test/java/org/baeldung/SpringContextIntegrationTest.java +++ b/spring-security-mvc-login/src/test/java/com/baeldung/SpringContextIntegrationTest.java @@ -1,4 +1,4 @@ -package org.baeldung; +package com.baeldung; import org.junit.Test; import org.junit.runner.RunWith; diff --git a/spring-security-mvc-login/src/test/java/org/baeldung/security/FormLoginUnitTest.java b/spring-security-mvc-login/src/test/java/com/baeldung/security/FormLoginUnitTest.java similarity index 96% rename from spring-security-mvc-login/src/test/java/org/baeldung/security/FormLoginUnitTest.java rename to spring-security-mvc-login/src/test/java/com/baeldung/security/FormLoginUnitTest.java index 4b3a091e6c..b7d959bf36 100644 --- a/spring-security-mvc-login/src/test/java/org/baeldung/security/FormLoginUnitTest.java +++ b/spring-security-mvc-login/src/test/java/com/baeldung/security/FormLoginUnitTest.java @@ -1,6 +1,5 @@ -package org.baeldung.security; +package com.baeldung.security; -import org.baeldung.spring.SecSecurityConfig; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -13,6 +12,8 @@ import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; +import com.baeldung.spring.SecSecurityConfig; + import javax.servlet.Filter; import static org.junit.Assert.assertTrue; diff --git a/spring-security-mvc-login/src/test/java/org/baeldung/security/RedirectionSecurityIntegrationTest.java b/spring-security-mvc-login/src/test/java/com/baeldung/security/RedirectionSecurityIntegrationTest.java similarity index 99% rename from spring-security-mvc-login/src/test/java/org/baeldung/security/RedirectionSecurityIntegrationTest.java rename to spring-security-mvc-login/src/test/java/com/baeldung/security/RedirectionSecurityIntegrationTest.java index 2b7a8ce5b9..1235e2e69f 100644 --- a/spring-security-mvc-login/src/test/java/org/baeldung/security/RedirectionSecurityIntegrationTest.java +++ b/spring-security-mvc-login/src/test/java/com/baeldung/security/RedirectionSecurityIntegrationTest.java @@ -1,4 +1,4 @@ -package org.baeldung.security; +package com.baeldung.security; import org.junit.Before; import org.junit.Test;