View Javadoc

1   package org.apache.maven.wagon.providers.ssh;
2   /*
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   */
20  
21  import org.apache.sshd.server.PasswordAuthenticator;
22  import org.apache.sshd.server.session.ServerSession;
23  import org.codehaus.plexus.util.StringUtils;
24  
25  import java.util.ArrayList;
26  import java.util.List;
27  
28  /**
29   * @author Olivier Lamy
30   */
31  public class TestPasswordAuthenticator
32      implements PasswordAuthenticator
33  {
34      public List<PasswordAuthenticatorRequest> passwordAuthenticatorRequests =
35          new ArrayList<PasswordAuthenticatorRequest>();
36  
37      public boolean authenticate( String username, String password, ServerSession session )
38      {
39          passwordAuthenticatorRequests.add( new PasswordAuthenticatorRequest( username, password ) );
40          return StringUtils.equals( username, TestData.getUserName() ) && StringUtils.equals( password,
41                                                                                               TestData.getUserPassword() );
42      }
43  
44      public static class PasswordAuthenticatorRequest
45      {
46          public String username;
47  
48          public String password;
49  
50          public PasswordAuthenticatorRequest( String username, String password )
51          {
52              this.username = username;
53              this.password = password;
54          }
55  
56          @Override
57          public String toString()
58          {
59              final StringBuilder sb = new StringBuilder();
60              sb.append( "PasswordAuthenticatorRequest" );
61              sb.append( "{username='" ).append( username ).append( '\'' );
62              sb.append( ", password='" ).append( password ).append( '\'' );
63              sb.append( '}' );
64              return sb.toString();
65          }
66      }
67  }