mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 01:54:22 +00:00
DS-2231 Use console.readPassword to not echo create-administrator password
This commit is contained in:
@@ -7,8 +7,8 @@
|
|||||||
*/
|
*/
|
||||||
package org.dspace.administer;
|
package org.dspace.administer;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.Console;
|
||||||
import java.io.InputStreamReader;
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
@@ -103,8 +103,7 @@ public final class CreateAdministrator
|
|||||||
private void negotiateAdministratorDetails()
|
private void negotiateAdministratorDetails()
|
||||||
throws Exception
|
throws Exception
|
||||||
{
|
{
|
||||||
// For easier reading of typing
|
Console console = System.console();
|
||||||
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
|
|
||||||
|
|
||||||
System.out.println("Creating an initial administrator account");
|
System.out.println("Creating an initial administrator account");
|
||||||
|
|
||||||
@@ -113,8 +112,8 @@ public final class CreateAdministrator
|
|||||||
String email = null;
|
String email = null;
|
||||||
String firstName = null;
|
String firstName = null;
|
||||||
String lastName = null;
|
String lastName = null;
|
||||||
String password1 = null;
|
char[] password1 = null;
|
||||||
String password2 = null;
|
char[] password2 = null;
|
||||||
String language = I18nUtil.DEFAULTLOCALE.getLanguage();
|
String language = I18nUtil.DEFAULTLOCALE.getLanguage();
|
||||||
|
|
||||||
while (!dataOK)
|
while (!dataOK)
|
||||||
@@ -122,7 +121,7 @@ public final class CreateAdministrator
|
|||||||
System.out.print("E-mail address: ");
|
System.out.print("E-mail address: ");
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
|
|
||||||
email = input.readLine();
|
email = console.readLine();
|
||||||
if (!StringUtils.isBlank(email))
|
if (!StringUtils.isBlank(email))
|
||||||
{
|
{
|
||||||
email = email.trim();
|
email = email.trim();
|
||||||
@@ -136,7 +135,7 @@ public final class CreateAdministrator
|
|||||||
System.out.print("First name: ");
|
System.out.print("First name: ");
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
|
|
||||||
firstName = input.readLine();
|
firstName = console.readLine();
|
||||||
|
|
||||||
if (firstName != null)
|
if (firstName != null)
|
||||||
{
|
{
|
||||||
@@ -146,7 +145,7 @@ public final class CreateAdministrator
|
|||||||
System.out.print("Last name: ");
|
System.out.print("Last name: ");
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
|
|
||||||
lastName = input.readLine();
|
lastName = console.readLine();
|
||||||
|
|
||||||
if (lastName != null)
|
if (lastName != null)
|
||||||
{
|
{
|
||||||
@@ -159,7 +158,7 @@ public final class CreateAdministrator
|
|||||||
System.out.print("Language: ");
|
System.out.print("Language: ");
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
|
|
||||||
language = input.readLine();
|
language = console.readLine();
|
||||||
|
|
||||||
if (language != null)
|
if (language != null)
|
||||||
{
|
{
|
||||||
@@ -168,34 +167,25 @@ public final class CreateAdministrator
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
System.out.println("WARNING: Password will appear on-screen.");
|
System.out.println("Password will not display on screen.");
|
||||||
System.out.print("Password: ");
|
System.out.print("Password: ");
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
|
|
||||||
password1 = input.readLine();
|
|
||||||
|
|
||||||
if (password1 != null)
|
password1 = console.readPassword();
|
||||||
{
|
|
||||||
password1 = password1.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
System.out.print("Again to confirm: ");
|
System.out.print("Again to confirm: ");
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
|
|
||||||
password2 = input.readLine();
|
password2 = console.readPassword();
|
||||||
|
|
||||||
if (password2 != null)
|
//TODO real password validation
|
||||||
{
|
if (password1.length > 1 && Arrays.equals(password1, password2))
|
||||||
password2 = password2.trim();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!StringUtils.isEmpty(password1) && StringUtils.equals(password1, password2))
|
|
||||||
{
|
{
|
||||||
// password OK
|
// password OK
|
||||||
System.out.print("Is the above data correct? (y or n): ");
|
System.out.print("Is the above data correct? (y or n): ");
|
||||||
System.out.flush();
|
System.out.flush();
|
||||||
|
|
||||||
String s = input.readLine();
|
String s = console.readLine();
|
||||||
|
|
||||||
if (s != null)
|
if (s != null)
|
||||||
{
|
{
|
||||||
@@ -213,7 +203,11 @@ public final class CreateAdministrator
|
|||||||
}
|
}
|
||||||
|
|
||||||
// if we make it to here, we are ready to create an administrator
|
// if we make it to here, we are ready to create an administrator
|
||||||
createAdministrator(email, firstName, lastName, language, password1);
|
createAdministrator(email, firstName, lastName, language, String.valueOf(password1));
|
||||||
|
|
||||||
|
//Cleaning arrays that held password
|
||||||
|
Arrays.fill(password1, ' ');
|
||||||
|
Arrays.fill(password2, ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,7 +217,8 @@ public final class CreateAdministrator
|
|||||||
* @param email the email for the user
|
* @param email the email for the user
|
||||||
* @param first user's first name
|
* @param first user's first name
|
||||||
* @param last user's last name
|
* @param last user's last name
|
||||||
* @param ps desired password
|
* @param language preferred language
|
||||||
|
* @param pw desired password
|
||||||
*
|
*
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
|
Reference in New Issue
Block a user