diff --git a/spring-mvc-forms/pom.xml b/spring-mvc-forms/pom.xml index f17d695c35..35ed00c0e9 100644 --- a/spring-mvc-forms/pom.xml +++ b/spring-mvc-forms/pom.xml @@ -47,22 +47,6 @@ ${fileupload.version} - - 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} - - @@ -115,7 +99,6 @@ 5.3.3.Final enter-location-of-server 1.3.2 - 4.2.1.RELEASE diff --git a/spring-mvc-forms/src/main/java/com/baeldung/springmvcforms/configuration/SecurityConfig.java b/spring-mvc-forms/src/main/java/com/baeldung/springmvcforms/configuration/SecurityConfig.java deleted file mode 100644 index e35844138d..0000000000 --- a/spring-mvc-forms/src/main/java/com/baeldung/springmvcforms/configuration/SecurityConfig.java +++ /dev/null @@ -1,122 +0,0 @@ -package com.baeldung.springmvcforms.configuration; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.core.annotation.Order; -import org.springframework.security.authentication.AuthenticationProvider; -import org.springframework.security.authentication.TestingAuthenticationProvider; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -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.core.userdetails.User; -import org.springframework.security.core.userdetails.UserDetailsService; -import org.springframework.security.provisioning.InMemoryUserDetailsManager; - -@Configuration -@EnableWebSecurity -public class SecurityConfig { - - @Bean - public UserDetailsService userDetailsService() throws Exception { - InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager(); - manager.createUser(User.withUsername("user") - .password("userPass") - .roles("USER") - .build()); - manager.createUser(User.withUsername("admin") - .password("adminPass") - .roles("ADMIN") - .build()); - return manager; - } - - @Configuration - @Order(1) - public static class App1ConfigurationAdapter extends WebSecurityConfigurerAdapter { - - public App1ConfigurationAdapter() { - super(); - } - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication() - .withUser("admin") - .password("admin") - .roles("ADMIN"); - } - - @Override - protected void configure(HttpSecurity http) throws Exception { - http.antMatcher("/admin*") - .authorizeRequests() - .anyRequest() - .hasRole("ADMIN") - // log in - .and() - .formLogin() - .loginPage("/loginAdmin") - .loginProcessingUrl("/admin_login") - .failureUrl("/loginAdmin?error=loginError") - .defaultSuccessUrl("/adminPage") - // logout - .and() - .logout() - .logoutUrl("/admin_logout") - .logoutSuccessUrl("/protectedLinks") - .deleteCookies("JSESSIONID") - .and() - .exceptionHandling() - .accessDeniedPage("/403") - .and() - .csrf() - .disable(); - } - } - - @Configuration - @Order(2) - public static class App2ConfigurationAdapter extends WebSecurityConfigurerAdapter { - - public App2ConfigurationAdapter() { - super(); - } - - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - auth.inMemoryAuthentication() - .withUser("user") - .password("user") - .roles("USER"); - } - - protected void configure(HttpSecurity http) throws Exception { - http.antMatcher("/user*") - .authorizeRequests() - .anyRequest() - .hasRole("USER") - // log in - .and() - .formLogin() - .loginPage("/loginUser") - .loginProcessingUrl("/user_login") - .failureUrl("/loginUser?error=loginError") - .defaultSuccessUrl("/userPage") - // logout - .and() - .logout() - .logoutUrl("/user_logout") - .logoutSuccessUrl("/protectedLinks") - .deleteCookies("JSESSIONID") - .and() - .exceptionHandling() - .accessDeniedPage("/403") - .and() - .csrf() - .disable(); - } - } - -} diff --git a/spring-mvc-forms/src/main/java/com/baeldung/springmvcforms/configuration/WebInitializer.java b/spring-mvc-forms/src/main/java/com/baeldung/springmvcforms/configuration/WebInitializer.java index fdc155e101..2eb669da2c 100644 --- a/spring-mvc-forms/src/main/java/com/baeldung/springmvcforms/configuration/WebInitializer.java +++ b/spring-mvc-forms/src/main/java/com/baeldung/springmvcforms/configuration/WebInitializer.java @@ -3,7 +3,6 @@ package com.baeldung.springmvcforms.configuration; import org.springframework.web.WebApplicationInitializer; import org.springframework.web.context.ContextLoaderListener; import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; -import org.springframework.web.filter.DelegatingFilterProxy; import org.springframework.web.servlet.DispatcherServlet; import javax.servlet.ServletContext; @@ -25,9 +24,7 @@ public class WebInitializer implements WebApplicationInitializer { servlet.setLoadOnStartup(1); servlet.addMapping("/"); - - container.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain")) - .addMappingForUrlPatterns(null, false, "/*"); + } // @Override // public void onStartup(ServletContext container) { diff --git a/spring-mvc-forms/src/main/java/com/baeldung/springmvcforms/controller/UsersController.java b/spring-mvc-forms/src/main/java/com/baeldung/springmvcforms/controller/UsersController.java deleted file mode 100644 index c0858d427f..0000000000 --- a/spring-mvc-forms/src/main/java/com/baeldung/springmvcforms/controller/UsersController.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.baeldung.springmvcforms.controller; - -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.RequestMapping; - -@Controller -public class UsersController { - - @RequestMapping("/protectedLinks") - public String getAnonymousPage() { - return "protectedLinks"; - } - - @RequestMapping("/userPage") - public String getUserPage() { - return "userPage"; - } - - @RequestMapping("/adminPage") - public String getAdminPage() { - return "adminPage"; - } - - @RequestMapping("/loginAdmin") - public String getAdminLoginPage() { - return "loginAdmin"; - } - - @RequestMapping("/loginUser") - public String getUserLoginPage() { - return "loginUser"; - } - - @RequestMapping("/403") - public String getAccessDeniedPage() { - return "403"; - } -} diff --git a/spring-mvc-forms/src/main/webapp/WEB-INF/views/403.jsp b/spring-mvc-forms/src/main/webapp/WEB-INF/views/403.jsp deleted file mode 100644 index e665793e10..0000000000 --- a/spring-mvc-forms/src/main/webapp/WEB-INF/views/403.jsp +++ /dev/null @@ -1,12 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> - - - - - - - -Your do not have permission to view this page. - - \ No newline at end of file diff --git a/spring-mvc-forms/src/main/webapp/WEB-INF/views/adminPage.jsp b/spring-mvc-forms/src/main/webapp/WEB-INF/views/adminPage.jsp deleted file mode 100644 index a210b690b0..0000000000 --- a/spring-mvc-forms/src/main/webapp/WEB-INF/views/adminPage.jsp +++ /dev/null @@ -1,16 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - -Insert title here - - -Welcome admin! Logout - -

-Back to links - - \ No newline at end of file diff --git a/spring-mvc-forms/src/main/webapp/WEB-INF/views/loginAdmin.jsp b/spring-mvc-forms/src/main/webapp/WEB-INF/views/loginAdmin.jsp deleted file mode 100644 index a6b2ee7914..0000000000 --- a/spring-mvc-forms/src/main/webapp/WEB-INF/views/loginAdmin.jsp +++ /dev/null @@ -1,38 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> - - - - -Insert title here - - - -

Admin login page

-
- - - - - - - - - - - - - -
User:
Password:
- -
- - <% - if (request.getParameter("error") != null) { - out.println("Login failed!"); - } - %> - - - \ No newline at end of file diff --git a/spring-mvc-forms/src/main/webapp/WEB-INF/views/loginUser.jsp b/spring-mvc-forms/src/main/webapp/WEB-INF/views/loginUser.jsp deleted file mode 100644 index e65c11edaf..0000000000 --- a/spring-mvc-forms/src/main/webapp/WEB-INF/views/loginUser.jsp +++ /dev/null @@ -1,37 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> - - - - -Login - - - -

User login page

- -
- - - - - - - - - - - - -
User:
Password:
- -
- <% - if (request.getParameter("error") != null) { - out.println("Login failed!"); - } - %> - - - \ No newline at end of file diff --git a/spring-mvc-forms/src/main/webapp/WEB-INF/views/protectedLinks.jsp b/spring-mvc-forms/src/main/webapp/WEB-INF/views/protectedLinks.jsp deleted file mode 100644 index b8453903ba..0000000000 --- a/spring-mvc-forms/src/main/webapp/WEB-INF/views/protectedLinks.jsp +++ /dev/null @@ -1,16 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - -Insert title here - - - -">User page -
-">Admin page - - \ No newline at end of file diff --git a/spring-mvc-forms/src/main/webapp/WEB-INF/views/userPage.jsp b/spring-mvc-forms/src/main/webapp/WEB-INF/views/userPage.jsp deleted file mode 100644 index 4c1bd47502..0000000000 --- a/spring-mvc-forms/src/main/webapp/WEB-INF/views/userPage.jsp +++ /dev/null @@ -1,15 +0,0 @@ -<%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1"%> -<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> - - - - -Insert title here - - -Welcome user! Logout -

-Back to links - - \ No newline at end of file