security work

This commit is contained in:
eparaschiv 2013-05-22 20:52:33 +03:00
parent 47bfc87401
commit dd8debd720
4 changed files with 69 additions and 18 deletions

View File

@ -11,9 +11,9 @@ import org.springframework.web.servlet.view.JstlView;
@EnableWebMvc @EnableWebMvc
@Configuration @Configuration
public class ClientWebConfig extends WebMvcConfigurerAdapter { public class FrontendConfig extends WebMvcConfigurerAdapter {
public ClientWebConfig() { public FrontendConfig() {
super(); super();
} }
@ -23,7 +23,6 @@ public class ClientWebConfig extends WebMvcConfigurerAdapter {
public void addViewControllers(final ViewControllerRegistry registry) { public void addViewControllers(final ViewControllerRegistry registry) {
super.addViewControllers(registry); super.addViewControllers(registry);
registry.addViewController("/login.html");
registry.addViewController("/homepage.html"); registry.addViewController("/homepage.html");
} }

View File

@ -0,0 +1,17 @@
package org.baeldung.spring.web.config;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
@ComponentScan("org.baeldung.spring.web.controller")
public class WebConfig extends WebMvcConfigurerAdapter {
public WebConfig() {
super();
}
// API
}

View File

@ -0,0 +1,28 @@
package org.baeldung.spring.web.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class TestController {
public TestController() {
super();
}
// API
@RequestMapping("/permitAll")
@ResponseBody
public String permitAll() {
return "Permit All";
}
@RequestMapping("/securityNone")
@ResponseBody
public String securityNone() {
return "Security None";
}
}

View File

@ -1,23 +1,30 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<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"
xsi:schemaLocation=" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:beans="http://www.springframework.org/schema/beans"
xsi:schemaLocation="
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd"> http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd">
<http use-expressions="true">
<intercept-url pattern="/login*" access="isAnonymous()" />
<intercept-url pattern="/**" access="isAuthenticated()" />
<http-basic /> <http use-expressions="true">
<intercept-url pattern="/login*" access="isAnonymous()" />
</http>
<authentication-manager> <intercept-url pattern="/permitAll" access="permitAll" />
<authentication-provider>
<user-service> <intercept-url pattern="/**" access="isAuthenticated()" />
<user name="user1" password="user1Pass" authorities="ROLE_USER" />
</user-service> <http-basic />
</authentication-provider>
</authentication-manager> </http>
<http pattern="/securityNone" security="none" />
<authentication-manager>
<authentication-provider>
<user-service>
<user name="user1" password="user1Pass" authorities="ROLE_USER" />
</user-service>
</authentication-provider>
</authentication-manager>
</beans:beans> </beans:beans>