zoukankan      html  css  js  c++  java
  • DefaultWebSessionManager DefaultSessionManager DefaultWebSecurityManager SessionsSecurityManager

     protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken token) throws AuthenticationException {
    System.out.println("------------------------------------doGetAuthenticationInfo(AuthenticationToken token)");
    UsernamePasswordToken utoken = (UsernamePasswordToken) token;//获取用户输入的token
    String username = utoken.getUsername();
    System.out.println("username=" + username);
    System.out.println("password=" + utoken.getPassword());

    //处理session
    SessionsSecurityManager securityManager = (SessionsSecurityManager) SecurityUtils.getSecurityManager();
    DefaultSessionManager sessionManager = (DefaultSessionManager) securityManager.getSessionManager();
    Collection<Session> sessions = sessionManager.getSessionDAO().getActiveSessions();//获取当前已登录的用户session列表
    for (Session session : sessions) {
    //清除该用户以前登录时保存的session
    // IotdUserEntity en=(IotdUserEntity)(session.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY));
    // String phone=en.getPhone();
    //如果和当前session是同一个session,则不剔除
    if (SecurityUtils.getSubject().getSession().getId().equals(session.getId()))
    break;
    IotdUserEntity user = (IotdUserEntity) (session.getAttribute("user"));
    if (user != null) {
    String phone = user.getPhone();
    if (username.equals(phone)) {
    System.out.println(username + "已登录,剔除中...");
    sessionManager.getSessionDAO().delete(session);
    }
    }
    }


    // User user = userService.findUserByUserName(username);
    IotdUserEntity user = iotdUserDao.findDistinctByPhone(username);
    SimpleAuthenticationInfo rst = new SimpleAuthenticationInfo(user, user.getPwd(), this.getClass().getName());//放入shiro.调用CredentialsMatcher检验密码
    return rst;
    }


    ——————————————————————————
    要用DefaultSessionManager
    而不能 用
    DefaultWebSessionManager

    SessionsSecurityManager和
    DefaultWebSecurityManager是同级子类,不能相互转换
  • 相关阅读:
    fastdfs部署及官网
    fasrdfs在spring cloud中的使用
    面包屑的查询
    SpringCloud中使用ES使用课程上下线
    Redis中在项目中的使用
    树结构Tree查询
    平凡的世界 田晓霞的日记 摘抄

    英语积累
    英语学习第四天
  • 原文地址:https://www.cnblogs.com/zhanying999666/p/8392621.html
Copyright © 2011-2022 走看看