1   package org.apache.maven.wagon.providers.ssh;
2   
3   
4   
5   
6   
7   
8   
9   
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  import org.apache.sshd.server.PasswordAuthenticator;
23  import org.apache.sshd.server.session.ServerSession;
24  import org.codehaus.plexus.util.StringUtils;
25  
26  import java.util.ArrayList;
27  import java.util.List;
28  
29  
30  
31  
32  public class TestPasswordAuthenticator
33      implements PasswordAuthenticator
34  {
35      List<PasswordAuthenticatorRequest> requests =
36          new ArrayList<PasswordAuthenticatorRequest>();
37  
38      public boolean authenticate( String username, String password, ServerSession session )
39      {
40          requests.add( new PasswordAuthenticatorRequest( username, password ) );
41          return StringUtils.equals( username, TestData.getUserName() )
42              && StringUtils.equals( password, TestData.getUserPassword() );
43      }
44  
45      
46  
47  
48      public static class PasswordAuthenticatorRequest
49      {
50          private String username;
51  
52          private String password;
53  
54          public PasswordAuthenticatorRequest( String username, String password )
55          {
56              this.username = username;
57              this.password = password;
58          }
59  
60          @Override
61          public String toString()
62          {
63              final StringBuilder sb = new StringBuilder();
64              sb.append( "PasswordAuthenticatorRequest" );
65              sb.append( "{username='" ).append( username ).append( '\'' );
66              sb.append( ", password='" ).append( password ).append( '\'' );
67              sb.append( '}' );
68              return sb.toString();
69          }
70  
71          public String getUsername()
72          {
73              return username;
74          }
75  
76          public String getPassword()
77          {
78              return password;
79          }
80      }
81  }