mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

Violette Roche-Montane
05.32.2014 9d1e0a2b58c07ff470a8678f458ed29d69d9223d
OPENDJ-1303 "opendj-cli"
- Fixed log warnings / info.

6 files modified
75 ■■■■ changed files
opendj-cli/src/main/java/com/forgerock/opendj/cli/ApplicationKeyManager.java 16 ●●●● patch | view | raw | blame | history
opendj-cli/src/main/java/com/forgerock/opendj/cli/ConsoleApplication.java 6 ●●●●● patch | view | raw | blame | history
opendj-cli/src/main/java/com/forgerock/opendj/cli/PromptingTrustManager.java 15 ●●●● patch | view | raw | blame | history
opendj-cli/src/main/java/com/forgerock/opendj/cli/TabSeparatedTablePrinter.java 7 ●●●●● patch | view | raw | blame | history
opendj-cli/src/main/java/com/forgerock/opendj/cli/TextTablePrinter.java 7 ●●●●● patch | view | raw | blame | history
opendj-cli/src/test/java/com/forgerock/opendj/cli/UtilsTestCase.java 24 ●●●●● patch | view | raw | blame | history
opendj-cli/src/main/java/com/forgerock/opendj/cli/ApplicationKeyManager.java
@@ -36,14 +36,14 @@
import java.security.PrivateKey;
import java.security.UnrecoverableKeyException;
import java.security.cert.X509Certificate;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509KeyManager;
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.slf4j.LocalizedLogger;
/**
 * This class is in charge of checking whether the certificates that are
 * presented are trusted or not. This implementation tries to check also that
@@ -58,7 +58,7 @@
 * parallel.
 */
final class ApplicationKeyManager implements X509KeyManager {
    private static final Logger LOG = Logger.getLogger(ApplicationKeyManager.class.getName());
    private static final LocalizedLogger LOG = LocalizedLogger.getLoggerForThisClass();
    /**
     * The default keyManager.
@@ -125,19 +125,19 @@
            } catch (final NoSuchAlgorithmException e) {
                // Nothing to do. Maybe we should avoid this and be strict, but
                // we are in a best effort mode.
                LOG.log(Level.WARNING, "Error with the algorithm", e);
                LOG.warn(LocalizableMessage.raw("Error with the algorithm", e));
            } catch (final KeyStoreException e) {
                // Nothing to do. Maybe we should avoid this and be strict, but
                // we are in a best effort mode..
                LOG.log(Level.WARNING, "Error with the keystore", e);
                LOG.warn(LocalizableMessage.raw("Error with the keystore", e));
            } catch (final UnrecoverableKeyException e) {
                // Nothing to do. Maybe we should avoid this and be strict, but
                // we are in a best effort mode.
                LOG.log(Level.WARNING, "Error with the key", e);
                LOG.warn(LocalizableMessage.raw("Error with the key", e));
            } catch (final NoSuchProviderException e) {
                // Nothing to do. Maybe we should avoid this and be strict, but
                // we are in a best effort mode.
                LOG.log(Level.WARNING, "Error with the provider", e);
                LOG.warn(LocalizableMessage.raw("Error with the provider", e));
            }
        }
    }
opendj-cli/src/main/java/com/forgerock/opendj/cli/ConsoleApplication.java
@@ -206,9 +206,8 @@
     * documentation to be scrolled out of view).
     */
    public final void pressReturnToContinue() {
        final LocalizableMessage msg = INFO_MENU_PROMPT_RETURN_TO_CONTINUE.get();
        try {
            readLineOfInput(msg);
            readLineOfInput(INFO_MENU_PROMPT_RETURN_TO_CONTINUE.get());
        } catch (final ClientException e) {
            // Ignore the exception - applications don't care.
        }
@@ -787,10 +786,9 @@
                    app.println();
                    app.println(errMsg);
                    app.println();
                }
                return null;
            }
            }
        };
        return readValidatedInput(prompt, validator, CONFIRMATION_MAX_TRIES);
opendj-cli/src/main/java/com/forgerock/opendj/cli/PromptingTrustManager.java
@@ -39,8 +39,6 @@
import java.security.cert.X509Certificate;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
@@ -48,6 +46,7 @@
import org.forgerock.i18n.LocalizableMessage;
import org.forgerock.i18n.LocalizableMessageBuilder;
import org.forgerock.i18n.slf4j.LocalizedLogger;
import org.forgerock.util.Reject;
/**
@@ -100,7 +99,7 @@
        }
    }
    private static final Logger LOG = Logger.getLogger(PromptingTrustManager.class.getName());
    private static final LocalizedLogger LOG = LocalizedLogger.getLoggerForThisClass();
    private static final String DEFAULT_PATH = System.getProperty("user.home") + File.separator
            + ".opendj" + File.separator + "keystore";
@@ -273,9 +272,9 @@
     */
    private void acceptCertificate(final X509Certificate[] chain, final boolean permanent) {
        if (permanent) {
            LOG.log(Level.INFO, "Permanently accepting certificate chain to " + "truststore");
            LOG.debug(LocalizableMessage.raw("Permanently accepting certificate chain to " + "truststore"));
        } else {
            LOG.log(Level.INFO, "Accepting certificate chain for this session");
            LOG.debug(LocalizableMessage.raw("Accepting certificate chain for this session"));
        }
        for (final X509Certificate aChain : chain) {
@@ -286,8 +285,8 @@
                    onDiskTrustStore.setCertificateEntry(alias, aChain);
                }
            } catch (final Exception e) {
                LOG.log(Level.WARNING, "Error setting certificate to store: " + e + "\nCert: "
                        + aChain.toString());
                LOG.warn(LocalizableMessage.raw("Error setting certificate to store: " + e + "\nCert: "
                        + aChain.toString()));
            }
        }
@@ -301,7 +300,7 @@
                onDiskTrustStore.store(fos, DEFAULT_PASSWORD);
                fos.close();
            } catch (final Exception e) {
                LOG.log(Level.WARNING, "Error saving store to disk: " + e);
                LOG.warn(LocalizableMessage.raw("Error saving store to disk: " + e));
            }
        }
    }
opendj-cli/src/main/java/com/forgerock/opendj/cli/TabSeparatedTablePrinter.java
@@ -44,10 +44,6 @@
     * Table serializer implementation.
     */
    private final class Serializer extends TableSerializer {
        /** The current column being output. */
        private int column = 0;
        /**
         * Counts the number of separators that should be output the next time a non-empty cell is displayed. The tab
         * separators are not displayed immediately so that we can avoid displaying unnecessary trailing separators.
@@ -74,7 +70,6 @@
            // Replace all new-lines and tabs with a single space.
            writer.print(s.replaceAll("[\\t\\n\\r]", " "));
            column++;
        }
        /** {@inheritDoc} */
@@ -108,14 +103,12 @@
        /** {@inheritDoc} */
        @Override
        public void startHeader() {
            column = 0;
            requiredSeparators = 0;
        }
        /** {@inheritDoc} */
        @Override
        public void startRow() {
            column = 0;
            requiredSeparators = 0;
        }
    }
opendj-cli/src/main/java/com/forgerock/opendj/cli/TextTablePrinter.java
@@ -48,9 +48,6 @@
     */
    private final class Serializer extends TableSerializer {
        // The current column being output.
        private int column = 0;
        /*The real column widths taking into account size constraints but
         not including padding or separators.*/
        private final List<Integer> columnWidths = new ArrayList<Integer>();
@@ -78,7 +75,6 @@
        @Override
        public void addCell(String s) {
            currentRow.add(s);
            column++;
        }
        /** {@inheritDoc} */
@@ -222,15 +218,12 @@
        @Override
        public void startHeader() {
            determineColumnWidths();
            column = 0;
            currentRow.clear();
        }
        /** {@inheritDoc} */
        @Override
        public void startRow() {
            column = 0;
            currentRow.clear();
        }
opendj-cli/src/test/java/com/forgerock/opendj/cli/UtilsTestCase.java
@@ -31,6 +31,7 @@
import org.testng.annotations.Test;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.assertEquals;
@SuppressWarnings("javadoc")
public class UtilsTestCase extends CliTestCase {
@@ -67,4 +68,27 @@
        assertTrue(f.exists());
        assertFalse(Utils.canWrite(f.getPath()));
    }
    @Test()
    public void testGetHostNameForLdapUrl() {
        assertEquals(Utils.getHostNameForLdapUrl("2a01:e35:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx"),
                "[2a01:e35:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]");
        assertEquals(Utils.getHostNameForLdapUrl("basicUrl"), "basicUrl");
        assertEquals(Utils.getHostNameForLdapUrl(null), null);
        // Left/right brackets.
        assertEquals(Utils.getHostNameForLdapUrl("[2a01:e35:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx"),
                "[2a01:e35:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]");
        assertEquals(Utils.getHostNameForLdapUrl("2a01:e35:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]"),
                "[2a01:e35:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]");
    }
    @Test()
    public void isDN() {
        assertTrue(Utils.isDN("cn=Jensen,ou=people,dc=example,dc=com"));
        assertTrue(Utils.isDN("cn=John Doe,dc=example,dc=org"));
        assertFalse(Utils.isDN(null));
        assertFalse(Utils.isDN("babs@example.com"));
    }
}