Search in sources :

Example 1 with Nullable

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

the class InternalSDKHelper method getPingIdentityServerRoot.

/**
 * Retrieves the path to the instance root directory for the Ping Identity
 * Directory Server (or related Ping Identity server product) with which this
 * instance of the LDAP SDK is associated.
 *
 * @return  The path to the associated Ping Identity server instance root, or
 *          {@code null} if the LDAP SDK is not running with knowledge of an
 *          associated Ping Identity server instance.
 */
@InternalUseOnly()
@Nullable()
public static File getPingIdentityServerRoot() {
    final String propertyValue = StaticUtils.getSystemProperty("com.unboundid.directory.server.ServerRoot");
    if (propertyValue != null) {
        try {
            final File f = new File(propertyValue);
            if (f.exists() && f.isDirectory()) {
                return f;
            }
        } catch (final Exception e) {
            Debug.debugException(e);
        }
    }
    final String environmentVariableValue = StaticUtils.getEnvironmentVariable("INSTANCE_ROOT");
    if (environmentVariableValue != null) {
        try {
            final File f = new File(environmentVariableValue);
            if (f.exists() && f.isDirectory()) {
                return f;
            }
        } catch (final Exception e) {
            Debug.debugException(e);
        }
    }
    return null;
}
Also used : File(java.io.File) InternalUseOnly(com.unboundid.util.InternalUseOnly) Nullable(com.unboundid.util.Nullable)

Example 2 with Nullable

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

the class Entry method getAttribute.

/**
 * Retrieves the attribute with the specified name.
 *
 * @param  attributeName  The name of the attribute to retrieve.  It must not
 *                        be {@code null}.
 * @param  schema         The schema to use to determine whether there may be
 *                        alternate names for the specified attribute.  It may
 *                        be {@code null} if no schema is available.
 *
 * @return  The requested attribute from this entry, or {@code null} if the
 *          specified attribute is not present in this entry.
 */
@Nullable()
public final Attribute getAttribute(@NotNull final String attributeName, @Nullable final Schema schema) {
    Validator.ensureNotNull(attributeName);
    Attribute a = attributes.get(StaticUtils.toLowerCase(attributeName));
    if ((a == null) && (schema != null)) {
        final String baseName;
        final String options;
        final int semicolonPos = attributeName.indexOf(';');
        if (semicolonPos > 0) {
            baseName = attributeName.substring(0, semicolonPos);
            options = StaticUtils.toLowerCase(attributeName.substring(semicolonPos));
        } else {
            baseName = attributeName;
            options = "";
        }
        final AttributeTypeDefinition at = schema.getAttributeType(baseName);
        if (at == null) {
            return null;
        }
        a = attributes.get(StaticUtils.toLowerCase(at.getOID() + options));
        if (a == null) {
            for (final String name : at.getNames()) {
                a = attributes.get(StaticUtils.toLowerCase(name) + options);
                if (a != null) {
                    return a;
                }
            }
        }
        return a;
    } else {
        return a;
    }
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Nullable(com.unboundid.util.Nullable)

Example 3 with Nullable

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

the class LDAPConnection method getSSLSession.

/**
 * {@inheritDoc}
 */
@Override()
@Nullable()
public SSLSession getSSLSession() {
    final LDAPConnectionInternals internals = connectionInternals;
    if (internals == null) {
        return null;
    }
    final Socket socket = internals.getSocket();
    if ((socket != null) && (socket instanceof SSLSocket)) {
        final SSLSocket sslSocket = (SSLSocket) socket;
        return sslSocket.getSession();
    } else {
        return null;
    }
}
Also used : SSLSocket(javax.net.ssl.SSLSocket) Socket(java.net.Socket) SSLSocket(javax.net.ssl.SSLSocket) Nullable(com.unboundid.util.Nullable)

Example 4 with Nullable

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

the class DeleteRequest method processAsync.

/**
 * Sends this delete request to the directory server over the provided
 * connection and returns the message ID for the request.
 *
 * @param  connection      The connection to use to communicate with the
 *                         directory server.
 * @param  resultListener  The async result listener that is to be notified
 *                         when the response is received.  It may be
 *                         {@code null} only if the result is to be processed
 *                         by this class.
 *
 * @return  The async request ID created for the operation, or {@code null} if
 *          the provided {@code resultListener} is {@code null} and the
 *          operation will not actually be processed asynchronously.
 *
 * @throws  LDAPException  If a problem occurs while sending the request.
 */
@Nullable()
AsyncRequestID processAsync(@NotNull final LDAPConnection connection, @Nullable final AsyncResultListener resultListener) throws LDAPException {
    // Create the LDAP message.
    messageID = connection.nextMessageID();
    final LDAPMessage message = new LDAPMessage(messageID, this, getControls());
    // If the provided async result listener is {@code null}, then we'll use
    // this class as the message acceptor.  Otherwise, create an async helper
    // and use it as the message acceptor.
    final AsyncRequestID asyncRequestID;
    final long timeout = getResponseTimeoutMillis(connection);
    if (resultListener == null) {
        asyncRequestID = null;
        connection.registerResponseAcceptor(messageID, this);
    } else {
        final AsyncHelper helper = new AsyncHelper(connection, OperationType.DELETE, messageID, resultListener, getIntermediateResponseListener());
        connection.registerResponseAcceptor(messageID, helper);
        asyncRequestID = helper.getAsyncRequestID();
        if (timeout > 0L) {
            final Timer timer = connection.getTimer();
            final AsyncTimeoutTimerTask timerTask = new AsyncTimeoutTimerTask(helper);
            timer.schedule(timerTask, timeout);
            asyncRequestID.setTimerTask(timerTask);
        }
    }
    // Send the request to the server.
    try {
        Debug.debugLDAPRequest(Level.INFO, this, messageID, connection);
        final LDAPConnectionLogger logger = connection.getConnectionOptions().getConnectionLogger();
        if (logger != null) {
            logger.logDeleteRequest(connection, messageID, this);
        }
        connection.getConnectionStatistics().incrementNumDeleteRequests();
        connection.sendMessage(message, timeout);
        return asyncRequestID;
    } catch (final LDAPException le) {
        Debug.debugException(le);
        connection.deregisterResponseAcceptor(messageID);
        throw le;
    }
}
Also used : Timer(java.util.Timer) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) Nullable(com.unboundid.util.Nullable)

Example 5 with Nullable

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

the class GetSupportedOTPDeliveryMechanismsExtendedResult method encodeValue.

/**
 * Encodes the provided information into an appropriate format for the value
 * of this extended operation.
 *
 * @param  resultCode             The result code from the response.  It must
 *                                not be {@code null}.
 * @param  deliveryMechanismInfo  The set of supported delivery mechanism info
 *                                for the result, if appropriate.  It should
 *                                be {@code null} or empty for non-success
 *                                results.
 *
 * @return  The ASN.1 octet string containing the encoded value.
 */
@Nullable()
private static ASN1OctetString encodeValue(@NotNull final ResultCode resultCode, @Nullable final Collection<SupportedOTPDeliveryMechanismInfo> deliveryMechanismInfo) {
    if (resultCode != ResultCode.SUCCESS) {
        return null;
    }
    if ((deliveryMechanismInfo == null) || deliveryMechanismInfo.isEmpty()) {
        return new ASN1OctetString(new ASN1Sequence().encode());
    }
    final ArrayList<ASN1Element> elements = new ArrayList<>(deliveryMechanismInfo.size());
    for (final SupportedOTPDeliveryMechanismInfo i : deliveryMechanismInfo) {
        final ArrayList<ASN1Element> infoElements = new ArrayList<>(3);
        infoElements.add(new ASN1OctetString(TYPE_DELIVERY_MECHANISM, i.getDeliveryMechanism()));
        if (i.isSupported() != null) {
            infoElements.add(new ASN1Boolean(TYPE_IS_SUPPORTED, i.isSupported()));
        }
        if (i.getRecipientID() != null) {
            infoElements.add(new ASN1OctetString(TYPE_RECIPIENT_ID, i.getRecipientID()));
        }
        elements.add(new ASN1Sequence(infoElements));
    }
    return new ASN1OctetString(new ASN1Sequence(elements).encode());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ASN1Sequence(com.unboundid.asn1.ASN1Sequence) ASN1Element(com.unboundid.asn1.ASN1Element) ArrayList(java.util.ArrayList) ASN1Boolean(com.unboundid.asn1.ASN1Boolean) 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