Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
PrompterUIKeyboardInteractive |
|
| 2.6666666666666665;2,667 |
1 | package org.apache.maven.wagon.providers.ssh.interactive; |
|
2 | ||
3 | /* |
|
4 | * Copyright 2001-2005 The Apache Software Foundation. |
|
5 | * |
|
6 | * Licensed under the Apache License, Version 2.0 (the "License"); |
|
7 | * you may not use this file except in compliance with the License. |
|
8 | * You may obtain a copy of the License at |
|
9 | * |
|
10 | * http://www.apache.org/licenses/LICENSE-2.0 |
|
11 | * |
|
12 | * Unless required by applicable law or agreed to in writing, software |
|
13 | * distributed under the License is distributed on an "AS IS" BASIS, |
|
14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
15 | * See the License for the specific language governing permissions and |
|
16 | * limitations under the License. |
|
17 | */ |
|
18 | ||
19 | import com.jcraft.jsch.UIKeyboardInteractive; |
|
20 | import org.codehaus.plexus.components.interactivity.Prompter; |
|
21 | import org.codehaus.plexus.components.interactivity.PrompterException; |
|
22 | ||
23 | /** |
|
24 | * UIKeyboardInteractive that use pluxus-prompter |
|
25 | * <p/> |
|
26 | * <code>UIKeyboardInteractive</code> are usefull when you don't use user with |
|
27 | * password authentication with a server that use keyboard-interactive and |
|
28 | * doesn't allow password method <code>PasswordAuthentication no</code>. |
|
29 | * |
|
30 | * @author <a href="mailto:juam at users.sourceforge.net">Juan F. Codagnone</a> |
|
31 | * @since Sep 22, 2005 |
|
32 | */ |
|
33 | public class PrompterUIKeyboardInteractive |
|
34 | implements UIKeyboardInteractive |
|
35 | { |
|
36 | private Prompter prompter; |
|
37 | ||
38 | public PrompterUIKeyboardInteractive() |
|
39 | 0 | { |
40 | 0 | } |
41 | ||
42 | public PrompterUIKeyboardInteractive( Prompter promper ) |
|
43 | 0 | { |
44 | 0 | this.prompter = promper; |
45 | 0 | } |
46 | ||
47 | /** |
|
48 | * @see UIKeyboardInteractive#promptKeyboardInteractive(String, String, |
|
49 | * String, String[], boolean[]) |
|
50 | */ |
|
51 | public String[] promptKeyboardInteractive( String destination, String name, String instruction, String[] prompt, |
|
52 | boolean[] echo ) |
|
53 | { |
|
54 | ||
55 | 0 | if ( prompt.length != echo.length ) |
56 | { |
|
57 | // jcsh is buggy? |
|
58 | 0 | throw new IllegalArgumentException( "prompt and echo size arrays are different!" ); |
59 | } |
|
60 | 0 | String[] ret = new String[prompt.length]; |
61 | ||
62 | try |
|
63 | { |
|
64 | ||
65 | 0 | for ( int i = 0; i < ret.length; i++ ) |
66 | { |
|
67 | 0 | if ( echo[i] ) |
68 | { |
|
69 | 0 | ret[i] = prompter.prompt( prompt[i] ); |
70 | 0 | } |
71 | else |
|
72 | { |
|
73 | 0 | ret[i] = prompter.promptForPassword( prompt[i] ); |
74 | } |
|
75 | } |
|
76 | } |
|
77 | 0 | catch ( PrompterException e ) |
78 | { |
|
79 | // TODO: log |
|
80 | // the user canceled? |
|
81 | 0 | ret = null; |
82 | 0 | } |
83 | ||
84 | 0 | return ret; |
85 | } |
|
86 | } |