springsecurity用户验证,默认我们为了简单,直接使用在配置文件中写死用户名和密码的方式:
在真实的系统中,我们希望用户的信息来自数据库,而不是写死的,我们就需要实现UserDetailsService接口,实现相应的方法,然后配置authentication-provider,指定我们自定义的UserDetailService。
这里定义一个类SecurityUserDetailsService,实现UserDetailsService接口:
package com.xxx.ssh.web.service.impl;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import com.xxx.ssh.web.domain.User;
import com.xxx.ssh.w