本文整理汇总了Java中org.apache.shiro.mgt.DefaultSecurityManager.setRealm方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultSecurityManager.setRealm方法的具体用法?Java DefaultSecurityManager.setRealm怎么用?Java DefaultSecurityManager.setRealm使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.shiro.mgt.DefaultSecurityManager
的用法示例。
在下文中一共展示了DefaultSecurityManager.setRealm方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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());
}
示例4: 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;
}
示例5: 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;
}
示例6: getShiroFilterFactoryBean
import org.apache.shiro.mgt.DefaultSecurityManager; //导入方法依赖的package包/类
@Bean(name = "shiroFilter")
@DependsOn("securityManager")
@ConditionalOnMissingBean
public ShiroFilterFactoryBean getShiroFilterFactoryBean(DefaultSecurityManager securityManager, Realm realm) {
securityManager.setRealm(realm);
ShiroFilterFactoryBean shiroFilter = new ShiroFilterFactoryBean();
shiroFilter.setSecurityManager(securityManager);
shiroFilter.setLoginUrl(properties.getLoginUrl());
shiroFilter.setSuccessUrl(properties.getSuccessUrl());
shiroFilter.setUnauthorizedUrl(properties.getUnauthorizedUrl());
shiroFilter.setFilterChainDefinitionMap(properties.getFilterChainDefinitionMap());
return shiroFilter;
}
示例7: init
import org.apache.shiro.mgt.DefaultSecurityManager; //导入方法依赖的package包/类
@Override
public void init() {
if (LOG.isTraceEnabled()) {
LOG.trace("Initializing the '" + getClass().getSimpleName()
+ "' using the default settings.");
}
// use the default realm
final MapDbAuthorizingRealm realm = new MapDbAuthorizingRealm(
handler.getDefaultLocation(true));
if (realm instanceof Initializable) {
realm.init();
}
// create a default manager and set it
final DefaultSecurityManager manager = new DefaultSecurityManager();
manager.setRealm(realm);
// get the manager and initialize it
if (manager instanceof Initializable) {
((Initializable) manager).init();
}
this.manager = manager;
final SessionManager sessionManager = this.manager.getSessionManager();
if (sessionManager instanceof AbstractValidatingSessionManager) {
((AbstractValidatingSessionManager) sessionManager)
.setSessionValidationSchedulerEnabled(false);
}
final SubjectDAO subjectDao = this.manager.getSubjectDAO();
if (subjectDao instanceof DefaultSubjectDAO) {
final SessionStorageEvaluator sessionStorageEvaluator = ((DefaultSubjectDAO) this.manager
.getSubjectDAO()).getSessionStorageEvaluator();
if (sessionStorageEvaluator instanceof DefaultSessionStorageEvaluator) {
((DefaultSessionStorageEvaluator) sessionStorageEvaluator)
.setSessionStorageEnabled(false);
}
}
this.builder = new Subject.Builder(manager);
this.builder.sessionCreationEnabled(false);
}