org.apache.shiro.realm.jdbc.JdbcRealm Java Examples

The following examples show how to use org.apache.shiro.realm.jdbc.JdbcRealm. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ShiroAutoConfiguration.java    From utils with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #2
Source File: WebSecurityConfig.java    From java-webapp-security-examples with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example #3
Source File: ShiroAuthenticationService.java    From zeppelin with Apache License 2.0 5 votes vote down vote up
/**
 * Get candidated users based on searchText
 *
 * @param searchText
 * @param numUsersToFetch
 * @return
 */
@Override
public List<String> getMatchedUsers(String searchText, int numUsersToFetch) {
  List<String> usersList = new ArrayList<>();
  try {
    Collection<Realm> realmsList = getRealmsList();
    if (realmsList != null) {
      for (Realm realm : realmsList) {
        String realClassName = realm.getClass().getName();
        LOGGER.debug("RealmClass.getName: " + realClassName);
        if (realClassName.equals("org.apache.shiro.realm.text.IniRealm")) {
          usersList.addAll(getUserList((IniRealm) realm));
        } else if (realClassName.equals("org.apache.zeppelin.realm.LdapGroupRealm")) {
          usersList.addAll(getUserList((JndiLdapRealm) realm, searchText, numUsersToFetch));
        } else if (realClassName.equals("org.apache.zeppelin.realm.LdapRealm")) {
          usersList.addAll(getUserList((LdapRealm) realm, searchText, numUsersToFetch));
        } else if (realClassName.equals("org.apache.zeppelin.realm.ActiveDirectoryGroupRealm")) {
          usersList.addAll(
              getUserList((ActiveDirectoryGroupRealm) realm, searchText, numUsersToFetch));
        } else if (realClassName.equals("org.apache.shiro.realm.jdbc.JdbcRealm")) {
          usersList.addAll(getUserList((JdbcRealm) realm));
        }
      }
    }
  } catch (Exception e) {
    LOGGER.error("Exception in retrieving Users from realms ", e);
  }
  return usersList;
}
 
Example #4
Source File: ShiroJdbcRealmProperties.java    From spring-boot-shiro with Apache License 2.0 4 votes vote down vote up
public JdbcRealm.SaltStyle getSalt() {
    return salt;
}
 
Example #5
Source File: ShiroJdbcRealmProperties.java    From spring-boot-shiro with Apache License 2.0 4 votes vote down vote up
public void setSalt(JdbcRealm.SaltStyle salt) {
    this.salt = salt;
}
 
Example #6
Source File: ShiroJdbcRealmProperties.java    From utils with Apache License 2.0 4 votes vote down vote up
public JdbcRealm.SaltStyle getSalt() {
    return salt;
}
 
Example #7
Source File: ShiroJdbcRealmProperties.java    From utils with Apache License 2.0 4 votes vote down vote up
public void setSalt(JdbcRealm.SaltStyle salt) {
    this.salt = salt;
}