web.xml进行拦截配置
| 
 <context-param> 
<param-name>contextConfigLocation</param-name> 
<param-value>classpath:spring-security.xml</param-value> 
</context-param> 
<listener> 
<listener-class> 
org.springframework.web.context.ContextLoaderListener 
</listener-class> 
</listener> 
拦截 
<filter> 
<filter-name>springSecurityFilterChain</filter-name> 
<filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class> 
</filter> 
<filter-mapping> 
<filter-name>springSecurityFilterChain</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 
 | 
springecurity配置文件
| 
 <?xml version="1.0" encoding="UTF-8"?>  
<beans:beans xmlns="http://www.springframework.org/schema/security"  
xmlns:beans="http://www.springframework.org/schema/beans"  
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
xsi:schemaLocation="http://www.springframework.org/schema/beans  
http://www.springframework.org/schema/beans/spring-beans.xsd  
http://www.springframework.org/schema/security  
http://www.springframework.org/schema/security/spring-security.xsd">  
<!-- 配置 favicon.ico 不进行安全拦截-->  
<http pattern="/favicon.ico" security="none"/>  
<!-- 以下页面不被拦截 -->  
<http pattern="/login.html" security="none"></http>  
<http pattern="/css/**" security="none"></http>  
<http pattern="/img/**" security="none"></http> 
<http pattern="/js/**" security="none"></http>  
<http pattern="/plugins/**" security="none"></http>  
<!-- 页面拦截规则 -->  
<http use-expressions="false">  
<intercept-url pattern="/**" access="ROLE_ADMIN" />  
<form-login login-page="/login.html"  
default-target-url="/admin/index.html"  
authentication-failure-url="/login.html"always-use-default-target="true"/>  
<csrf disabled="true"/>  
<headers>  
<frame-options policy="SAMEORIGIN"/>  
</headers>  
</http>  
<!-- 认证管理器 -->  
<authentication-manager>  
<authentication-provider>  
<user-service> 
//直接配置 
<user name="admin" password="123456"  
authorities="ROLE_ADMIN"/>  
<user name="sunny" password="offcn123"  
authorities="ROLE_ADMIN"/>  
</user-service> 
</authentication-provider>  
</authentication-manager>  
</beans:beans>  
 | 
获取名字
| 
 String name=SecurityContextHolder.getContext().getAuthentication().getName(); 
 | 
| 
 public class UserDetailsServiceImpl implements UserDetailsService {  
@Override  
public UserDetails loadUserByUsername(String username) throws  
UsernameNotFoundException {  
List<GrantedAuthority> grantedAuths = new ArrayList<GrantedAuthority>();  
grantedAuths.add(new SimpleGrantedAuthority("ROLE_SELLER")); 
//返回 
//return new User(username,"123456", grantedAuths); 
//或者道数据库查询 
//得到对象  
TbSeller seller = sellerService.findOne(username);  
if(seller!=null){  
if(seller.getStatus().equals("1")){  
return new User(username,seller.getPassword(),grantAuths);  
}else{ 
return null;  
} 
} 
 | 
| 
 <!-- 认证管理器 -->  
<authentication-manager>  
<authentication-provider user-service-ref="userDetailService">  
</authentication-provider>  
</authentication-manager>  
<!-- 定义自定义认证类 -->  
<beans:bean id="userDetailService"  
class="com.offcn.service.UserDetailsServiceImpl"></beans:bean>  
 | 
原文:https://www.cnblogs.com/meani/p/12712870.html