]>
git.argeo.org Git - gpl/argeo-slc.git/blob - runtime/org.argeo.slc.support.simple/src/main/java/org/argeo/slc/jsch/SimpleUserInfo.java
1 package org
.argeo
.slc
.jsch
;
3 import java
.io
.IOException
;
4 import java
.io
.InputStream
;
5 import java
.io
.PushbackInputStream
;
6 import java
.util
.Arrays
;
8 import org
.apache
.commons
.logging
.Log
;
9 import org
.apache
.commons
.logging
.LogFactory
;
10 import org
.argeo
.slc
.SlcException
;
12 import com
.jcraft
.jsch
.UserInfo
;
14 public class SimpleUserInfo
implements UserInfo
{
15 private Boolean permissive
= true;
16 private final static Log log
= LogFactory
.getLog(SimpleUserInfo
.class);
18 private String password
;
19 private char[] passwordSafe
;
21 public void setPassword(String password
) {
22 this.password
= password
;
25 public String
getPassphrase() {
29 public String
getPassword() {
30 if (passwordSafe
!= null)
31 return new String(passwordSafe
);
35 public boolean promptPassphrase(String message
) {
39 public boolean promptPassword(String message
) {
44 passwordSafe
= readPassword(System
.in
);
45 return passwordSafe
!= null;
49 public boolean promptYesNo(String message
) {
50 String msg
= message
+ " (y/n): ";
58 c
= (char) System
.in
.read();
59 } catch (IOException e
) {
60 throw new SlcException("Cannot read stdin", e
);
69 public void showMessage(String message
) {
73 public void setPermissive(Boolean permissive
) {
74 this.permissive
= permissive
;
77 protected char[] readPassword(InputStream in
) {
84 buf
= lineBuffer
= new char[128];
86 int room
= buf
.length
;
91 switch (c
= in
.read()) {
98 if ((c2
!= '\n') && (c2
!= -1)) {
99 if (!(in
instanceof PushbackInputStream
)) {
100 in
= new PushbackInputStream(in
);
102 ((PushbackInputStream
) in
).unread(c2
);
108 buf
= new char[offset
+ 128];
109 room
= buf
.length
- offset
- 1;
110 System
.arraycopy(lineBuffer
, 0, buf
, 0, offset
);
111 Arrays
.fill(lineBuffer
, ' ');
114 buf
[offset
++] = (char) c
;
123 char[] ret
= new char[offset
];
124 System
.arraycopy(buf
, 0, ret
, 0, offset
);
125 Arrays
.fill(buf
, ' ');
128 } catch (IOException e
) {
129 throw new SlcException("Cannot read password.", e
);