• shiro cookie登录根据角色跳转不同页面的解决方案


    先拿到cookie,再根据jsessionid来获取username,再进行角色判断即可。

    @RequestMapping("/common/checkCookie")
        public void getUserInfo(HttpServletRequest request, HttpServletResponse response){
            String sessionID = null;
            Cookie[] cookies = request.getCookies();
            if (cookies == null){
                System.out.println("cookie null");
            }else {
                for (Cookie cookie : cookies) {
                    System.out.println(cookie.getName() + " " + cookie.getValue());
                    if ("JSESSIONID".equals(cookie.getName())){
                        sessionID = cookie.getValue();
                    }
                }
                SessionKey key = new WebSessionKey(sessionID,request,response);
                try{
                    Session se = SecurityUtils.getSecurityManager().getSession(key);
                    Object obj = se.getAttribute(DefaultSubjectContext.PRINCIPALS_SESSION_KEY);
                    //org.apache.shiro.subject.SimplePrincipalCollection cannot be cast to com.hncxhd.bywl.entity.manual.UserInfo
                    SimplePrincipalCollection coll = (SimplePrincipalCollection) obj;
                    System.out.println(coll.getPrimaryPrincipal());
                }catch(Exception e){
                    e.printStackTrace();
                }finally{
                }
            }
    
        }
  • 相关阅读:
    Linux查看所有用户用什么命令
    Sudoku Solver
    Restore IP Addresses
    Implement strStr()
    Insert Interval
    Recover Binary Search Tree
    First Missing Positive
    Rotate List
    Longest Palindromic Substring
    4Sum
  • 原文地址:https://www.cnblogs.com/kinome/p/12306186.html
Copyright © 2020-2023  润新知