本文整理汇总了Java中org.apache.shiro.mgt.RealmSecurityManager类的典型用法代码示例。如果您正苦于以下问题:Java RealmSecurityManager类的具体用法?Java RealmSecurityManager怎么用?Java RealmSecurityManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
RealmSecurityManager类属于org.apache.shiro.mgt包,在下文中一共展示了RealmSecurityManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRealm
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T getRealm(Class<? extends Realm> realmType){
RealmSecurityManager securityManager = (RealmSecurityManager) SecurityUtils.getSecurityManager();
if(!CollectionUtils.isEmpty(securityManager.getRealms())){
for(Iterator<Realm> it = securityManager.getRealms().iterator(); it.hasNext();){
Realm realm = it.next();
if(realm.getClass().equals(realmType)){
return (T) realm;
}
}
}
return null;
}
示例2: getPrincipals
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
@Override
public PrincipalCollection getPrincipals() {
RealmSecurityManager manager = (RealmSecurityManager) SecurityUtils.getSecurityManager();
SimplePrincipalCollection ret = new SimplePrincipalCollection();
for (Realm realm : manager.getRealms()) {
/*
if (realm instanceof ProfileRealm) {
String email = token.getEmail();
if (((ProfileRealm) realm).accountExists(email)) {
ret.add(email, realm.getName());
}
}
*/
}
ret.add(token.getEmail(), bearerTokenAuthenticatingRealm.getName());
return ret;
}
示例3: contextInitialized
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
@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 );
}
}
示例4: clearCachedAuthorization
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
/**
* clears the shiro authorization cache for this user -- call when
* permissions change
*/
public void clearCachedAuthorization() {
// cache clearing
Collection crealms = ((RealmSecurityManager) SecurityUtils
.getSecurityManager()).getRealms();
Iterator cr = crealms.iterator();
while (cr.hasNext()) {
RoleSecurityJdbcRealm sm = (RoleSecurityJdbcRealm) cr.next();
try {
sm.clearCacheForPrincipalCollection(getSubject()
.getPrincipals());
} catch (Exception e) {
// may happen if we call before login()
}
}
}
示例5: synchronizeRealms
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
/**
* Synchronizes the realm's map with the security manager.
*/
protected final void synchronizeRealms() {
RealmSecurityManager securityManager = (RealmSecurityManager)
getSecurityManager();
if (securityManager != null) {
if (!realms.isEmpty()) {
securityManager.setRealms(realms.values());
} else {
// bind simple realm because it should be at least one realm
securityManager.setRealm(new SimpleAccountRealm());
}
} else {
log.warn("Realm security manager is not available. Realms is not updated");
}
}
示例6: isAutoApplyRealms
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
protected boolean isAutoApplyRealms(SecurityManager securityManager) {
boolean autoApply = true;
if (securityManager instanceof RealmSecurityManager) {
//only apply realms if they haven't been explicitly set by the user:
RealmSecurityManager realmSecurityManager = (RealmSecurityManager) securityManager;
Collection<Realm> realms = realmSecurityManager.getRealms();
if (!CollectionUtils.isEmpty(realms)) {
log.info("Realms have been explicitly set on the SecurityManager instance - auto-setting of " +
"realms will not occur.");
autoApply = false;
}
}
return autoApply;
}
示例7: assertRealmSecurityManager
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
private void assertRealmSecurityManager(SecurityManager securityManager) {
if (securityManager == null) {
throw new NullPointerException("securityManager instance cannot be null");
}
if (!(securityManager instanceof RealmSecurityManager)) {
String msg = "securityManager instance is not a " + RealmSecurityManager.class.getName() +
" instance. This is required to access or configure realms on the instance.";
throw new ConfigurationException(msg);
}
}
示例8: createEnvironment
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
@Override
protected WebEnvironment createEnvironment(ServletContext sc) {
WebEnvironment webEnvironment = super.createEnvironment(sc);
RealmSecurityManager rsm = (RealmSecurityManager) webEnvironment.getSecurityManager();
HashedCredentialsMatcher hashedCredentialsMatcher = new HashedCredentialsMatcher(HASHING_ALGORITHM);
hashedCredentialsMatcher.setStoredCredentialsHexEncoded(true);
jpaRealm.setCredentialsMatcher(hashedCredentialsMatcher);
Collection<Realm> realms = rsm.getRealms();
realms.add(jpaRealm);
rsm.setRealms(realms);
((DefaultWebEnvironment) webEnvironment).setSecurityManager(rsm);
return webEnvironment;
}
示例9: activateService
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
@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 );
}
示例10: bindWebSecurityManager
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
@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);
}
示例11: DefaultSecuritySystem
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
@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)
{
this.eventManager = checkNotNull(eventManager);
this.realmSecurityManager = checkNotNull(realmSecurityManager);
this.realmManager = checkNotNull(realmManager);
this.anonymousManager = checkNotNull(anonymousManager);
this.authorizationManagers = checkNotNull(authorizationManagers);
this.userManagers = checkNotNull(userManagers);
}
示例12: RealmManagerImpl
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
@Inject
public RealmManagerImpl(final EventManager eventManager,
final RealmConfigurationStore store,
@Named("initial") final Provider<RealmConfiguration> defaults,
final RealmSecurityManager realmSecurityManager,
final Map<String, Realm> availableRealms)
{
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);
}
示例13: AuthorizingRealmImpl
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
@Inject
public AuthorizingRealmImpl(final RealmSecurityManager realmSecurityManager,
final UserManager userManager,
final Map<String, UserManager> userManagerMap)
{
this.realmSecurityManager = realmSecurityManager;
this.userManager = userManager;
this.userManagerMap = userManagerMap;
setCredentialsMatcher(new Sha1CredentialsMatcher());
setName(NAME);
setAuthenticationCachingEnabled(false); // we authz only, no authc done by this realm
setAuthorizationCachingEnabled(true);
}
示例14: getPortofinoRealm
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
public static PortofinoRealm getPortofinoRealm() {
RealmSecurityManager realmSecurityManager =
(RealmSecurityManager)SecurityUtils.getSecurityManager();
PortofinoRealm portofinoRealm =
(PortofinoRealm) realmSecurityManager.getRealms().iterator().next();
return portofinoRealm;
}
示例15: getRealm
import org.apache.shiro.mgt.RealmSecurityManager; //导入依赖的package包/类
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();
}