1、用户校验.

登录校验主要围绕着用户后台登陆的url拦截

a.围绕着用户登录过程中设计到两张用户表

jc_user:存储着用户的基本信息

jo_user:存储着用户登录、注册、更新时间及用户密码信息

b.后台用户登录负责处理的servlet是CmsLoginAct类,该类包含两个方法:

input:根据浏览器的请求指向用户登录页面。

submit:用户输入账号信息登录处理method。

@RequestMapping(value = "/login.do", method = RequestMethod.GET)
public String input(HttpServletRequest request,
HttpServletResponse response, ModelMap model) {

@RequestMapping(value = "/login.do", method = RequestMethod.POST)
public String submit(String username, String password, String captcha,String processUrl, String returnUrl, String message,
HttpServletRequest request, HttpServletResponse response,
ModelMap model) {
                    这里从submit展开,该方法中主要包含3个操作:

第一个就是用户的username、password的校验。

public UnifiedUser login(String username, String password, String ip)
throws UsernameNotFoundException, BadCredentialsException {
UnifiedUser user = getByUsername(username);//根据用户取得jo_user
if (user == null) {
throw new UsernameNotFoundException("该用户未注册: " + username);
}
//无需加密后比较
//TODO DavidfINCH
//if (!pwdEncoder.isPasswordValid(user.getPassword(), password) && !user.getPassword().equals(password)){
//不再启用暗文!
if (!user.getPassword().equals(password)) {//将取来的用户的密码和request获取的密码进行比较,如果成功则返回jo_user
updateLoginError(user.getId(), ip);
throw new BadCredentialsException("密码错误!");
}
if (!user.getActivation()) {
throw new BadCredentialsException("该用户信息需激活!");
}
updateLoginSuccess(user.getId(), ip);
return user;
}
 获取到用户信息后将用户的认证信息保存到数据库中,同时产生一个认证key,放入到session

UnifiedUser user = unifiedUserMng.login(username, password, ip);
Authentication auth = new Authentication();
auth.setUid(user.getId());
auth.setUsername(user.getUsername());
auth.setEmail(user.getEmail());
auth.setLoginIp(ip);
save(auth);
session.setAttribute(request, response, AUTH_KEY, auth.getId());
 第二个是从认证表中的取得的user_id ,再获取jc_user

最后根据传入的returnurl将direct到index.do去处理。

2、url校验

在整个过程中AdminContextInterceptor都对url进行拦截处理。

主要步骤:

从session中取得cmsUser也就是jc_user的信息。

比较url和user.getPerms

private boolean permistionPass(String uri, Set<String> perms,
boolean viewOnly) {
String u = null;
int i;
for (String perm : perms) {
if (uri.startsWith(perm)) {
// 只读管理员
if (viewOnly) {
// 获得最后一个 '/' 的URI地址。
i = uri.lastIndexOf("/");
if (i == -1) {
throw new RuntimeException("uri must start width '/':"
+ uri);
}
u = uri.substring(i + 1);
// 操作型地址被禁止
if (u.startsWith("o_")) {
return false;
}
}
return true;
}
}
return false;
}
 
---------------------
作者:jnaix
来源:CSDN
原文:https://blog.csdn.net/jnaix/article/details/84456496
版权声明:本文为博主原创文章,转载请附上博文链接!

最新文章

  1. .Net Core 1.0.0 RC2安装及示例教程
  2. Eclipse中Jquery报错
  3. [置顶] MySQL Cluster初步学习资料整理--安装部署新特性性能测试等
  4. 常用命令(ubuntu)
  5. mysql innodb myisam 主要区别与更改方法
  6. MFC网络编程
  7. Mysql中主从复制的原理、配置过程以及实际案例
  8. mysql基础篇-----mysql简介
  9. 小白的Python之路 day1 用户输入
  10. access窗体最大化到软件大小
  11. [翻译 EF Core in Action 1.8] MyFirstEfCoreApp应用程序设置
  12. [LeetCode] Peak Index in a Mountain Array 山形数组的顶峰坐标
  13. JSP知识点总结
  14. 【jdbc访问数据库获取执行sql转换json】
  15. JasperReport子报表参数传递
  16. Linux实践一:问题及解决
  17. python seek()方法报错:“io.UnsupportedOperation: can&#39;t do nonzero cur-relative seeks”
  18. ES6中的Promise使用方法与总结
  19. SRM 449 DIV 1 总结(550p标记下,下次做)
  20. DIV+CSS 按比例等分

热门文章

  1. Spring基础面试题(一)
  2. awk 一些题目
  3. 第二周课堂笔记3th and4th
  4. &lt;爬虫&gt;黑板爬虫闯关02
  5. 第二章计算机网络ios 模型
  6. CF627A Xor Equation
  7. sqlite3加密
  8. SPOJ 1043 GSS1 - Can you answer these queries I
  9. 用docker部署zabbix
  10. java线程池的使用学习