Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TraditionalUIKeyboardInteractive |
|
| 1.6;1,6 |
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 org.apache.maven.wagon.authentication.AuthenticationInfo; | |
24 | ||
25 | /** | |
26 | * A conservative <code>UIKeyboardInteractive</code> that avoids real | |
27 | * user interaction :). This implementation expects only one prompt with the | |
28 | * word password in it. | |
29 | * <p/> | |
30 | * <code>UIKeyboardInteractive</code> are useful when you don't use user with | |
31 | * password authentication with a server that use keyboard-interactive and | |
32 | * doesn't allow password method <code>PasswordAuthentication no</code>. | |
33 | * | |
34 | * @author Juan F. Codagnone | |
35 | * @since Sep 21, 2005 | |
36 | */ | |
37 | public class TraditionalUIKeyboardInteractive | |
38 | implements UIKeyboardInteractive | |
39 | { | |
40 | private AuthenticationInfo authInfo; | |
41 | ||
42 | public TraditionalUIKeyboardInteractive() | |
43 | 0 | { |
44 | // void | |
45 | 0 | } |
46 | ||
47 | public TraditionalUIKeyboardInteractive( AuthenticationInfo authInfo ) | |
48 | 0 | { |
49 | 0 | this.authInfo = authInfo; |
50 | ||
51 | 0 | checkProperties(); |
52 | 0 | } |
53 | ||
54 | /** | |
55 | * @see UIKeyboardInteractive#promptKeyboardInteractive(String,String, | |
56 | *String,String[],boolean[]) | |
57 | */ | |
58 | public String[] promptKeyboardInteractive( String destination, String name, String instruction, String[] prompt, | |
59 | boolean[] echo ) | |
60 | { | |
61 | ||
62 | String[] ret; | |
63 | ||
64 | 0 | if ( prompt.length == echo.length && prompt.length == 1 && !echo[0] |
65 | && prompt[0].toLowerCase().indexOf( "password" ) > -1 ) | |
66 | { | |
67 | ||
68 | 0 | ret = new String[1]; |
69 | 0 | ret[0] = authInfo.getPassword(); |
70 | } | |
71 | else | |
72 | { | |
73 | // jsch-0.1.21/examples/UserAuthKI.java returns null to cancel | |
74 | 0 | ret = null; |
75 | } | |
76 | ||
77 | 0 | return ret; |
78 | } | |
79 | ||
80 | public void setAuthInfo( AuthenticationInfo authInfo ) | |
81 | { | |
82 | 0 | this.authInfo = authInfo; |
83 | ||
84 | 0 | checkProperties(); |
85 | 0 | } |
86 | ||
87 | private void checkProperties() | |
88 | throws IllegalArgumentException | |
89 | { | |
90 | 0 | if ( authInfo == null ) |
91 | { | |
92 | 0 | throw new IllegalArgumentException( "authorization info can't be null" ); |
93 | } | |
94 | 0 | } |
95 | } |