Java shiro框架,切换身份后刷新subject的用户属性


/**
 * @title 切换身份,登录后,动态更改subject的用户属性
 * @param principal
 * @desc principal为用户的认证信息
 */
public static void  reloadAuthorizing(User principal) throws Exception{
    Subject subject = SecurityUtils.getSubject();
    String realmName = subject.getPrincipals().getRealmNames().iterator().next();
    SimplePrincipalCollection principals = new SimplePrincipalCollection(principal, realmName);
    subject.runAs(principals);
    // 刷新权限
    //subject.releaseRunAs();
}

你可能感兴趣的:(java,开发语言)