本文整理汇总了Java中org.apache.shiro.mgt.DefaultSecurityManager类的典型用法代码示例。如果您正苦于以下问题:Java DefaultSecurityManager类的具体用法?Java DefaultSecurityManager怎么用?Java DefaultSecurityManager使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultSecurityManager类属于org.apache.shiro.mgt包,在下文中一共展示了DefaultSecurityManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: provideSecurityManager
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
@Provides
@Singleton
SecurityManager provideSecurityManager(
SessionManager sessionManager,
RememberMeManager rememberMeManager,
Realms realms,
Set<AuthenticationListener> authListeners) {
DefaultSecurityManager manager = new DefaultSecurityManager(realms.getRealms());
((AbstractAuthenticator) manager.getAuthenticator()).setAuthenticationListeners(authListeners);
manager.setSessionManager(sessionManager);
manager.setRememberMeManager(rememberMeManager);
return manager;
}
示例2: CentralDogmaSecurityManager
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
public CentralDogmaSecurityManager(File dataDir, Ini securityConfig) {
try {
sessionDao = new FileBasedSessionDAO(new File(dataDir, "_sessions").toPath());
} catch (IOException e) {
throw new IOError(e);
}
sessionManager = new CentralDogmaSessionManager(sessionDao);
final Factory<SecurityManager> factory = new IniSecurityManagerFactory(securityConfig) {
@Override
protected SecurityManager createDefaultInstance() {
DefaultSecurityManager securityManager = new DefaultSecurityManager();
securityManager.setSessionManager(sessionManager);
securityManager.setCacheManager(new MemoryConstrainedCacheManager());
return securityManager;
}
};
delegate = factory.getInstance();
}
示例3: securityManager
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
@Bean(name = "securityManager")
@ConditionalOnMissingBean
public DefaultSecurityManager securityManager(CacheManager shiroCacheManager) {
DefaultWebSecurityManager dwsm = new DefaultWebSecurityManager();
// 用自己的Factory实现替换默认
// 用于关闭session功能
dwsm.setSubjectFactory(new StatelessSubjectFactory());
dwsm.setSessionManager(defaultSessionManager());
// 关闭session存储
((DefaultSessionStorageEvaluator) ((DefaultSubjectDAO)dwsm.getSubjectDAO()).getSessionStorageEvaluator()).setSessionStorageEnabled(false);
// <!-- 用户授权/认证信息Cache, 采用EhCache 缓存 -->
dwsm.setCacheManager(shiroCacheManager);
SecurityUtils.setSecurityManager(dwsm);
return dwsm;
}
示例4: getShiroFilterFactoryBean
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
@Bean(name = "shiroFilter")
@DependsOn("securityManager")
@ConditionalOnMissingBean
public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultSecurityManager securityManager, Realm realm, ShiroFilterRegistry registry) {
securityManager.setRealm(realm);
Map<String, String> filterDef = swapKeyValue(properties.getFilterChainDefinitions());
log.info("过虑器配置: {}", filterDef);
log.info("自定义过虑器: {}", registry.getFilterMap());
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
shiroFilter.setSecurityManager(securityManager);
shiroFilter.setLoginUrl(properties.getLoginUrl());
shiroFilter.setSuccessUrl(properties.getSuccessUrl());
shiroFilter.setUnauthorizedUrl(properties.getUnauthorizedUrl());
shiroFilter.setFilterChainDefinitionMap(filterDef);
shiroFilter.getFilters().putAll(registry.getFilterMap());
return shiroFilter;
}
示例5: provideSecurityManager
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
@Provides @Singleton SecurityManager provideSecurityManager(KhaRealm khaRealm,
OAuth2Realm oauth2Realm,
CacheManager cacheManager) {
Factory<SecurityManager> factory = new AbstractFactory<SecurityManager>() {
@Override
protected SecurityManager createInstance() {
DefaultSecurityManager manager = new DefaultSecurityManager();
manager.setRealms(Arrays.asList(khaRealm, oauth2Realm));
manager.setCacheManager(cacheManager);
return manager;
}
};
SecurityManager securityManager = factory.getInstance();
SecurityUtils.setSecurityManager(securityManager);
return securityManager;
}
示例6: start
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
@BeforeClass
public static void start() throws Exception {
securityManager = new DefaultSecurityManager();
SecurityUtils.setSecurityManager(securityManager);
realm = new SimpleAccountRealm("test-realm");
realm.addRole("role");
realm.addAccount("foo", "bar", "role");
realm.addAccount("bilbo", "precious", "hobbit");
realm.setRolePermissionResolver(new RolePermissionResolver() {
public Collection<Permission> resolvePermissionsInRole(String roleString) {
if ("role".equals(roleString)) {
final Permission dp = new WildcardPermission("permission");
return Arrays.asList(dp);
}
return Collections.emptyList();
}
});
securityManager.setRealm(realm);
}
示例7: getCdiBeanFromIni
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
@Test
public void getCdiBeanFromIni() {
CdiIniSecurityManagerFactory securityManagerFactory = new CdiIniSecurityManagerFactory("classpath:test-shiro-cdi.ini", beanManager);
DefaultSecurityManager securityManager = (DefaultSecurityManager) securityManagerFactory.createInstance();
assertThat(securityManager, is(notNullValue()));
SecurityUtils.setSecurityManager(securityManager);
Object passwordMatcher = securityManagerFactory.getBeans().get("myPasswordMatcher");
assertThat(passwordMatcher, is(instanceOf(MyPasswordMatcher.class)));
IniRealm realm = (IniRealm) securityManager.getRealms().iterator().next();
assertThat(realm.getCredentialsMatcher(), is(instanceOf(MyPasswordMatcher.class)));
Subject subject = SecurityUtils.getSubject();
assertThat(subject, is(notNullValue()));
assertThat(subject.getPrincipal(), is(nullValue()));
assertThat(subject.isAuthenticated(), is(false));
UsernamePasswordToken token = new UsernamePasswordToken("admin", "secret");
subject.login(token);
assertThat(subject.isAuthenticated(), is(true));
subject.logout();
assertThat(subject.isAuthenticated(), is(false));
}
示例8: checkInjectedSubject
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
@Test
public void checkInjectedSubject() {
CdiIniSecurityManagerFactory securityManagerFactory = new CdiIniSecurityManagerFactory("classpath:test-shiro-cdi.ini", beanManager);
DefaultSecurityManager securityManager = (DefaultSecurityManager) securityManagerFactory.createInstance();
assertThat(securityManager, is(notNullValue()));
SecurityUtils.setSecurityManager(securityManager);
assertThat(subject, is(notNullValue()));
assertThat(subject.getPrincipal(), is(nullValue()));
assertThat(subject.isAuthenticated(), is(false));
UsernamePasswordToken token = new UsernamePasswordToken("admin", "secret");
subject.login(token);
assertThat(subject.isAuthenticated(), is(true));
subject.logout();
assertThat(subject.isAuthenticated(), is(false));
}
示例9: shiroFilterFactoryBean
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
/**
* 对过滤器进行调整
*
* @param securityManager
* @return
*/
@Bean
protected ShiroFilterFactoryBean shiroFilterFactoryBean(SecurityManager securityManager, SubjectFactory subjectFactory,@Qualifier("filters") Map<String, Filter> filters) {
//把subject对象设为subjectFactory
((DefaultSecurityManager) securityManager).setSubjectFactory(subjectFactory);
ShiroFilterFactoryBean filterFactoryBean = super.shiroFilterFactoryBean();
filterFactoryBean.setSecurityManager(securityManager);
filterFactoryBean.setFilters(filters);
return filterFactoryBean;
}
示例10: setSecurityManager
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
public void setSecurityManager(SecurityManager securityManager) {
if (securityManager == null) {
return;
}
this.securityManager = securityManager;
Realm realm = new CustomAuthRealm(securityManager);
DefaultSecurityManager shiroManager = new DefaultSecurityManager(realm);
SecurityUtils.setSecurityManager(shiroManager);
increaseShiroGlobalSessionTimeout(shiroManager);
isIntegratedSecurity = true;
isClientAuthenticator = false;
isPeerAuthenticator = false;
}
示例11: increaseShiroGlobalSessionTimeout
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
private void increaseShiroGlobalSessionTimeout(final DefaultSecurityManager shiroManager) {
SessionManager sessionManager = shiroManager.getSessionManager();
if (DefaultSessionManager.class.isInstance(sessionManager)) {
DefaultSessionManager defaultSessionManager = (DefaultSessionManager) sessionManager;
defaultSessionManager.setGlobalSessionTimeout(Long.MAX_VALUE);
long value = defaultSessionManager.getGlobalSessionTimeout();
if (value != Long.MAX_VALUE) {
logger.error("Unable to set Shiro Global Session Timeout. Current value is '{}'.", value);
}
} else {
logger.error("Unable to set Shiro Global Session Timeout. Current SessionManager is '{}'.",
sessionManager == null ? "null" : sessionManager.getClass());
}
}
示例12: shiroFilterFactoryBean
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
/**
* 对过滤器进行调整
*
* @return
*/
@Bean
protected ShiroFilterFactoryBean shiroFilterFactoryBean() {
//把subject对象设为subjectFactory
//由于cas代理了用户,所以必须通过cas进行创建对象
((DefaultSecurityManager) securityManager).setSubjectFactory(new Pac4jSubjectFactory());
ShiroFilterFactoryBean filterFactoryBean = super.shiroFilterFactoryBean();
filterFactoryBean.setFilters(shiroFilters());
return filterFactoryBean;
}
示例13: test
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
@Test
public void test(){
DefaultSecurityManager securityManager = new DefaultSecurityManager();
//设置authenticator
ModularRealmAuthenticator authenticator = new ModularRealmAuthenticator();
authenticator.setAuthenticationStrategy(new AtLeastOneSuccessfulStrategy());
securityManager.setAuthenticator(authenticator);
//设置authorizer
ModularRealmAuthorizer authorizer = new ModularRealmAuthorizer();
authorizer.setPermissionResolver(new WildcardPermissionResolver());
securityManager.setAuthorizer(authorizer);
//创建datasource
DruidDataSource dataSource = new DruidDataSource();
dataSource.setDriverClassName("com.mysql.jdbc.Driver");
dataSource.setUrl("jdbc:mysql://192.168.31.188:3306/shiro");
dataSource.setUsername("root");
dataSource.setPassword("[email protected]");
//设置real
JdbcRealm realm = new JdbcRealm();
realm.setDataSource(dataSource);
realm.setPermissionsLookupEnabled(true);
securityManager.setRealm(realm);
//将SecurityManager设置到SecurityUtils,方便全局使用
SecurityUtils.setSecurityManager(securityManager);
Subject subject = SecurityUtils.getSubject();
UsernamePasswordToken token = new UsernamePasswordToken("zhang", "123");
subject.login(token);
Assert.assertTrue(subject.isAuthenticated());
}
示例14: securityManager
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
@Bean(name = "securityManager")
@DependsOn(value = {"cacheManager", "rememberMeManager", "mainRealm"})
public DefaultSecurityManager securityManager(Realm realm, RememberMeManager rememberMeManager,
CacheManager cacheManager, SessionManager sessionManager) {
DefaultSecurityManager sm = new DefaultWebSecurityManager();
sm.setRealm(realm);
sm.setCacheManager(cacheManager);
sm.setSessionManager(sessionManager);
sm.setRememberMeManager(rememberMeManager);
return sm;
}
示例15: getAuthorizationAttributeSourceAdvisor
import org.apache.shiro.mgt.DefaultSecurityManager; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean
public AuthorizationAttributeSourceAdvisor getAuthorizationAttributeSourceAdvisor(DefaultSecurityManager securityManager) {
AuthorizationAttributeSourceAdvisor aasa = new AuthorizationAttributeSourceAdvisor();
aasa.setSecurityManager(securityManager);
return aasa;
}