zoukankan      html  css  js  c++  java
  • 动态改变shiro的Principal属性

    因为要保存一些用户名之外的内容在shiro中,所以创建了一个ShiroUser的类,当用户修改了某些属性后,如何动态保存到shiro中:

    Subject subject = SecurityUtils.getSubject();
    ShiroUser shiroUser = (ShiroUser)subject.getPrincipal();
    PrincipalCollection principalCollection = subject.getPrincipals();
    //修改属性
    shiroUser.setUsername("123");
    String realmName = principalCollection.getRealmNames().iterator().next();
    PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(shiroUser, realmName);
    //重新加载Principal
    subject.runAs(newPrincipalCollection)
    思路就是重建一个PrincipalCollection,以它来运行

  • 相关阅读:
    Python
    Python
    Python
    Python
    python
    python
    Python
    pure css做的pc登陆界面
    MvcAdmin功能介绍
    pure css做的手机版博客园(我自己博客)
  • 原文地址:https://www.cnblogs.com/exmyth/p/13261860.html
Copyright © 2011-2022 走看看