View Javadoc
1   package org.apache.maven.wagon.providers.ssh.jsch;
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 com.jcraft.jsch.UserInfo;
23  import org.apache.maven.wagon.authentication.AuthenticationInfo;
24  import org.apache.maven.wagon.providers.ssh.interactive.InteractiveUserInfo;
25  
26  /**
27   * WagonUserInfo 
28   *
29   *
30   */
31  class WagonUserInfo
32      implements UserInfo
33  {
34      private final InteractiveUserInfo userInfo;
35  
36      private String password;
37  
38      private String passphrase;
39  
40      WagonUserInfo( AuthenticationInfo authInfo, InteractiveUserInfo userInfo )
41      {
42          this.userInfo = userInfo;
43  
44          this.password = authInfo.getPassword();
45  
46          this.passphrase = authInfo.getPassphrase();
47      }
48  
49      public String getPassphrase()
50      {
51          return passphrase;
52      }
53  
54      public String getPassword()
55      {
56          return password;
57      }
58  
59      public boolean promptPassphrase( String message )
60      {
61          if ( passphrase == null && userInfo != null )
62          {
63              passphrase = userInfo.promptPassphrase( message );
64          }
65          return passphrase != null;
66      }
67  
68      public boolean promptPassword( String message )
69      {
70          if ( password == null && userInfo != null )
71          {
72              password = userInfo.promptPassword( message );
73          }
74          return password != null;
75      }
76  
77      public boolean promptYesNo( String message )
78      {
79          return userInfo != null && userInfo.promptYesNo( message );
80      }
81  
82      public void showMessage( String message )
83      {
84          if ( userInfo != null )
85          {
86              userInfo.showMessage( message );
87          }
88      }
89  }