From ce18581ef79637c8c6a4cac5c696598f1eb024e0 Mon Sep 17 00:00:00 2001
From: Jean-Noel Rouvignac <jean-noel.rouvignac@forgerock.com>
Date: Thu, 04 Jul 2013 08:04:19 +0000
Subject: [PATCH] Removed reflection that was used to access APIs new from JDK 6.
---
opends/src/server/org/opends/server/util/PasswordReader.java | 44 +++++---------------------------------------
1 files changed, 5 insertions(+), 39 deletions(-)
diff --git a/opends/src/server/org/opends/server/util/PasswordReader.java b/opends/src/server/org/opends/server/util/PasswordReader.java
index f4b271d..a41846d 100644
--- a/opends/src/server/org/opends/server/util/PasswordReader.java
+++ b/opends/src/server/org/opends/server/util/PasswordReader.java
@@ -23,18 +23,14 @@
*
*
* Copyright 2006-2008 Sun Microsystems, Inc.
+ * Portions copyright 2013 ForgeRock AS
*/
package org.opends.server.util;
-
-
-import java.lang.reflect.Method;
import java.util.Arrays;
import org.opends.server.api.DirectoryThread;
-
-
/**
* This class provides a means of interactively reading a password from the
* command-line without echoing it to the console. If it is running on a Java 6
@@ -84,6 +80,7 @@
mayInstantiate=false,
mayExtend=false,
mayInvoke=false)
+ @Override
public void run()
{
Thread currentThread = Thread.currentThread();
@@ -141,19 +138,12 @@
*/
public static char[] readPassword()
{
- // First, use reflection to determine whether the System.console() method
- // is available.
try
{
- Method consoleMethod = System.class.getDeclaredMethod("console",
- new Class[0]);
- if (consoleMethod != null)
+ char[] password = System.console().readPassword();
+ if (password != null)
{
- char[] password = readPasswordUsingConsole(consoleMethod);
- if (password != null)
- {
- return password;
- }
+ return password;
}
}
catch (Exception e)
@@ -173,30 +163,6 @@
/**
- * Uses reflection to invoke the <CODE>java.io.Console.readPassword()</CODE>
- * method in order to retrieve the password from the user.
- *
- * @param consoleMethod The <CODE>Method</CODE> object that may be used to
- * obtain a <CODE>Console</CODE> instance.
- *
- * @return The password as an array of characters.
- *
- * @throws Exception If any problem occurs while attempting to read the
- * password.
- */
- private static char[] readPasswordUsingConsole(Method consoleMethod)
- throws Exception
- {
- Object consoleObject = consoleMethod.invoke(null);
- Method passwordMethod =
- consoleObject.getClass().getDeclaredMethod("readPassword",
- new Class[0]);
- return (char[]) passwordMethod.invoke(consoleObject);
- }
-
-
-
- /**
* Attempts to read a password from the console by repeatedly sending
* backspace characters to mask whatever the user may have entered. This will
* be used if the <CODE>java.io.Console</CODE> class is not available.
--
Gitblit v1.10.0