This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 55
/
ConsoleConnectionAuthorizationHandler.java
78 lines (65 loc) · 2.1 KB
/
ConsoleConnectionAuthorizationHandler.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*******************************************************************************
* Copyright (c) 2019- UT-Battelle, LLC.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Initial API and implementation and/or initial documentation -
* Jay Jay Billings, Joe Osborn
*******************************************************************************/
package org.eclipse.ice.commands;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* @author Joe Osborn
*
*/
public class ConsoleConnectionAuthorizationHandler extends ConnectionAuthorizationHandler {
/**
* Default constructor
*/
public ConsoleConnectionAuthorizationHandler() {
}
/**
* See
* {@link org.eclipse.ice.commands.ConnectionAuthorizationHandler#getPassword()}
*/
@Override
protected char[] getPassword() {
String password = "";
// Start up a console eraser class to erase characters as they are typed to the
// console screen
ConsoleEraser eraser = new ConsoleEraser();
logger.info("Please enter your password: ");
// Read in the password
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
// Start erasing the characters that are input to the console screen
eraser.start();
try {
// Read in the password
password = in.readLine();
in.close();
} catch (IOException e) {
logger.error("Couldn't read the password...", e);
return null;
}
// Stop the thread from erasing the previous character, since other output
// is important to see
eraser.stopErasing();
System.out.print("\b");
// Return the password as a char array for added safety, since strings are
// immutable
return password.toCharArray();
}
/**
* No options required for console authorization
* See {@link org.eclipse.ice.commands.ConnectionAuthorizationHandler#setOption(String)}
*/
@Override
public void setOption(String option) {
return;
}
}