| | |
| | | * specific credentials to connect, and ensure that your application has access |
| | | * to use the LDAP controls needed. |
| | | */ |
| | | @SuppressWarnings("resource") |
| | | public final class Controls { |
| | | |
| | | /** |
| | |
| | | /** |
| | | * Demonstrates accessing server information about capabilities and schema. |
| | | */ |
| | | @SuppressWarnings("resource") |
| | | public final class GetInfo { |
| | | // Connection information |
| | | private static String host; |
| | |
| | | * <baseDN> <scope> <filter> [<attibute> <attribute> ...] |
| | | * </pre> |
| | | */ |
| | | @SuppressWarnings("resource") |
| | | public final class Search { |
| | | /** |
| | | * Main method. |
| | |
| | | import static org.forgerock.opendj.ldap.CoreMessages.ERR_HEX_DECODE_INVALID_CHARACTER; |
| | | import static org.forgerock.opendj.ldap.CoreMessages.ERR_HEX_DECODE_INVALID_LENGTH; |
| | | |
| | | import java.io.Closeable; |
| | | import java.io.IOException; |
| | | import java.lang.reflect.InvocationTargetException; |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.CharBuffer; |
| | |
| | | } |
| | | |
| | | /** |
| | | * Closes the provided resources ignoring any errors which occurred. |
| | | * |
| | | * @param resources |
| | | * The resources to be closed, which may be {@code null}. |
| | | */ |
| | | public static void closeSilently(Closeable... resources) { |
| | | for (Closeable r : resources) { |
| | | try { |
| | | if (r != null) { |
| | | r.close(); |
| | | } |
| | | } catch (IOException ignored) { |
| | | // Ignore. |
| | | } |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * Attempts to compress the data in the provided source array into the given |
| | | * destination array. If the compressed data will fit into the destination |
| | | * array, then this method will return the number of bytes of compressed |
| | |
| | | * |
| | | * |
| | | * Copyright 2009 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package org.forgerock.opendj.ldap; |
| | |
| | | switch (matches(v, rule, assertion)) { |
| | | case TRUE: |
| | | return ConditionResult.TRUE; |
| | | case FALSE: |
| | | continue; |
| | | case UNDEFINED: |
| | | r = ConditionResult.UNDEFINED; |
| | | } |
| | |
| | | */ |
| | | public static ChangeRecord valueOfLDIFChangeRecord(final String... ldifLines) { |
| | | // LDIF change record reader is tolerant to missing change types. |
| | | @SuppressWarnings("resource") |
| | | final LDIFChangeRecordReader reader = new LDIFChangeRecordReader(ldifLines); |
| | | try { |
| | | if (!reader.hasNext()) { |
| | |
| | | * If {@code ldifLines} was {@code null}. |
| | | */ |
| | | public static Entry valueOfLDIFEntry(final String... ldifLines) { |
| | | @SuppressWarnings("resource") |
| | | final LDIFEntryReader reader = new LDIFEntryReader(ldifLines); |
| | | try { |
| | | if (!reader.hasNext()) { |
| | |
| | | * |
| | | * |
| | | * Copyright 2010 Sun Microsystems, Inc. |
| | | * Portions copyright 2012 ForgeRock AS. |
| | | */ |
| | | |
| | | package com.forgerock.opendj.ldap; |
| | |
| | | |
| | | // Establish a socket connection to see if the transport factory works. |
| | | final Socket socket = new Socket(); |
| | | socket.connect(socketAddress); |
| | | try { |
| | | socket.connect(socketAddress); |
| | | |
| | | // Successfully connected if there is no exception. |
| | | assertTrue(socket.isConnected()); |
| | | // Don't stop the transport because it is shared with the ldap server. |
| | | // Successfully connected if there is no exception. |
| | | assertTrue(socket.isConnected()); |
| | | // Don't stop the transport because it is shared with the ldap server. |
| | | } finally { |
| | | socket.close(); |
| | | } |
| | | } |
| | | } |
| | |
| | | * Unit test for AbstractAsynchronousConnection. The tests verify that all |
| | | * synchronous operation methods delegate to the equivalent asynchronous method. |
| | | */ |
| | | @SuppressWarnings("javadoc") |
| | | @SuppressWarnings({ "javadoc", "resource" }) |
| | | public class AbstractAsynchronousConnectionTestCase extends SdkTestCase { |
| | | |
| | | private final class MockConnection extends AbstractAsynchronousConnection { |
| | |
| | | /** |
| | | * Test {@code Entry}. |
| | | */ |
| | | @SuppressWarnings("javadoc") |
| | | @SuppressWarnings({ "javadoc", "resource" }) |
| | | public final class EntryTestCase extends SdkTestCase { |
| | | |
| | | private static interface EntryFactory { |
| | |
| | | /** |
| | | * Class for organizing options into logical groups when arguement usage is |
| | | * printed. To use an argument group, create an instance and use |
| | | * {@link ArgumentParser#addArgument(Argument, ArgumentGroup)} |
| | | * {@code ArgumentParser#addArgument(Argument, ArgumentGroup)} |
| | | * when adding arguments for to the parser. |
| | | */ |
| | | final class ArgumentGroup implements Comparable<ArgumentGroup> { |
| | |
| | | import static com.forgerock.opendj.ldap.tools.ToolConstants.*; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.*; |
| | | import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode; |
| | | import static com.forgerock.opendj.util.StaticUtils.closeSilently; |
| | | |
| | | import java.io.FileInputStream; |
| | | import java.io.IOException; |
| | |
| | | return verbose.isPresent(); |
| | | } |
| | | |
| | | @SuppressWarnings("resource") |
| | | private int run(final String[] args) { |
| | | // Create the command-line argument parser for use with this |
| | | // program. |
| | |
| | | |
| | | writer = new LDIFEntryWriter(getOutputStream()); |
| | | final VisitorImpl visitor = new VisitorImpl(); |
| | | ChangeRecordReader reader = null; |
| | | try { |
| | | ChangeRecordReader reader; |
| | | if (filename.isPresent()) { |
| | | try { |
| | | reader = new LDIFChangeRecordReader(new FileInputStream(filename.getValue())); |
| | |
| | | return ResultCode.CLIENT_SIDE_LOCAL_ERROR.intValue(); |
| | | } |
| | | } finally { |
| | | if (connection != null) { |
| | | connection.close(); |
| | | } |
| | | closeSilently(reader, connection); |
| | | } |
| | | |
| | | return ResultCode.SUCCESS.intValue(); |
| | |
| | | import static com.forgerock.opendj.ldap.tools.ToolConstants.*; |
| | | import static com.forgerock.opendj.ldap.tools.ToolsMessages.*; |
| | | import static com.forgerock.opendj.ldap.tools.Utils.filterExitCode; |
| | | import static com.forgerock.opendj.util.StaticUtils.closeSilently; |
| | | |
| | | import java.io.BufferedReader; |
| | | import java.io.FileReader; |
| | |
| | | return verbose.isPresent(); |
| | | } |
| | | |
| | | @SuppressWarnings("resource") |
| | | private int run(final String[] args, final boolean returnMatchingEntries) { |
| | | // Create the command-line argument parser for use with this |
| | | // program. |
| | |
| | | // We don't actually need to open a connection or perform the |
| | | // search, so we're done. We should return 0 to either mean that the |
| | | // processing was successful or that there were no matching entries, |
| | | // based |
| | | // on countEntries.isPresent() (but in either case the return value |
| | | // should |
| | | // be zero). |
| | | // based on countEntries.isPresent() (but in either case the return value |
| | | // should be zero). |
| | | return 0; |
| | | } |
| | | |
| | |
| | | } catch (final ErrorResultException ere) { |
| | | return Utils.printErrorMessage(this, ere); |
| | | } finally { |
| | | connection.close(); |
| | | closeSilently(ldifWriter, connection); |
| | | } |
| | | |
| | | return 0; |