org.apache.shiro.authc.credential.HashedCredentialsMatcher.hashProvidedCredentials()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(8.2k)|赞(0)|评价(0)|浏览(105)

本文整理了Java中org.apache.shiro.authc.credential.HashedCredentialsMatcher.hashProvidedCredentials()方法的一些代码示例,展示了HashedCredentialsMatcher.hashProvidedCredentials()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HashedCredentialsMatcher.hashProvidedCredentials()方法的具体详情如下:
包路径:org.apache.shiro.authc.credential.HashedCredentialsMatcher
类名称:HashedCredentialsMatcher
方法名:hashProvidedCredentials

HashedCredentialsMatcher.hashProvidedCredentials介绍

[英]Hashes the provided credentials a total of hashIterations times, using the given salt. The hash implementation/algorithm used is based on the #getHashAlgorithmName() property.
[中]使用给定的salt对提供的凭据进行哈希运算,总共哈希迭代次数。使用的哈希实现/算法基于#getHashAlgorithmName()属性。

代码示例

代码示例来源:origin: apache/shiro

/**
 * This implementation first hashes the {@code token}'s credentials, potentially using a
 * {@code salt} if the {@code info} argument is a
 * {@link org.apache.shiro.authc.SaltedAuthenticationInfo SaltedAuthenticationInfo}.  It then compares the hash
 * against the {@code AuthenticationInfo}'s
 * {@link #getCredentials(org.apache.shiro.authc.AuthenticationInfo) already-hashed credentials}.  This method
 * returns {@code true} if those two values are {@link #equals(Object, Object) equal}, {@code false} otherwise.
 *
 * @param token the {@code AuthenticationToken} submitted during the authentication attempt.
 * @param info  the {@code AuthenticationInfo} stored in the system matching the token principal
 * @return {@code true} if the provided token credentials hash match to the stored account credentials hash,
 *         {@code false} otherwise
 * @since 1.1
 */
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
  Object tokenHashedCredentials = hashProvidedCredentials(token, info);
  Object accountCredentials = getCredentials(info);
  return equals(tokenHashedCredentials, accountCredentials);
}

代码示例来源:origin: apache/shiro

/**
 * Hash the provided {@code token}'s credentials using the salt stored with the account if the
 * {@code info} instance is an {@code instanceof} {@link SaltedAuthenticationInfo SaltedAuthenticationInfo} (see
 * the class-level JavaDoc for why this is the preferred approach).
 * <p/>
 * If the {@code info} instance is <em>not</em>
 * an {@code instanceof} {@code SaltedAuthenticationInfo}, the logic will fall back to Shiro 1.0
 * backwards-compatible logic:  it will first check to see {@link #isHashSalted() isHashSalted} and if so, will try
 * to acquire the salt from {@link #getSalt(AuthenticationToken) getSalt(AuthenticationToken)}.  See the class-level
 * JavaDoc for why this is not recommended.  This 'fallback' logic exists only for backwards-compatibility.
 * {@code Realm}s should be updated as soon as possible to return {@code SaltedAuthenticationInfo} instances
 * if account credentials salting is enabled (highly recommended for password-based systems).
 *
 * @param token the submitted authentication token from which its credentials will be hashed
 * @param info  the stored account data, potentially used to acquire a salt
 * @return the token credentials hash
 * @since 1.1
 */
protected Object hashProvidedCredentials(AuthenticationToken token, AuthenticationInfo info) {
  Object salt = null;
  if (info instanceof SaltedAuthenticationInfo) {
    salt = ((SaltedAuthenticationInfo) info).getCredentialsSalt();
  } else {
    //retain 1.0 backwards compatibility:
    if (isHashSalted()) {
      salt = getSalt(token);
    }
  }
  return hashProvidedCredentials(token.getCredentials(), salt, getHashIterations());
}

代码示例来源:origin: org.apache.shiro/shiro-core

/**
 * This implementation first hashes the {@code token}'s credentials, potentially using a
 * {@code salt} if the {@code info} argument is a
 * {@link org.apache.shiro.authc.SaltedAuthenticationInfo SaltedAuthenticationInfo}.  It then compares the hash
 * against the {@code AuthenticationInfo}'s
 * {@link #getCredentials(org.apache.shiro.authc.AuthenticationInfo) already-hashed credentials}.  This method
 * returns {@code true} if those two values are {@link #equals(Object, Object) equal}, {@code false} otherwise.
 *
 * @param token the {@code AuthenticationToken} submitted during the authentication attempt.
 * @param info  the {@code AuthenticationInfo} stored in the system matching the token principal
 * @return {@code true} if the provided token credentials hash match to the stored account credentials hash,
 *         {@code false} otherwise
 * @since 1.1
 */
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
  Object tokenHashedCredentials = hashProvidedCredentials(token, info);
  Object accountCredentials = getCredentials(info);
  return equals(tokenHashedCredentials, accountCredentials);
}

代码示例来源:origin: org.apache.shiro/shiro-core

/**
 * Hash the provided {@code token}'s credentials using the salt stored with the account if the
 * {@code info} instance is an {@code instanceof} {@link SaltedAuthenticationInfo SaltedAuthenticationInfo} (see
 * the class-level JavaDoc for why this is the preferred approach).
 * <p/>
 * If the {@code info} instance is <em>not</em>
 * an {@code instanceof} {@code SaltedAuthenticationInfo}, the logic will fall back to Shiro 1.0
 * backwards-compatible logic:  it will first check to see {@link #isHashSalted() isHashSalted} and if so, will try
 * to acquire the salt from {@link #getSalt(AuthenticationToken) getSalt(AuthenticationToken)}.  See the class-level
 * JavaDoc for why this is not recommended.  This 'fallback' logic exists only for backwards-compatibility.
 * {@code Realm}s should be updated as soon as possible to return {@code SaltedAuthenticationInfo} instances
 * if account credentials salting is enabled (highly recommended for password-based systems).
 *
 * @param token the submitted authentication token from which its credentials will be hashed
 * @param info  the stored account data, potentially used to acquire a salt
 * @return the token credentials hash
 * @since 1.1
 */
protected Object hashProvidedCredentials(AuthenticationToken token, AuthenticationInfo info) {
  Object salt = null;
  if (info instanceof SaltedAuthenticationInfo) {
    salt = ((SaltedAuthenticationInfo) info).getCredentialsSalt();
  } else {
    //retain 1.0 backwards compatibility:
    if (isHashSalted()) {
      salt = getSalt(token);
    }
  }
  return hashProvidedCredentials(token.getCredentials(), salt, getHashIterations());
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

/**
 * This implementation first hashes the {@code token}'s credentials, potentially using a
 * {@code salt} if the {@code info} argument is a
 * {@link org.apache.shiro.authc.SaltedAuthenticationInfo SaltedAuthenticationInfo}.  It then compares the hash
 * against the {@code AuthenticationInfo}'s
 * {@link #getCredentials(org.apache.shiro.authc.AuthenticationInfo) already-hashed credentials}.  This method
 * returns {@code true} if those two values are {@link #equals(Object, Object) equal}, {@code false} otherwise.
 *
 * @param token the {@code AuthenticationToken} submitted during the authentication attempt.
 * @param info  the {@code AuthenticationInfo} stored in the system matching the token principal
 * @return {@code true} if the provided token credentials hash match to the stored account credentials hash,
 *         {@code false} otherwise
 * @since 1.1
 */
@Override
public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
  Object tokenHashedCredentials = hashProvidedCredentials(token, info);
  Object accountCredentials = getCredentials(info);
  return equals(tokenHashedCredentials, accountCredentials);
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.shiro

/**
 * Hash the provided {@code token}'s credentials using the salt stored with the account if the
 * {@code info} instance is an {@code instanceof} {@link SaltedAuthenticationInfo SaltedAuthenticationInfo} (see
 * the class-level JavaDoc for why this is the preferred approach).
 * <p/>
 * If the {@code info} instance is <em>not</em>
 * an {@code instanceof} {@code SaltedAuthenticationInfo}, the logic will fall back to Shiro 1.0
 * backwards-compatible logic:  it will first check to see {@link #isHashSalted() isHashSalted} and if so, will try
 * to acquire the salt from {@link #getSalt(AuthenticationToken) getSalt(AuthenticationToken)}.  See the class-level
 * JavaDoc for why this is not recommended.  This 'fallback' logic exists only for backwards-compatibility.
 * {@code Realm}s should be updated as soon as possible to return {@code SaltedAuthenticationInfo} instances
 * if account credentials salting is enabled (highly recommended for password-based systems).
 *
 * @param token the submitted authentication token from which its credentials will be hashed
 * @param info  the stored account data, potentially used to acquire a salt
 * @return the token credentials hash
 * @since 1.1
 */
protected Object hashProvidedCredentials(AuthenticationToken token, AuthenticationInfo info) {
  Object salt = null;
  if (info instanceof SaltedAuthenticationInfo) {
    salt = ((SaltedAuthenticationInfo) info).getCredentialsSalt();
  } else {
    //retain 1.0 backwards compatibility:
    if (isHashSalted()) {
      salt = getSalt(token);
    }
  }
  return hashProvidedCredentials(token.getCredentials(), salt, getHashIterations());
}

相关文章