View Javadoc
1   package org.apache.maven.wagon.providers.ssh;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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   * @author Olivier Lamy
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  }