(118) - Add java-config(零配置) 的支持
parent
4d94ac10c6
commit
d7acfccd5c
|
@ -23,12 +23,12 @@ public class ServletInitializer extends AbstractAnnotationConfigDispatcherServle
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?>[] getRootConfigClasses() {
|
protected Class<?>[] getRootConfigClasses() {
|
||||||
throw new UnsupportedOperationException("Not yet implemented");
|
return new Class[]{WebSecurityConfigurer.class};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?>[] getServletConfigClasses() {
|
protected Class<?>[] getServletConfigClasses() {
|
||||||
return new Class[]{MkkWebMvcConfigurer.class};
|
return new Class[]{WebMvcConfigurer.class};
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,7 +43,7 @@ public class ServletInitializer extends AbstractAnnotationConfigDispatcherServle
|
||||||
|
|
||||||
// servletContext.setAttribute("webAppRootKey", "spring-oauth-server");
|
// servletContext.setAttribute("webAppRootKey", "spring-oauth-server");
|
||||||
servletContext.setInitParameter("webAppRootKey", "spring-oauth-server");
|
servletContext.setInitParameter("webAppRootKey", "spring-oauth-server");
|
||||||
servletContext.setInitParameter("contextConfigLocation", "classpath:spring/*.xml");
|
// servletContext.setInitParameter("contextConfigLocation", "classpath:spring/*.xml");
|
||||||
servletContext.setInitParameter("log4jConfigLocation", "/WEB-INF/log4j.xml");
|
servletContext.setInitParameter("log4jConfigLocation", "/WEB-INF/log4j.xml");
|
||||||
|
|
||||||
//Add Filters
|
//Add Filters
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package com.monkeyk.sos.config;
|
package com.monkeyk.sos.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.web.servlet.config.annotation.*;
|
import org.springframework.web.servlet.config.annotation.*;
|
||||||
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
||||||
|
@ -14,7 +15,8 @@ import org.springframework.web.servlet.view.JstlView;
|
||||||
*/
|
*/
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableWebMvc
|
@EnableWebMvc
|
||||||
public class MkkWebMvcConfigurer extends WebMvcConfigurerAdapter {
|
@ComponentScan(basePackages = {"com.monkeyk.sos.web"})
|
||||||
|
public class WebMvcConfigurer extends WebMvcConfigurerAdapter {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
|
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
|
|
@ -0,0 +1,60 @@
|
||||||
|
package com.monkeyk.sos.config;
|
||||||
|
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.context.annotation.Configuration;
|
||||||
|
import org.springframework.security.authentication.AuthenticationManager;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.builders.WebSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
|
||||||
|
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||||
|
import org.springframework.security.oauth2.provider.expression.OAuth2WebSecurityExpressionHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 2016/4/3
|
||||||
|
* <p/>
|
||||||
|
* Replace security.xml
|
||||||
|
*
|
||||||
|
* @author Shengzhao Li
|
||||||
|
*/
|
||||||
|
@Configuration
|
||||||
|
@EnableWebSecurity
|
||||||
|
public class WebSecurityConfigurer extends WebSecurityConfigurerAdapter {
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void configure(WebSecurity web) throws Exception {
|
||||||
|
web.expressionHandler(new OAuth2WebSecurityExpressionHandler());
|
||||||
|
web.ignoring().antMatchers("/resources/**");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Bean
|
||||||
|
public AuthenticationManager authenticationManagerBean() throws Exception {
|
||||||
|
return super.authenticationManagerBean();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void configure(HttpSecurity http) throws Exception {
|
||||||
|
|
||||||
|
http.authorizeRequests()
|
||||||
|
.antMatchers("/oauth/**").hasAnyRole("ROLE_USER,ROLE_UNITY,ROLE_MOBILE")
|
||||||
|
.antMatchers("/**").anonymous()
|
||||||
|
.and()
|
||||||
|
.exceptionHandling().accessDeniedPage("/login.jsp?authorization_error=2")
|
||||||
|
.and()
|
||||||
|
.csrf().disable()
|
||||||
|
.formLogin().loginPage("/login.jsp")
|
||||||
|
.failureUrl("/login.jsp?authentication_error=1")
|
||||||
|
.defaultSuccessUrl("/index.jsp")
|
||||||
|
.loginProcessingUrl("/login.do")
|
||||||
|
.and()
|
||||||
|
.logout().logoutUrl("/logout.do")
|
||||||
|
.logoutSuccessUrl("/index.jsp")
|
||||||
|
.and()
|
||||||
|
.anonymous();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue