本文整理汇总了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;
}
示例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());
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}