Search in sources :

Example 11 with DefaultWebSecurityManager

use of org.apache.shiro.web.mgt.DefaultWebSecurityManager in project littlefisher-system by littlefishercoder.

the class ShiroConfig method securityManager.

@Bean
public SecurityManager securityManager() {
    DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
    securityManager.setRealm(userRealm());
    return securityManager;
}
Also used : DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 12 with DefaultWebSecurityManager

use of org.apache.shiro.web.mgt.DefaultWebSecurityManager in project tesla by linking12.

the class AuthzConfig method securityManager.

@Bean
public SecurityManager securityManager(TeslaUserRealm userRealm) {
    DefaultWebSecurityManager manager = new DefaultWebSecurityManager();
    manager.setRealm(userRealm);
    manager.setCacheManager(getEhCacheManager());
    manager.setSessionManager(sessionManager());
    return manager;
}
Also used : DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) InitializingBean(org.springframework.beans.factory.InitializingBean) ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 13 with DefaultWebSecurityManager

use of org.apache.shiro.web.mgt.DefaultWebSecurityManager in project nutzboot by nutzam.

the class ShiroEnvStarter method getWebSecurityManager.

@IocBean(name = "shiroWebSecurityManager")
public WebSecurityManager getWebSecurityManager() {
    DefaultWebSecurityManager webSecurityManager = new DefaultWebSecurityManager() {

        protected SubjectContext resolveSession(SubjectContext context) {
            if (context.resolveSession() != null) {
                return context;
            }
            try {
                Session session = resolveContextSession(context);
                if (session != null) {
                    context.setSession(session);
                }
            } catch (InvalidSessionException e) {
            }
            return context;
        }
    };
    // Shiro Session相关
    if (conf.getBoolean(PROP_SESSION_ENABLE, true)) {
        webSecurityManager.setSessionManager(ioc.get(WebSessionManager.class, "shiroWebSessionManager"));
    }
    List<Realm> realms = new ArrayList<>();
    for (String realmName : ioc.getNamesByType(Realm.class)) {
        AuthorizingRealm realm = ioc.get(AuthorizingRealm.class, realmName);
        if (conf.getBoolean(PROP_REALM_CACHE_ENABLE, false)) {
            realm.setCacheManager(ioc.get(CacheManager.class, "shiroCacheManager"));
        }
        realms.add(realm);
    }
    if (ioc.has("authenticationStrategy")) {
        ModularRealmAuthenticator modularRealmAuthenticator = new ModularRealmAuthenticator();
        modularRealmAuthenticator.setAuthenticationStrategy(ioc.get(AuthenticationStrategy.class, "authenticationStrategy"));
        if (realms.size() > 0)
            modularRealmAuthenticator.setRealms(realms);
        webSecurityManager.setAuthenticator(modularRealmAuthenticator);
    }
    if (realms.size() > 0)
        webSecurityManager.setRealms(realms);
    webSecurityManager.setRememberMeManager(ioc.get(RememberMeManager.class, "shiroRememberMeManager"));
    return webSecurityManager;
}
Also used : InvalidSessionException(org.apache.shiro.session.InvalidSessionException) RememberMeManager(org.apache.shiro.mgt.RememberMeManager) CookieRememberMeManager(org.apache.shiro.web.mgt.CookieRememberMeManager) SubjectContext(org.apache.shiro.subject.SubjectContext) DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) AuthenticationStrategy(org.apache.shiro.authc.pam.AuthenticationStrategy) ArrayList(java.util.ArrayList) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) ModularRealmAuthenticator(org.apache.shiro.authc.pam.ModularRealmAuthenticator) LCacheManager(org.nutz.plugins.cache.impl.lcache.LCacheManager) MemoryConstrainedCacheManager(org.apache.shiro.cache.MemoryConstrainedCacheManager) RedisCacheManager(org.nutz.plugins.cache.impl.redis.RedisCacheManager) CacheManager(org.apache.shiro.cache.CacheManager) EhCacheManager(org.apache.shiro.cache.ehcache.EhCacheManager) DefaultWebSessionManager(org.apache.shiro.web.session.mgt.DefaultWebSessionManager) WebSessionManager(org.apache.shiro.web.session.mgt.WebSessionManager) Realm(org.apache.shiro.realm.Realm) AuthorizingRealm(org.apache.shiro.realm.AuthorizingRealm) Session(org.apache.shiro.session.Session) IocBean(org.nutz.ioc.loader.annotation.IocBean)

Example 14 with DefaultWebSecurityManager

use of org.apache.shiro.web.mgt.DefaultWebSecurityManager in project vip by guangdada.

the class ShiroConfig method securityManager.

/**
 * 安全管理器
 */
@Bean
public DefaultWebSecurityManager securityManager(CookieRememberMeManager rememberMeManager, CacheManager cacheShiroManager, SessionManager sessionManager) {
    DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
    securityManager.setRealm(this.shiroDbRealm());
    securityManager.setCacheManager(cacheShiroManager);
    securityManager.setRememberMeManager(rememberMeManager);
    securityManager.setSessionManager(sessionManager);
    return securityManager;
}
Also used : DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) MethodInvokingFactoryBean(org.springframework.beans.factory.config.MethodInvokingFactoryBean) EhCacheManagerFactoryBean(org.springframework.cache.ehcache.EhCacheManagerFactoryBean) Bean(org.springframework.context.annotation.Bean)

Example 15 with DefaultWebSecurityManager

use of org.apache.shiro.web.mgt.DefaultWebSecurityManager in project spring-boot-examples by ityouknow.

the class ShiroConfig method securityManager.

@Bean
public SecurityManager securityManager() {
    DefaultWebSecurityManager securityManager = new DefaultWebSecurityManager();
    securityManager.setRealm(myShiroRealm());
    return securityManager;
}
Also used : DefaultWebSecurityManager(org.apache.shiro.web.mgt.DefaultWebSecurityManager) ShiroFilterFactoryBean(org.apache.shiro.spring.web.ShiroFilterFactoryBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

DefaultWebSecurityManager (org.apache.shiro.web.mgt.DefaultWebSecurityManager)21 ShiroFilterFactoryBean (org.apache.shiro.spring.web.ShiroFilterFactoryBean)9 Bean (org.springframework.context.annotation.Bean)9 Realm (org.apache.shiro.realm.Realm)6 CookieRememberMeManager (org.apache.shiro.web.mgt.CookieRememberMeManager)3 MalformedURLException (java.net.MalformedURLException)2 ConfigurationException (org.apache.shiro.config.ConfigurationException)2 IniRealm (org.apache.shiro.realm.text.IniRealm)2 WebSecurityManager (org.apache.shiro.web.mgt.WebSecurityManager)2 DefaultWebSessionManager (org.apache.shiro.web.session.mgt.DefaultWebSessionManager)2 LdapRealm (org.apache.zeppelin.realm.LdapRealm)2 Test (org.junit.Test)2 Injector (com.google.inject.Injector)1 Provides (com.google.inject.Provides)1 ArrayList (java.util.ArrayList)1 Filter (javax.servlet.Filter)1 ServletContext (javax.servlet.ServletContext)1 Cookie (javax.servlet.http.Cookie)1 AuthenticationStrategy (org.apache.shiro.authc.pam.AuthenticationStrategy)1 ModularRealmAuthenticator (org.apache.shiro.authc.pam.ModularRealmAuthenticator)1