Remove use of yangtools.concepts.Builder
[netconf.git] / netconf / callhome-protocol / src / main / java / org / opendaylight / netconf / callhome / protocol / CallHomeAuthorization.java
index 886021ed3c600d8da303fcd40201b91b42c64ef0..5d0e48d7eb9939a155cc83dbaece0a09c7ccbefe 100644 (file)
@@ -7,14 +7,15 @@
  */
 package org.opendaylight.netconf.callhome.protocol;
 
-import com.google.common.base.Preconditions;
+import static java.util.Objects.requireNonNull;
+
 import com.google.common.collect.ImmutableSet;
 import java.security.KeyPair;
 import java.util.Collection;
 import java.util.HashSet;
 import java.util.Set;
-import org.apache.sshd.client.session.ClientSession;
-import org.apache.sshd.client.session.ClientSessionImpl;
+import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.netconf.shaded.sshd.client.session.ClientSession;
 
 /**
  * Authorization context for incoming call home sessions.
@@ -93,19 +94,17 @@ public abstract class CallHomeAuthorization {
      * Builder for CallHomeAuthorization which accepts incoming connection.
      *
      * <p>
-     * Use {@link CallHomeAuthorization#serverAccepted(String, String)} to instantiate
-     * builder.
+     * Use {@link CallHomeAuthorization#serverAccepted(String, String)} to instantiate builder.
      */
-    public static class Builder implements org.opendaylight.yangtools.concepts.Builder<CallHomeAuthorization> {
-
+    public static class Builder {
         private final String nodeId;
         private final String username;
         private final Set<String> passwords = new HashSet<>();
         private final Set<KeyPair> clientKeys = new HashSet<>();
 
         Builder(final String nodeId, final String username) {
-            this.nodeId = Preconditions.checkNotNull(nodeId);
-            this.username = Preconditions.checkNotNull(username);
+            this.nodeId = requireNonNull(nodeId);
+            this.username = requireNonNull(username);
         }
 
         /**
@@ -115,7 +114,7 @@ public abstract class CallHomeAuthorization {
          * @return this builder.
          */
         public Builder addPassword(final String password) {
-            this.passwords.add(password);
+            passwords.add(password);
             return this;
         }
 
@@ -126,19 +125,16 @@ public abstract class CallHomeAuthorization {
          * @return this builder.
          */
         public Builder addClientKeys(final KeyPair clientKey) {
-            this.clientKeys.add(clientKey);
+            clientKeys.add(clientKey);
             return this;
         }
 
-        @Override
-        public CallHomeAuthorization build() {
+        public @NonNull CallHomeAuthorization build() {
             return new ServerAllowed(nodeId, username, passwords, clientKeys);
         }
-
     }
 
-    private static class ServerAllowed extends CallHomeAuthorization {
-
+    private static final class ServerAllowed extends CallHomeAuthorization {
         private final String nodeId;
         private final String username;
         private final Set<String> passwords;
@@ -146,10 +142,10 @@ public abstract class CallHomeAuthorization {
 
         ServerAllowed(final String nodeId, final String username, final Collection<String> passwords,
                       final Collection<KeyPair> clientKeyPairs) {
-            this.username = Preconditions.checkNotNull(username);
+            this.username = requireNonNull(username);
             this.passwords = ImmutableSet.copyOf(passwords);
-            this.clientKeyPair = ImmutableSet.copyOf(clientKeyPairs);
-            this.nodeId = Preconditions.checkNotNull(nodeId);
+            clientKeyPair = ImmutableSet.copyOf(clientKeyPairs);
+            this.nodeId = requireNonNull(nodeId);
         }
 
         @Override
@@ -164,8 +160,7 @@ public abstract class CallHomeAuthorization {
 
         @Override
         protected void applyTo(final ClientSession session) {
-            Preconditions.checkArgument(session instanceof ClientSessionImpl);
-            ((ClientSessionImpl) session).setUsername(username);
+            session.setUsername(username);
 
             // First try authentication using server host keys, else try password.
             for (KeyPair keyPair : clientKeyPair) {