From a625ca3bec22d4cfe48a3c86a65be626cc499f4a Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 23 Jan 2023 20:39:17 +0100 Subject: [PATCH] Clean up aaa-password-service Add proper @Override annotations and simplify declarations via local variable type inference. Change-Id: I5f732535236947951379885efb1ff683fd25e2a5 Signed-off-by: Robert Varga --- .../service/DefaultPasswordHashService.java | 40 +++++++++---------- .../password/service/PasswordHashImpl.java | 14 ++++--- 2 files changed, 26 insertions(+), 28 deletions(-) diff --git a/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/DefaultPasswordHashService.java b/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/DefaultPasswordHashService.java index f4d1c00ee..af48b4af7 100644 --- a/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/DefaultPasswordHashService.java +++ b/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/DefaultPasswordHashService.java @@ -9,7 +9,6 @@ package org.opendaylight.aaa.impl.password.service; 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; @@ -39,33 +38,30 @@ public class DefaultPasswordHashService implements PasswordHashService { @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 diff --git a/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/PasswordHashImpl.java b/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/PasswordHashImpl.java index 06faad0d4..7d6591339 100644 --- a/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/PasswordHashImpl.java +++ b/aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/PasswordHashImpl.java @@ -10,7 +10,6 @@ package org.opendaylight.aaa.impl.password.service; 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; @@ -18,7 +17,6 @@ public final class PasswordHashImpl implements PasswordHash { private PasswordHashImpl(final String algorithmName, final String salt, final int iterations, final String hashedPassword) { - this.algorithmName = algorithmName; this.salt = salt; this.iterations = iterations; @@ -31,19 +29,23 @@ public final class PasswordHashImpl implements PasswordHash { 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 -- 2.36.6