spring Security快速入门【spring安全】

psring security 快速入门

pom.xml 配置


 
        
            org.springframework.security
            spring-security-web
            5.0.1.RELEASE
        
        
            org.springframework.security
            spring-security-config
            5.0.1.RELEASE
        
    

web.xml配置


	contextConfigLocation
	classpath*:spring-security.xml


	org.springframework.web.context.ContextLoaderListener



	
	springSecurityFilterChain
	org.springframework.web.filter.DelegatingFilterProxy



	
	springSecurityFilterChain
	/*

spring security配置









    
    

    
    

    
    
    
    





    
        
    
    








需要实现的接口

	需要用service层的接口 来继承UserDetailsService 接口;
	public interface IUserService extends UserDetailsService {}

	通过UserDetailsService 接口来规范认证的方法;
	用UserDetails 封装正在认真的用户信息;
	public class UserServiceImp implements IUserService {
    @Autowired
    private IUserDao iud;
    Users users = null;
    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
       users =  iud.findUsername(username);
	   User user = new User(users.getUsername(),"{noop}"+users.getPassword(),users.getStatus()==0 ? false : true,true,true,true,getAuthority(users.getRoles()));
	           return user;
    }
  private List getAuthority(List roles) {
        List  authoritys  = new ArrayList<>();
        for (Role role : roles) {
            authoritys.add(new SimpleGrantedAuthority("ROLE_"+role.getRoleName()));
        }
          return  authoritys;
}

你可能感兴趣的:(spring Security快速入门【spring安全】)