opends/src/server/org/opends/server/loggers/FreeDiskSpaceRetentionPolicy.java
@@ -23,33 +23,32 @@ * * * Copyright 2006-2008 Sun Microsystems, Inc. * Portions copyright 2013 ForgeRock AS */ package org.opends.server.loggers; import org.opends.messages.Message; import static org.opends.messages.LoggerMessages.*; import static org.opends.server.loggers.debug.DebugLogger.*; import static org.opends.server.util.StaticUtils.*; import java.io.File; import java.lang.reflect.Method; import java.util.Arrays; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import static org.opends.server.loggers.debug.DebugLogger.*; import static org.opends.messages.LoggerMessages.*; import org.opends.server.loggers.debug.DebugTracer; import org.opends.server.types.DebugLogLevel; import org.opends.server.types.ResultCode; import org.opends.server.types.ConfigChangeResult; import org.opends.server.types.DirectoryException; import org.opends.server.admin.std.server.FreeDiskSpaceLogRetentionPolicyCfg; import org.opends.messages.Message; import org.opends.server.admin.server.ConfigurationChangeListener; import org.opends.server.admin.std.server.FreeDiskSpaceLogRetentionPolicyCfg; import org.opends.server.core.DirectoryServer; import static org.opends.server.util.StaticUtils.stackTraceToSingleLineString; import org.opends.server.loggers.debug.DebugTracer; import org.opends.server.types.ConfigChangeResult; import org.opends.server.types.DebugLogLevel; import org.opends.server.types.DirectoryException; import org.opends.server.types.ResultCode; /** * This class implements a retention policy based on the free disk * space available expressed as a percentage. This policy is only * available on Java 6. * This class implements a retention policy based on the free disk space * available expressed as a percentage. */ public class FreeDiskSpaceRetentionPolicy implements RetentionPolicy<FreeDiskSpaceLogRetentionPolicyCfg>, @@ -66,6 +65,7 @@ /** * {@inheritDoc} */ @Override public void initializeLogRetentionPolicy( FreeDiskSpaceLogRetentionPolicyCfg config) { @@ -78,6 +78,7 @@ /** * {@inheritDoc} */ @Override public boolean isConfigurationChangeAcceptable( FreeDiskSpaceLogRetentionPolicyCfg config, List<Message> unacceptableReasons) @@ -89,6 +90,7 @@ /** * {@inheritDoc} */ @Override public ConfigChangeResult applyConfigurationChange( FreeDiskSpaceLogRetentionPolicyCfg config) { @@ -106,6 +108,7 @@ /** * {@inheritDoc} */ @Override public File[] deleteFiles(FileNamingPolicy fileNamingPolicy) throws DirectoryException { @@ -119,7 +122,7 @@ message); } ArrayList<File> filesToDelete = new ArrayList<File>(); List<File> filesToDelete = new ArrayList<File>(); if(files.length <= 0) { @@ -127,14 +130,9 @@ } long freeSpace = 0; try { // Use reflection to see use the getFreeSpace method if available. // this method is only available on Java 6. Method meth = File.class.getMethod("getFreeSpace", new Class[0]); Object value = meth.invoke(files[0]); freeSpace = ((Long) value).longValue(); freeSpace = files[0].getFreeSpace(); } catch (Exception e) { @@ -177,12 +175,13 @@ } } return filesToDelete.toArray(new File[0]); return filesToDelete.toArray(new File[filesToDelete.size()]); } /** * {@inheritDoc} */ @Override public String toString() { return "Free Disk Retention Policy " + config.dn().toString(); opends/src/server/org/opends/server/loggers/RetentionPolicy.java
@@ -23,20 +23,21 @@ * * * Copyright 2006-2008 Sun Microsystems, Inc. * Portions copyright 2013 ForgeRock AS */ package org.opends.server.loggers; import java.io.File; import org.opends.server.admin.std.server.LogRetentionPolicyCfg; import org.opends.server.config.ConfigException; import org.opends.server.types.InitializationException; import org.opends.server.types.DirectoryException; import java.io.File; import org.opends.server.types.InitializationException; /** * This interface describes the retention policy that should be used * for the logger. Supported policies include number of files and * disk utilization (for Java 6). * disk utilization. * * @param <T> The type of retention policy configuration handled by * this retention policy implementation. opends/src/server/org/opends/server/tools/EncodePassword.java
@@ -27,12 +27,10 @@ */ package org.opends.server.tools; import java.io.Console; import java.io.IOException; import java.io.OutputStream; import java.io.PrintStream; import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; @@ -58,19 +56,9 @@ import org.opends.server.loggers.debug.DebugTracer; import org.opends.server.schema.AuthPasswordSyntax; import org.opends.server.schema.UserPasswordSyntax; import org.opends.server.types.ByteString; import org.opends.server.types.DN; import org.opends.server.types.DebugLogLevel; import org.opends.server.types.DirectoryException; import org.opends.server.types.InitializationException; import org.opends.server.types.NullOutputStream; import org.opends.server.types.WritabilityMode; import org.opends.server.types.*; import org.opends.server.util.BuildVersion; import org.opends.server.util.args.ArgumentException; import org.opends.server.util.args.ArgumentParser; import org.opends.server.util.args.BooleanArgument; import org.opends.server.util.args.FileBasedArgument; import org.opends.server.util.args.StringArgument; import org.opends.server.util.args.*; import static org.opends.messages.ConfigMessages.*; import static org.opends.messages.ToolMessages.*; @@ -81,8 +69,6 @@ import static org.opends.server.util.ServerConstants.*; import static org.opends.server.util.StaticUtils.*; /** * This program provides a utility that may be used to interact with the * password storage schemes defined in the Directory Server. In particular, @@ -1070,27 +1056,17 @@ throws IOException { String password; try // JDK 6 console try { // get the Console (class the constructor) Method constructor = System.class.getDeclaredMethod("console",new Class[0]); Object console = constructor.invoke(null, new Object[0]); Console console = System.console(); if (console != null) { // class to method Class<?> c = Class.forName("java.io.Console"); Object[] args = new Object[] { prompt, new Object[0] }; Method m = c.getDeclaredMethod("readPassword", new Class[] { String.class, args.getClass() }); password = new String((char[]) m.invoke(console, args)); password = new String(console.readPassword(prompt)); } else { throw new IOException("No console"); } } catch (Exception e) { 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.