Merge pull request #4495 from eugenp/update-security-custom

update to spring 5
This commit is contained in:
Loredana Crusoveanu 2018-06-17 14:55:17 +03:00 committed by GitHub
commit 90c0268429
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 16 deletions

View File

@ -9,9 +9,9 @@
<parent> <parent>
<groupId>com.baeldung</groupId> <groupId>com.baeldung</groupId>
<artifactId>parent-spring-4</artifactId> <artifactId>parent-spring-5</artifactId>
<version>0.0.1-SNAPSHOT</version> <version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-spring-4</relativePath> <relativePath>../parent-spring-5</relativePath>
</parent> </parent>
<dependencies> <dependencies>
@ -193,26 +193,26 @@
<properties> <properties>
<!-- Spring --> <!-- Spring -->
<org.springframework.security.version>4.2.6.RELEASE</org.springframework.security.version> <org.springframework.security.version>5.0.6.RELEASE</org.springframework.security.version>
<!-- persistence --> <!-- persistence -->
<hibernate.version>5.2.5.Final</hibernate.version> <hibernate.version>5.2.5.Final</hibernate.version>
<mysql-connector-java.version>5.1.40</mysql-connector-java.version> <mysql-connector-java.version>5.1.40</mysql-connector-java.version>
<!-- various --> <!-- various -->
<hibernate-validator.version>5.3.3.Final</hibernate-validator.version> <hibernate-validator.version>5.4.1.Final</hibernate-validator.version>
<javax.servlet.version>3.1.0</javax.servlet.version> <javax.servlet.version>3.1.0</javax.servlet.version>
<jstl.version>1.2</jstl.version> <jstl.version>1.2</jstl.version>
<!-- util --> <!-- util -->
<guava.version>19.0</guava.version> <guava.version>19.0</guava.version>
<commons-lang3.version>3.5</commons-lang3.version> <commons-lang3.version>3.5</commons-lang3.version>
<jackson-databind.version>2.9.1</jackson-databind.version> <jackson-databind.version>2.9.4</jackson-databind.version>
<httpclient.version>4.5.2</httpclient.version> <httpclient.version>4.5.2</httpclient.version>
<httpcore.version>4.4.5</httpcore.version> <httpcore.version>4.4.5</httpcore.version>
<rest-assured.version>2.9.0</rest-assured.version> <rest-assured.version>3.0.7</rest-assured.version>
<!-- Maven plugins --> <!-- Maven plugins -->
<maven-war-plugin.version>2.6</maven-war-plugin.version> <maven-war-plugin.version>2.6</maven-war-plugin.version>

View File

@ -10,14 +10,14 @@ import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry; 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.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView; import org.springframework.web.servlet.view.JstlView;
@EnableWebMvc @EnableWebMvc
@Configuration @Configuration
@ComponentScan("org.baeldung.web.controller") @ComponentScan("org.baeldung.web.controller")
public class MvcConfig extends WebMvcConfigurerAdapter { public class MvcConfig implements WebMvcConfigurer {
public MvcConfig() { public MvcConfig() {
super(); super();
@ -27,8 +27,6 @@ public class MvcConfig extends WebMvcConfigurerAdapter {
@Override @Override
public void addViewControllers(final ViewControllerRegistry registry) { public void addViewControllers(final ViewControllerRegistry registry) {
super.addViewControllers(registry);
registry.addViewController("/anonymous.html"); registry.addViewController("/anonymous.html");
registry.addViewController("/login.html"); registry.addViewController("/login.html");

View File

@ -7,6 +7,8 @@ import org.springframework.context.annotation.ImportResource;
@ImportResource({ "classpath:webSecurityConfig.xml" }) @ImportResource({ "classpath:webSecurityConfig.xml" })
public class SecSecurityConfig { public class SecSecurityConfig {
public SecSecurityConfig() { public SecSecurityConfig() {
super(); super();
} }

View File

@ -1,5 +1,6 @@
package org.baeldung.web.controller; package org.baeldung.web.controller;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
@ -18,7 +19,7 @@ import org.springframework.web.bind.annotation.RequestParam;
@RequestMapping(value = "/custom") @RequestMapping(value = "/custom")
public class LoginController { public class LoginController {
@Autowired @Resource(name="authenticationManager")
private AuthenticationManager authManager; private AuthenticationManager authManager;
public LoginController() { public LoginController() {

View File

@ -2,9 +2,9 @@
<beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans" <beans:beans xmlns="http://www.springframework.org/schema/security" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation=" xsi:schemaLocation="
http://www.springframework.org/schema/security http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-4.2.xsd http://www.springframework.org/schema/security/spring-security.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd" http://www.springframework.org/schema/beans/spring-beans.xsd"
> >
<http use-expressions="true"> <http use-expressions="true">
@ -24,11 +24,11 @@
<beans:bean id="myAuthenticationSuccessHandler" class="org.baeldung.security.MySimpleUrlAuthenticationSuccessHandler"/> <beans:bean id="myAuthenticationSuccessHandler" class="org.baeldung.security.MySimpleUrlAuthenticationSuccessHandler"/>
<authentication-manager> <authentication-manager id="authenticationManager">
<authentication-provider> <authentication-provider>
<user-service> <user-service>
<user name="user1" password="user1Pass" authorities="ROLE_USER"/> <user name="user1" password="{noop}user1Pass" authorities="ROLE_USER" />
<user name="admin1" password="admin1Pass" authorities="ROLE_ADMIN"/> <user name="admin1" password="{noop}admin1Pass" authorities="ROLE_ADMIN"/>
</user-service> </user-service>
</authentication-provider> </authentication-provider>
</authentication-manager> </authentication-manager>