import org.apache.shiro.codec.Base64;
import org.apache.shiro.crypto.hash.DefaultHashService;
-import org.apache.shiro.crypto.hash.Hash;
import org.apache.shiro.crypto.hash.HashRequest;
import org.apache.shiro.crypto.hash.SimpleHashRequest;
import org.apache.shiro.util.ByteSource;
@Override
public PasswordHash getPasswordHash(final String password) {
- final HashRequest hashRequest = new HashRequest.Builder()
- .setAlgorithmName(hashService.getHashAlgorithmName())
- .setIterations(hashService.getHashIterations())
- .setSource(ByteSource.Util.bytes(password)).build();
-
- final Hash hash = hashService.computeHash(hashRequest);
+ final var hash = hashService.computeHash(new HashRequest.Builder()
+ .setAlgorithmName(hashService.getHashAlgorithmName())
+ .setIterations(hashService.getHashIterations())
+ .setSource(ByteSource.Util.bytes(password))
+ .build());
return PasswordHashImpl.create(
- hash.getAlgorithmName(),
- hash.getSalt().toBase64(),
- hash.getIterations(),
- hash.toBase64());
+ hash.getAlgorithmName(),
+ hash.getSalt().toBase64(),
+ hash.getIterations(),
+ hash.toBase64());
}
@Override
public PasswordHash getPasswordHash(final String password, final String salt) {
- final HashRequest hashRequest = new SimpleHashRequest(
- hashService.getHashAlgorithmName(),
- ByteSource.Util.bytes(password),
- ByteSource.Util.bytes(Base64.decode(salt)),
- hashService.getHashIterations());
-
- final Hash hash = hashService.computeHash(hashRequest);
+ final var hash = hashService.computeHash(new SimpleHashRequest(
+ hashService.getHashAlgorithmName(),
+ ByteSource.Util.bytes(password),
+ ByteSource.Util.bytes(Base64.decode(salt)),
+ hashService.getHashIterations()));
return PasswordHashImpl.create(
- hash.getAlgorithmName(),
- hash.getSalt().toBase64(),
- hash.getIterations(),
- hash.toBase64());
+ hash.getAlgorithmName(),
+ hash.getSalt().toBase64(),
+ hash.getIterations(),
+ hash.toBase64());
}
@Override
import org.opendaylight.aaa.api.password.service.PasswordHash;
public final class PasswordHashImpl implements PasswordHash {
-
private final String algorithmName;
private final String salt;
private final int iterations;
private PasswordHashImpl(final String algorithmName, final String salt, final int iterations,
final String hashedPassword) {
-
this.algorithmName = algorithmName;
this.salt = salt;
this.iterations = iterations;
return new PasswordHashImpl(algorithmName, salt, iterations, hashedPassword);
}
+ @Override
public String getAlgorithmName() {
- return this.algorithmName;
+ return algorithmName;
}
+ @Override
public String getSalt() {
- return this.salt;
+ return salt;
}
+ @Override
public int getIterations() {
- return this.iterations;
+ return iterations;
}
+ @Override
public String getHashedPassword() {
- return this.hashedPassword;
+ return hashedPassword;
}
}
\ No newline at end of file