import java.io.IOException;
import org.apache.sshd.ClientSession;
import org.apache.sshd.client.future.AuthFuture;
+import org.opendaylight.aaa.encrypt.AAAEncryptionService;
/**
* Class Providing username/password authentication option to
* {@link org.opendaylight.netconf.nettyutil.handler.ssh.client.AsyncSshHandler}
*/
public class LoginPassword extends AuthenticationHandler {
+
private final String username;
private final String password;
+ private final AAAEncryptionService encryptionService;
public LoginPassword(String username, String password) {
+ this(username, password, null);
+ }
+
+ public LoginPassword(final String username, final String password, final AAAEncryptionService encryptionService) {
this.username = username;
this.password = password;
+ this.encryptionService = encryptionService;
}
@Override
public String getUsername() {
+ if (encryptionService != null) {
+ return encryptionService.decrypt(username);
+
+ }
return username;
}
@Override
public AuthFuture authenticate(final ClientSession session) throws IOException {
- session.addPasswordIdentity(password);
+ if (encryptionService != null) {
+ final String decryptedPassword = encryptionService.decrypt(password);
+ session.addPasswordIdentity(decryptedPassword);
+ } else {
+ session.addPasswordIdentity(password);
+ }
return session.auth();
}
}