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 { @Overridepublic UserDetails loadUserByUsername(String username) throwsUsernameNotFoundException {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
经过上述配置,用户在输入密码 123456 时就会通过(用户名随意)
點(diǎn)擊查看更多內(nèi)容
為 TA 點(diǎn)贊
評(píng)論
評(píng)論
共同學(xué)習(xí),寫下你的評(píng)論
評(píng)論加載中...
作者其他優(yōu)質(zhì)文章
正在加載中
感謝您的支持,我會(huì)繼續(xù)努力的~
掃碼打賞,你說多少就多少
贊賞金額會(huì)直接到老師賬戶
支付方式
打開微信掃一掃,即可進(jìn)行掃碼打賞哦