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


Java JdbcRealm.setDataSource方法代码示例

本文整理汇总了Java中org.apache.shiro.realm.jdbc.JdbcRealm.setDataSource方法的典型用法代码示例。如果您正苦于以下问题:Java JdbcRealm.setDataSource方法的具体用法?Java JdbcRealm.setDataSource怎么用?Java JdbcRealm.setDataSource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.shiro.realm.jdbc.JdbcRealm的用法示例。


在下文中一共展示了JdbcRealm.setDataSource方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: jdbcRealm

import org.apache.shiro.realm.jdbc.JdbcRealm; //导入方法依赖的package包/类
@Bean(name = "mainRealm")
@ConditionalOnMissingBean(name = "mainRealm")
@ConditionalOnProperty(prefix = "shiro.realm.jdbc", name = "enabled", havingValue = "true")
@DependsOn(value = {"dataSource", "lifecycleBeanPostProcessor", "credentialsMatcher"})
public Realm jdbcRealm(DataSource dataSource, CredentialsMatcher credentialsMatcher) {
    JdbcRealm realm = new JdbcRealm();

    if (shiroJdbcRealmProperties.getAuthenticationQuery() != null) {
        realm.setAuthenticationQuery(shiroJdbcRealmProperties.getAuthenticationQuery());
    }
    if (shiroJdbcRealmProperties.getUserRolesQuery() != null) {
        realm.setUserRolesQuery(shiroJdbcRealmProperties.getUserRolesQuery());
    }
    if (shiroJdbcRealmProperties.getPermissionsQuery() != null) {
        realm.setPermissionsQuery(shiroJdbcRealmProperties.getPermissionsQuery());
    }
    if (shiroJdbcRealmProperties.getSalt() != null) {
        realm.setSaltStyle(shiroJdbcRealmProperties.getSalt());
    }
    realm.setPermissionsLookupEnabled(shiroJdbcRealmProperties.isPermissionsLookupEnabled());
    realm.setDataSource(dataSource);
    realm.setCredentialsMatcher(credentialsMatcher);

    return realm;
}
 
开发者ID:storezhang,项目名称:utils,代码行数:26,代码来源:ShiroAutoConfiguration.java

示例2: test

import org.apache.shiro.realm.jdbc.JdbcRealm; //导入方法依赖的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

示例3: createRealm

import org.apache.shiro.realm.jdbc.JdbcRealm; //导入方法依赖的package包/类
@Override
public Realm createRealm(Injector injector) {

    DataSource ds = findDataSource(injector.getInstance(DataSourceFactory.class));

    JdbcRealm realm = new JdbcRealm();

    if (name != null) {
        realm.setName(name);
    }

    realm.setDataSource(ds);
    realm.setPermissionsLookupEnabled(lookupPermissions);

    if (authenticationQuery != null) {
        realm.setAuthenticationQuery(authenticationQuery);
    }

    if (permissionsQuery != null) {
        realm.setPermissionsQuery(permissionsQuery);
    }

    if (saltStyle != null) {
        realm.setSaltStyle(saltStyle);
    }

    if(userRolesQuery != null) {
        realm.setUserRolesQuery(userRolesQuery);
    }

    return realm;
}
 
开发者ID:bootique,项目名称:bootique-shiro,代码行数:33,代码来源:JdbcRealmFactory.java

示例4: jdbcRealm

import org.apache.shiro.realm.jdbc.JdbcRealm; //导入方法依赖的package包/类
@Bean(name = "jdbcRealm")
@DependsOn("lifecycleBeanPostProcessor")
public JdbcRealm jdbcRealm() {
    JdbcRealm realm = new JdbcRealm();
    HashedCredentialsMatcher credentialsMatcher = new HashedCredentialsMatcher();
    credentialsMatcher.setHashAlgorithmName(Sha256Hash.ALGORITHM_NAME);
    realm.setCredentialsMatcher(credentialsMatcher);
    realm.setDataSource(dataSource);
    realm.init();
    return realm;
}
 
开发者ID:mraible,项目名称:java-webapp-security-examples,代码行数:12,代码来源:WebSecurityConfig.java

示例5: createJdbcRealm

import org.apache.shiro.realm.jdbc.JdbcRealm; //导入方法依赖的package包/类
private JdbcRealm createJdbcRealm() {
    JdbcRealm realm = new JdbcRealm();
    realm.setDataSource(dataSource);
    realm.setAuthenticationQuery("SELECT user_pass FROM JAWN_USERS where user_login = ?");
    realm.setUserRolesQuery("select role_name from user_roles where username = ?");
    realm.setPermissionsLookupEnabled(false);
    realm.setSaltStyle(SaltStyle.NO_SALT); // README this of course needs to be implemented at some point
    return realm;
}
 
开发者ID:MTDdk,项目名称:jawn,代码行数:10,代码来源:JawnSecurityManagerFactory.java

示例6: provideRealm

import org.apache.shiro.realm.jdbc.JdbcRealm; //导入方法依赖的package包/类
@Singleton
@Provides
Realm provideRealm(DataSource dataSource) {
	JdbcRealm realm = new JdbcRealm();
	realm.setPermissionsLookupEnabled(true);
	realm.setDataSource(dataSource);
	realm.setCacheManager(new MemoryConstrainedCacheManager());
	return realm;
}
 
开发者ID:robertgmoss,项目名称:vectorization,代码行数:10,代码来源:AppInjector.java


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