Clean up aaa-password-service 03/104103/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 23 Jan 2023 19:39:17 +0000 (20:39 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 23 Jan 2023 19:39:17 +0000 (20:39 +0100)
Add proper @Override annotations and simplify declarations via local
variable type inference.

Change-Id: I5f732535236947951379885efb1ff683fd25e2a5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/DefaultPasswordHashService.java
aaa-password-service/impl/src/main/java/org/opendaylight/aaa/impl/password/service/PasswordHashImpl.java

index f4d1c00ee257f5b44bfa691e1879db510900773d..af48b4af77460b0632a5d40508adb03c3d82f13d 100644 (file)
@@ -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
index 06faad0d4b182552f3bc45178fe9bf4afc7c5e00..7d6591339a87a5bc4e6579810f90ce8387db1a1b 100644 (file)
@@ -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