View Javadoc
1   package org.apache.maven.wagon.providers.ssh.jsch.interactive;
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.UIKeyboardInteractive;
23  import com.jcraft.jsch.UserInfo;
24  
25  /**
26   * A proxy that let you merge a <code>UserInfo</code> and a
27   * <code>UIKeyboardInteractive</code>
28   *
29   * @author Juan F. Codagnone
30   * @since Sep 22, 2005
31   */
32  public class UserInfoUIKeyboardInteractiveProxy
33      implements UserInfo, UIKeyboardInteractive
34  {
35      private final UIKeyboardInteractive interactive;
36  
37      private final UserInfo userInfo;
38  
39      public UserInfoUIKeyboardInteractiveProxy( UserInfo userInfo, UIKeyboardInteractive interactive )
40      {
41          this.userInfo = userInfo;
42          this.interactive = interactive;
43      }
44  
45      /**
46       * @see com.jcraft.jsch.UIKeyboardInteractive#promptKeyboardInteractive(String,String,String,String[],boolean[])
47       */
48      public String[] promptKeyboardInteractive( String destination, String name, String instruction, String[] prompt,
49                                                 boolean[] echo )
50      {
51          if ( userInfo.getPassword() != null && prompt != null && prompt.length != 0 )
52          {
53              prompt[0] = "Keyboard interactive required, supplied password is ignored\n" + prompt[0];
54          }
55          return interactive.promptKeyboardInteractive( destination, name, instruction, prompt, echo );
56      }
57  
58      /**
59       * @see com.jcraft.jsch.UserInfo#getPassphrase()
60       */
61      public String getPassphrase()
62      {
63          return userInfo.getPassphrase();
64      }
65  
66      /**
67       * @see com.jcraft.jsch.UserInfo#getPassword()
68       */
69      public String getPassword()
70      {
71          return userInfo.getPassword();
72      }
73  
74      /**
75       * @see com.jcraft.jsch.UserInfo#promptPassword(String)
76       */
77      public boolean promptPassword( String arg0 )
78      {
79          return userInfo.promptPassword( arg0 );
80      }
81  
82      /**
83       * @see com.jcraft.jsch.UserInfo#promptPassphrase(String)
84       */
85      public boolean promptPassphrase( String arg0 )
86      {
87          return userInfo.promptPassphrase( arg0 );
88      }
89  
90      /**
91       * @see com.jcraft.jsch.UserInfo#promptYesNo(String)
92       */
93      public boolean promptYesNo( String arg0 )
94      {
95          return userInfo.promptYesNo( arg0 );
96      }
97  
98      /**
99       * @see com.jcraft.jsch.UserInfo#showMessage(String)
100      */
101     public void showMessage( String arg0 )
102     {
103         userInfo.showMessage( arg0 );
104     }
105 
106 }