*/
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.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.
}
@Override
- protected void applyTo(ClientSession session) {
+ protected void applyTo(final ClientSession session) {
throw new IllegalStateException("Server is not allowed.");
}
};
* @param username Username to be used for authorization
* @return Builder which allows to specify credentials.
*/
- public static final Builder serverAccepted(String sessionName, String username) {
+ public static final Builder serverAccepted(final String sessionName, final String username) {
return new Builder(sessionName, username);
}
* 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<>();
- private Builder(String nodeId, String username) {
- this.nodeId = Preconditions.checkNotNull(nodeId);
- this.username = Preconditions.checkNotNull(username);
+ Builder(final String nodeId, final String username) {
+ this.nodeId = requireNonNull(nodeId);
+ this.username = requireNonNull(username);
}
/**
* @param password Password to be used for password-based authorization.
* @return this builder.
*/
- public Builder addPassword(String password) {
- this.passwords.add(password);
+ public Builder addPassword(final String password) {
+ passwords.add(password);
return this;
}
* @param clientKey Keys to be used for authorization.
* @return this builder.
*/
- public Builder addClientKeys(KeyPair clientKey) {
- this.clientKeys.add(clientKey);
+ public Builder addClientKeys(final KeyPair 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;
private final Set<KeyPair> clientKeyPair;
- ServerAllowed(String nodeId, String username, Collection<String> passwords,
- Collection<KeyPair> clientKeyPairs) {
- this.username = Preconditions.checkNotNull(username);
+ ServerAllowed(final String nodeId, final String username, final Collection<String> passwords,
+ final Collection<KeyPair> clientKeyPairs) {
+ 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
}
@Override
- protected void applyTo(ClientSession session) {
- Preconditions.checkArgument(session instanceof ClientSessionImpl);
- ((ClientSessionImpl) session).setUsername(username);
+ protected void applyTo(final ClientSession session) {
+ session.setUsername(username);
// First try authentication using server host keys, else try password.
for (KeyPair keyPair : clientKeyPair) {