Java Code Examples for org.apache.shiro.subject.Subject#runAs()

The following examples show how to use org.apache.shiro.subject.Subject#runAs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShiroUtils.java    From supplierShop with MIT License 5 votes vote down vote up
public static void setSysUser(SysUser user)
{
    Subject subject = getSubject();
    PrincipalCollection principalCollection = subject.getPrincipals();
    String realmName = principalCollection.getRealmNames().iterator().next();
    PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName);
    // 重新加载Principal
    subject.runAs(newPrincipalCollection);
}
 
Example 2
Source File: ShiroUtils.java    From ruoyiplus with MIT License 5 votes vote down vote up
public static void setSysUser(SysUser user)
{
    Subject subject = getSubject();
    PrincipalCollection principalCollection = subject.getPrincipals();
    String realmName = principalCollection.getRealmNames().iterator().next();
    PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName);
    // 重新加载Principal
    subject.runAs(newPrincipalCollection);
}
 
Example 3
Source File: ShiroUtils.java    From NutzSite with Apache License 2.0 5 votes vote down vote up
public static void setSysUser(User user) {
    Subject subject = getSubject();
    PrincipalCollection principalCollection = subject.getPrincipals();
    String realmName = principalCollection.getRealmNames().iterator().next();
    PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName);
    // 重新加载Principal
    subject.runAs(newPrincipalCollection);
}
 
Example 4
Source File: UserContext.java    From v-mock with MIT License 5 votes vote down vote up
public static void setSysUser(User user) {
    Subject subject = getSubject();
    PrincipalCollection principalCollection = subject.getPrincipals();
    String realmName = principalCollection.getRealmNames().iterator().next();
    PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName);
    // 重新加载Principal
    subject.runAs(newPrincipalCollection);
}
 
Example 5
Source File: RoleController.java    From springboot-learn with MIT License 5 votes vote down vote up
public void reloadAuthorizingByUserId(User user) {
    RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    UserRealm shiroRealm = (UserRealm) rsm.getRealms().iterator().next();
    Subject subject = SecurityUtils.getSubject();
    String realmName = subject.getPrincipals().getRealmNames().iterator().next();
    SimplePrincipalCollection principals = new SimplePrincipalCollection(user, realmName);
    subject.runAs(principals);
    shiroRealm.getAuthorizationCache().remove(subject.getPrincipals());
    subject.releaseRunAs();

    LOG.info("用户[{}]的权限更新成功!!", user.getUsername());

}
 
Example 6
Source File: ShiroServiceImpl.java    From springboot-shiro with MIT License 5 votes vote down vote up
/**
 * 重新加载用户权限
 *
 * @param user
 */
@Override
public void reloadAuthorizingByUserId(User user) {
    RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    ShiroRealm shiroRealm = (ShiroRealm) rsm.getRealms().iterator().next();
    Subject subject = SecurityUtils.getSubject();
    String realmName = subject.getPrincipals().getRealmNames().iterator().next();
    SimplePrincipalCollection principals = new SimplePrincipalCollection(user, realmName);
    subject.runAs(principals);
    shiroRealm.getAuthorizationCache().remove(subject.getPrincipals());
    subject.releaseRunAs();

    log.info("用户[{}]的权限更新成功!!", user.getUsername());

}
 
Example 7
Source File: ShiroUtils.java    From RuoYi with Apache License 2.0 5 votes vote down vote up
public static void setSysUser(SysUser user) {
    Subject subject = getSubject();
    PrincipalCollection principalCollection = subject.getPrincipals();
    String realmName = principalCollection.getRealmNames().iterator().next();
    PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName);
    // 重新加载Principal
    subject.runAs(newPrincipalCollection);
}
 
Example 8
Source File: ShiroUtils.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void setSysUser(User user)
{
    Subject subject = getSubject();
    PrincipalCollection principalCollection = subject.getPrincipals();
    String realmName = principalCollection.getRealmNames().iterator().next();
    PrincipalCollection newPrincipalCollection = new SimplePrincipalCollection(user, realmName);
    // 重新加载Principal
    subject.runAs(newPrincipalCollection);
}
 
Example 9
Source File: ShiroServiceImpl.java    From OneBlog with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 重新加载用户权限
 *
 * @param user
 */
private void reloadAuthorizingByUserId(User user) {
    RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    ShiroRealm shiroRealm = (ShiroRealm) rsm.getRealms().iterator().next();
    Subject subject = SecurityUtils.getSubject();
    String realmName = subject.getPrincipals().getRealmNames().iterator().next();
    SimplePrincipalCollection principals = new SimplePrincipalCollection(user.getId(), realmName);
    subject.runAs(principals);
    shiroRealm.getAuthorizationCache().remove(subject.getPrincipals());
    subject.releaseRunAs();

    log.info("用户[{}]的权限更新成功!!", user.getUsername());

}