org.apache.shiro.mgt.RealmSecurityManager Java Examples
The following examples show how to use
org.apache.shiro.mgt.RealmSecurityManager.
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: EnvironmentLoaderService.java From attic-polygene-java with Apache License 2.0 | 6 votes |
@Override public void contextInitialized( ServletContextEvent sce ) { configuration.refresh(); ShiroIniConfiguration config = configuration.get(); String iniResourcePath = config.iniResourcePath().get() == null ? "classpath:shiro.ini" : config.iniResourcePath().get(); sce.getServletContext().setInitParameter( "shiroConfigLocations", iniResourcePath ); WebEnvironment env = initEnvironment( sce.getServletContext() ); if ( realmsRefs != null && realmsRefs.iterator().hasNext() ) { // Register Realms Services RealmSecurityManager realmSecurityManager = ( RealmSecurityManager ) env.getSecurityManager(); Collection<Realm> iniRealms = new ArrayList<Realm>( realmSecurityManager.getRealms() ); for ( ServiceReference<Realm> realmRef : realmsRefs ) { iniRealms.add( realmRef.get() ); LOG.debug( "Realm Service '{}' registered!", realmRef.identity() ); } realmSecurityManager.setRealms( iniRealms ); } }
Example #2
Source File: SysRoleMenuController.java From scaffold-cloud with MIT License | 6 votes |
/** * 给角色授权菜单 * * @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: RealmManagerImpl.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Inject public RealmManagerImpl( final BeanLocator beanLocator, final EventManager eventManager, final RealmConfigurationStore store, @Named("initial") final Provider<RealmConfiguration> defaults, final RealmSecurityManager realmSecurityManager, final Map<String, Realm> availableRealms) { this.beanLocator = checkNotNull(beanLocator); this.eventManager = checkNotNull(eventManager); this.store = checkNotNull(store); log.debug("Store: {}", store); this.defaults = checkNotNull(defaults); log.debug("Defaults: {}", defaults); this.realmSecurityManager = checkNotNull(realmSecurityManager); this.availableRealms = checkNotNull(availableRealms); }
Example #4
Source File: DefaultSecuritySystem.java From nexus-public with Eclipse Public License 1.0 | 6 votes |
@Inject public DefaultSecuritySystem(final EventManager eventManager, final RealmSecurityManager realmSecurityManager, final RealmManager realmManager, final AnonymousManager anonymousManager, final Map<String, AuthorizationManager> authorizationManagers, final Map<String, UserManager> userManagers, final SecurityHelper securityHelper) { this.eventManager = checkNotNull(eventManager); this.realmSecurityManager = checkNotNull(realmSecurityManager); this.realmManager = checkNotNull(realmManager); this.anonymousManager = checkNotNull(anonymousManager); this.authorizationManagers = checkNotNull(authorizationManagers); this.userManagers = checkNotNull(userManagers); this.securityHelper = checkNotNull(securityHelper); }
Example #5
Source File: WebSecurityModule.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Override protected void bindWebSecurityManager(final AnnotatedBindingBuilder<? super WebSecurityManager> bind) { bind(NexusWebSecurityManager.class).asEagerSingleton(); // bind RealmSecurityManager and WebSecurityManager to _same_ component bind(RealmSecurityManager.class).to(NexusWebSecurityManager.class); bind.to(NexusWebSecurityManager.class); // bindings used by external modules expose(RealmSecurityManager.class); expose(WebSecurityManager.class); }
Example #6
Source File: RealmServiceImpl.java From nano-framework with Apache License 2.0 | 5 votes |
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 #7
Source File: IniSecurityManagerService.java From attic-polygene-java with Apache License 2.0 | 5 votes |
@Override public void activateService() throws Exception { configuration.refresh(); ShiroIniConfiguration config = configuration.get(); String iniResourcePath = config.iniResourcePath().get() == null ? Shiro.DEFAULT_INI_RESOURCE_PATH : config.iniResourcePath().get(); setIni( Ini.fromResourcePath( iniResourcePath ) ); securityManager = getInstance(); if ( realmsRefs != null && realmsRefs.iterator().hasNext() ) { // Register Realms Services RealmSecurityManager realmSecurityManager = ( RealmSecurityManager ) securityManager; Collection<Realm> iniRealms = new ArrayList<>( realmSecurityManager.getRealms() ); for ( ServiceReference<Realm> realmRef : realmsRefs ) { iniRealms.add( realmRef.get() ); LOG.debug( "Realm Service '{}' registered!", realmRef.identity() ); } realmSecurityManager.setRealms( iniRealms ); } ThreadContext.bind( securityManager ); }
Example #8
Source File: AuthorizingRealmImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
@Inject public AuthorizingRealmImpl(final RealmSecurityManager realmSecurityManager, final UserManager userManager, final Map<String, UserManager> userManagerMap) { this.realmSecurityManager = realmSecurityManager; this.userManager = userManager; this.userManagerMap = userManagerMap; HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher(); credentialsMatcher.setHashAlgorithmName(Sha1Hash.ALGORITHM_NAME); setCredentialsMatcher(credentialsMatcher); setName(NAME); setAuthenticationCachingEnabled(false); // we authz only, no authc done by this realm setAuthorizationCachingEnabled(true); }
Example #9
Source File: RealmManagerImpl.java From nexus-public with Eclipse Public License 1.0 | 5 votes |
/** * Clear the authentication cache for the given userId as a result of a password change. */ private void clearAuthcRealmCacheForUserId(final String userId) { // NOTE: we don't need to iterate all the Sec Managers, they use the same Realms, so one is fine. Optional.of(realmSecurityManager) .map(RealmSecurityManager::getRealms) .orElse(emptyList()) .stream() .filter(realm -> realm instanceof AuthenticatingRealmImpl) .map(realm -> (AuthenticatingRealmImpl) realm) .findFirst() .ifPresent(realm -> realm.clearCache(userId)); }
Example #10
Source File: ShiroServiceImpl.java From OneBlog with GNU General Public License v3.0 | 5 votes |
/** * 重新加载用户权限 * * @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 #11
Source File: WebLogAspect.java From SpringBoot-Base-System with GNU Lesser General Public License v3.0 | 5 votes |
/** * 授权修改之后调用 * * @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 #12
Source File: ShiroServiceImpl.java From springboot-shiro with MIT License | 5 votes |
/** * 重新加载用户权限 * * @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 #13
Source File: RoleController.java From springboot-learn with MIT License | 5 votes |
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 #14
Source File: ShiroUtils.java From LuckyFrameWeb with GNU Affero General Public License v3.0 | 4 votes |
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 supplierShop with MIT License | 4 votes |
public static void clearCachedAuthorizationInfo() { RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager(); UserRealm realm = (UserRealm) rsm.getRealms().iterator().next(); realm.clearCachedAuthorizationInfo(); }
Example #16
Source File: AnonymousAccessApiResource.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Inject public AnonymousAccessApiResource(final AnonymousManager anonymousManager, final RealmSecurityManager realmSecurityManager) { this.anonymousManager = checkNotNull(anonymousManager); this.realmSecurityManager = checkNotNull(realmSecurityManager); }
Example #17
Source File: RealmExistsValidator.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Inject public RealmExistsValidator(final RealmSecurityManager realmSecurityManager) { this.realmSecurityManager = checkNotNull(realmSecurityManager); }
Example #18
Source File: ShiroUtils.java From RuoYi with Apache License 2.0 | 4 votes |
public static void clearCachedAuthorizationInfo() { RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager(); UserRealm realm = (UserRealm) rsm.getRealms().iterator().next(); realm.clearCachedAuthorizationInfo(); }
Example #19
Source File: DefaultUserHealthCheck.java From nexus-public with Eclipse Public License 1.0 | 4 votes |
@Inject public DefaultUserHealthCheck(final RealmManager realmManager, final RealmSecurityManager realmSecurityManager) { this.realmManager = checkNotNull(realmManager); this.realmSecurityManager = checkNotNull(realmSecurityManager); }
Example #20
Source File: ShiroKit.java From kvf-admin with MIT License | 4 votes |
/** * 刷新权限 */ public static void flushPrivileges() { RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager(); UserRealm realm = (UserRealm) rsm.getRealms().iterator().next(); realm.clearCachedAuthorization(); }
Example #21
Source File: UserContext.java From v-mock with MIT License | 4 votes |
public static void clearCachedAuthorizationInfo() { RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager(); CustomRealm realm = (CustomRealm) rsm.getRealms().iterator().next(); realm.clearCachedAuthorizationInfo(); }
Example #22
Source File: ShiroUtils.java From ruoyiplus with MIT License | 4 votes |
public static void clearCachedAuthorizationInfo() { RealmSecurityManager rsm = (RealmSecurityManager) SecurityUtils.getSecurityManager(); UserRealm realm = (UserRealm) rsm.getRealms().iterator().next(); realm.clearCachedAuthorizationInfo(); }