5.商家系统登录与安全控制
5.1 需求分析
完成商家系统登陆与安全控制,商家账号来自数据库,并实现密码加密
5.2 自定义认证类
(1)pom.xml、web.xml 、login.html 参照运营商管理后台
(2)在 pinyougou-shop-web 创 建 com.pinyougou.service 包 , 包 下 创 建 类
UserDetailsServiceImpl.java 实现 UserDetailsService 接口
package com.pinyougou.service; import java.util.ArrayList; import java.util.List;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
/**
*认证类
*@author Administrator
*
*/
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);
}
}
(3)在 pinyougou-shop-web 的 spring 目录下创建 spring-security.xml