当前位置: 首页>>代码示例>>Java>>正文


Java DefaultSecurityManager.setRealm方法代码示例

本文整理汇总了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;
}
 
开发者ID:wanghongfei,项目名称:shiro-spring-boot-starter,代码行数:22,代码来源:ShiroAutoConfiguration.java

示例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);
}
 
开发者ID:ops4j,项目名称:org.ops4j.pax.shiro,代码行数:22,代码来源:AbstractCdiTest.java

示例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());
}
 
开发者ID:l81893521,项目名称:shiro-demo,代码行数:39,代码来源:NonConfigurationCreateTest.java

示例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;
}
 
开发者ID:johntostring,项目名称:spring-boot-shiro,代码行数:12,代码来源:ShiroConfiguration.java

示例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;
}
 
开发者ID:storezhang,项目名称:utils,代码行数:12,代码来源:ShiroConfiguration.java

示例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;
}
 
开发者ID:boyazuo,项目名称:shiro-spring-boot,代码行数:15,代码来源:ShiroAutoConfiguration.java

示例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);
}
 
开发者ID:pmeisen,项目名称:dis-timeintervaldataanalyzer,代码行数:43,代码来源:ShiroAuthManager.java


注:本文中的org.apache.shiro.mgt.DefaultSecurityManager.setRealm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。