Search in sources :

Example 96 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class AbstractConnectionPool method getSchema.

/**
 * Retrieves the directory server schema definitions that govern the specified
 * entry using a connection from this connection pool.  The subschemaSubentry
 * attribute will be retrieved from the target entry, and then the appropriate
 * schema definitions will be loaded from the entry referenced by that
 * attribute.  This may be necessary to ensure correct behavior in servers
 * that support multiple schemas.
 *
 * @param  entryDN  The DN of the entry for which to retrieve the associated
 *                  schema definitions.  It may be {@code null} or an empty
 *                  string if the subschemaSubentry attribute should be
 *                  retrieved from the server's root DSE.
 *
 * @return  The directory server schema definitions, or {@code null} if the
 *          schema information could not be retrieved (e.g, the client does
 *          not have permission to read the server schema).
 *
 * @throws  LDAPException  If a problem occurs while attempting to retrieve
 *                         the server schema.
 */
@Override()
@Nullable()
public final Schema getSchema(@Nullable final String entryDN) throws LDAPException {
    final LDAPConnection conn = getConnection();
    try {
        final Schema schema = conn.getSchema(entryDN);
        releaseConnection(conn);
        return schema;
    } catch (final Throwable t) {
        throwLDAPExceptionIfShouldNotRetry(t, OperationType.SEARCH, conn);
        // If we have gotten here, then we should retry the operation with a
        // newly-created connection.
        final LDAPConnection newConn = replaceDefunctConnection(t, conn);
        try {
            final Schema schema = newConn.getSchema(entryDN);
            releaseConnection(newConn);
            return schema;
        } catch (final Throwable t2) {
            throwLDAPException(t2, newConn);
        }
        // This return statement should never be reached.
        return null;
    }
}
Also used : Schema(com.unboundid.ldap.sdk.schema.Schema) Nullable(com.unboundid.util.Nullable)

Example 97 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class InterceptedOperation method getConnectedAddress.

/**
 * {@inheritDoc}
 */
@Override()
@Nullable()
public String getConnectedAddress() {
    if (clientConnection == null) {
        return null;
    }
    final Socket s = clientConnection.getSocket();
    if (s == null) {
        return null;
    }
    final InetAddress localAddress = s.getLocalAddress();
    if (localAddress == null) {
        return null;
    }
    return localAddress.getHostAddress();
}
Also used : InetAddress(java.net.InetAddress) Socket(java.net.Socket) Nullable(com.unboundid.util.Nullable)

Example 98 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class JNDIConverter method convertControl.

/**
 * Converts the provided JNDI control to an LDAP SDK control.
 *
 * @param  c  The control to be converted.
 *
 * @return  The LDAP SDK control that corresponds to the provided JNDI
 *          control.
 *
 * @throws  NamingException  If a problem is encountered during the conversion
 *                           process.
 */
@Nullable
public static Control convertControl(@Nullable final javax.naming.ldap.Control c) throws NamingException {
    if (c == null) {
        return null;
    }
    final ASN1OctetString value;
    final byte[] valueBytes = c.getEncodedValue();
    if ((valueBytes == null) || (valueBytes.length == 0)) {
        value = null;
    } else {
        try {
            value = ASN1OctetString.decodeAsOctetString(valueBytes);
        } catch (final ASN1Exception ae) {
            throw new NamingException(StaticUtils.getExceptionMessage(ae));
        }
    }
    return new Control(c.getID(), c.isCritical(), value);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) BasicControl(javax.naming.ldap.BasicControl) ASN1Exception(com.unboundid.asn1.ASN1Exception) NamingException(javax.naming.NamingException) Nullable(com.unboundid.util.Nullable)

Example 99 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class JNDIConverter method convertSearchEntry.

/**
 * Converts the provided LDAP SDK entry to a JNDI search result.
 *
 * @param  e              The entry to be converted to a JNDI search result.
 * @param  contextBaseDN  The base DN for the JNDI context over which the
 *                        search result was retrieved.  If it is
 *                        non-{@code null} and non-empty, then it will be
 *                        removed from the end of the entry's DN in order to
 *                        obtain the name for the {@code SearchResult} that is
 *                        returned.
 *
 * @return  The JNDI search result that corresponds to the provided LDAP SDK
 *          entry.
 */
@Nullable()
public static SearchResult convertSearchEntry(@Nullable final Entry e, @Nullable final String contextBaseDN) {
    if (e == null) {
        return null;
    }
    String name = e.getDN();
    if ((contextBaseDN != null) && (!contextBaseDN.isEmpty())) {
        try {
            final DN parsedEntryDN = e.getParsedDN();
            final DN parsedBaseDN = new DN(contextBaseDN);
            if (parsedEntryDN.equals(parsedBaseDN)) {
                name = "";
            } else if (parsedEntryDN.isDescendantOf(parsedBaseDN, false)) {
                final RDN[] entryRDNs = parsedEntryDN.getRDNs();
                final RDN[] baseRDNs = parsedBaseDN.getRDNs();
                final RDN[] remainingRDNs = new RDN[entryRDNs.length - baseRDNs.length];
                System.arraycopy(entryRDNs, 0, remainingRDNs, 0, remainingRDNs.length);
                name = new DN(remainingRDNs).toString();
            }
        } catch (final Exception ex) {
            Debug.debugException(ex);
        }
    }
    final Collection<Attribute> attrs = e.getAttributes();
    final Attribute[] attributes = new Attribute[attrs.size()];
    attrs.toArray(attributes);
    return new SearchResult(name, null, convertAttributes(attributes));
}
Also used : Attribute(com.unboundid.ldap.sdk.Attribute) BasicAttribute(javax.naming.directory.BasicAttribute) DN(com.unboundid.ldap.sdk.DN) RDN(com.unboundid.ldap.sdk.RDN) SearchResult(javax.naming.directory.SearchResult) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) NamingException(javax.naming.NamingException) ASN1Exception(com.unboundid.asn1.ASN1Exception) Nullable(com.unboundid.util.Nullable)

Example 100 with Nullable

use of com.unboundid.util.Nullable in project ldapsdk by pingidentity.

the class JNDIExtendedRequest method toSDKExtendedRequest.

/**
 * Retrieves an LDAP SDK extended request that is the equivalent of the
 * provided JNDI extended request.
 *
 * @param  r  The JNDI extended request to convert to an LDAP SDK extended
 *            request.
 *
 * @return  The LDAP SDK extended request converted from the provided JNDI
 *          extended request.
 *
 * @throws  NamingException  If a problem occurs while decoding the provided
 *                           JNDI extended request as an SDK extended request.
 */
@Nullable()
public static ExtendedRequest toSDKExtendedRequest(@Nullable final javax.naming.ldap.ExtendedRequest r) throws NamingException {
    if (r == null) {
        return null;
    }
    final ASN1OctetString value;
    final byte[] valueBytes = r.getEncodedValue();
    if (valueBytes == null) {
        value = null;
    } else {
        try {
            value = ASN1OctetString.decodeAsOctetString(valueBytes);
        } catch (final ASN1Exception ae) {
            throw new NamingException(StaticUtils.getExceptionMessage(ae));
        }
    }
    return new ExtendedRequest(r.getID(), value);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Exception(com.unboundid.asn1.ASN1Exception) ExtendedRequest(com.unboundid.ldap.sdk.ExtendedRequest) NamingException(javax.naming.NamingException) Nullable(com.unboundid.util.Nullable)

Aggregations

Nullable (com.unboundid.util.Nullable)149 ArrayList (java.util.ArrayList)47 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)42 Entry (com.unboundid.ldap.sdk.Entry)30 LDAPException (com.unboundid.ldap.sdk.LDAPException)30 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)21 Attribute (com.unboundid.ldap.sdk.Attribute)21 ASN1Element (com.unboundid.asn1.ASN1Element)20 Filter (com.unboundid.ldap.sdk.Filter)20 SearchResult (com.unboundid.ldap.sdk.SearchResult)18 IOException (java.io.IOException)16 ReadOnlyEntry (com.unboundid.ldap.sdk.ReadOnlyEntry)14 File (java.io.File)14 DN (com.unboundid.ldap.sdk.DN)12 ArgumentException (com.unboundid.util.args.ArgumentException)10 RDN (com.unboundid.ldap.sdk.RDN)9 LDIFException (com.unboundid.ldif.LDIFException)8 ChangeLogEntry (com.unboundid.ldap.sdk.ChangeLogEntry)7 Modification (com.unboundid.ldap.sdk.Modification)7 LDIFModifyChangeRecord (com.unboundid.ldif.LDIFModifyChangeRecord)7