Java Code Examples for org.apache.shiro.SecurityUtils#getSecurityManager()

The following examples show how to use org.apache.shiro.SecurityUtils#getSecurityManager() . 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: CustomResolverTest.java    From usergrid with Apache License 2.0 6 votes vote down vote up
@AfterClass
public static void tearDownShiro() {
    doClearSubject();

    try {
        org.apache.shiro.mgt.SecurityManager securityManager = SecurityUtils.getSecurityManager();
        LifecycleUtils.destroy( securityManager );
    }
    catch ( UnavailableSecurityManagerException e ) {
        // we don't care about this when cleaning up the test environment
        // (for example, maybe the subclass is a unit test and it didn't
        // need a SecurityManager instance because it was using only
        // mock Subject instances)
    }
    SecurityUtils.setSecurityManager( null );
}
 
Example 2
Source File: SysRoleMenuController.java    From scaffold-cloud with MIT License 6 votes vote down vote up
/**
 * 给角色授权菜单
 *
 * @param uuid
 * @param roleId
 * @return
 */
@RequestMapping(value = "/addRoleMenu")
@ResponseBody
public ResponseModel addRoleMenu(String uuid, Long roleId) {
    uuid = uuid.replaceAll("'", "");
    final List<Long> menuIds = Arrays.stream(uuid.split(",")).map(Long::parseLong).collect(Collectors.toList());
    List<SysRoleMenuAO> list = new ArrayList<>();
    menuIds.forEach(o -> {
        final SysRoleMenuAO roleMenuAO = new SysRoleMenuAO();
        roleMenuAO.setMenuId(o);
        roleMenuAO.setRoleId(roleId);
        list.add(roleMenuAO);
    });
    ResponseModel resp = sysRoleMenuFeign.addRoleMenu(list);

    //重新刷新shrio中的url 和菜单权限
    RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    MyShiroRealm realm = (MyShiroRealm) rsm.getRealms().iterator().next();
    realm.clearCachedAuthorization();
    return resp;
}
 
Example 3
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 4
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 5
Source File: WebLogAspect.java    From SpringBoot-Base-System with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * 授权修改之后调用
 * 
 * @author 梦境迷离.
 * @time 上午9:32:02
 * @version V1.0
 *
 */
@After(value = "shiroAop()")
public void afterGrant(JoinPoint point) {
	int id = (int) point.getArgs()[0];
	log.info("第一个参数是用户id:{}", id);
	RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
	MyRealm realm = (MyRealm) rsm.getRealms().iterator().next();
	realm.clearCachedAuthorization(id);
}
 
Example 6
Source File: SSOServiceImpl.java    From nano-framework with Apache License 2.0 5 votes vote down vote up
protected SessionDAO getSessionDAO() {
    final SecurityManager securityManager = SecurityUtils.getSecurityManager();
    if(securityManager instanceof SessionsSecurityManager) {
        final SessionManager sessionManager = ((SessionsSecurityManager) securityManager).getSessionManager();
        if(sessionManager instanceof DefaultSessionManager) {
            return ((DefaultSessionManager) sessionManager).getSessionDAO();
        }
    }
    
    return null;
}
 
Example 7
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());

}
 
Example 8
Source File: RealmServiceImpl.java    From nano-framework with Apache License 2.0 5 votes vote down vote up
protected Realm getRealm() {
    final SecurityManager securityManager = SecurityUtils.getSecurityManager();
    if(securityManager instanceof RealmSecurityManager) {
        Collection<Realm> realms = ((RealmSecurityManager) securityManager).getRealms();
        if(!CollectionUtils.isEmpty(realms) && realms.size() == 1) {
            return realms.iterator().next();
        }
    }
    
    throw new MultiRealmException();
}
 
Example 9
Source File: ShiroUtils.java    From LuckyFrameWeb with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void clearCachedAuthorizationInfo()
{
    RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    UserRealm realm = (UserRealm) rsm.getRealms().iterator().next();
    realm.clearCachedAuthorizationInfo();
}
 
Example 10
Source File: ShiroLogin.java    From gazpachoquest with GNU General Public License v3.0 4 votes vote down vote up
protected static SecurityManager getSecurityManager() {
    return SecurityUtils.getSecurityManager();
}
 
Example 11
Source File: AbstractShiroTest.java    From gazpachoquest with GNU General Public License v3.0 4 votes vote down vote up
protected static SecurityManager getSecurityManager() {
    return SecurityUtils.getSecurityManager();
}
 
Example 12
Source File: AbstractShiroTest.java    From seed with Mozilla Public License 2.0 4 votes vote down vote up
protected static SecurityManager getSecurityManager() {
    return SecurityUtils.getSecurityManager();
}
 
Example 13
Source File: SecurityHelper.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns current security manager.
 */
public SecurityManager getSecurityManager() {
  return SecurityUtils.getSecurityManager();
}
 
Example 14
Source File: ShiroUtils.java    From supplierShop with MIT License 4 votes vote down vote up
public static void clearCachedAuthorizationInfo()
{
    RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    UserRealm realm = (UserRealm) rsm.getRealms().iterator().next();
    realm.clearCachedAuthorizationInfo();
}
 
Example 15
Source File: ShiroUtils.java    From RuoYi with Apache License 2.0 4 votes vote down vote up
public static void clearCachedAuthorizationInfo() {
    RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    UserRealm realm = (UserRealm) rsm.getRealms().iterator().next();
    realm.clearCachedAuthorizationInfo();
}
 
Example 16
Source File: ShiroKit.java    From kvf-admin with MIT License 4 votes vote down vote up
/**
 * 刷新权限
 */
public static void flushPrivileges() {
    RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    UserRealm realm = (UserRealm) rsm.getRealms().iterator().next();
    realm.clearCachedAuthorization();
}
 
Example 17
Source File: UserContext.java    From v-mock with MIT License 4 votes vote down vote up
public static void clearCachedAuthorizationInfo() {
    RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    CustomRealm realm = (CustomRealm) rsm.getRealms().iterator().next();
    realm.clearCachedAuthorizationInfo();
}
 
Example 18
Source File: ShiroUtils.java    From ruoyiplus with MIT License 4 votes vote down vote up
public static void clearCachedAuthorizationInfo()
{
    RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager();
    UserRealm realm = (UserRealm) rsm.getRealms().iterator().next();
    realm.clearCachedAuthorizationInfo();
}