001/*
002 * The contents of this file are subject to the terms of the Common Development and
003 * Distribution License (the License). You may not use this file except in compliance with the
004 * License.
005 *
006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
007 * specific language governing permission and limitations under the License.
008 *
009 * When distributing Covered Software, include this CDDL Header Notice in each file and include
010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
011 * Header, with the fields enclosed by brackets [] replaced by your own identifying
012 * information: "Portions Copyright [year] [name of copyright owner]".
013 *
014 * Copyright 2016 ForgeRock AS.
015 */
016
017package org.opends.server.protocols.http;
018
019import org.forgerock.opendj.ldap.Connection;
020import org.forgerock.opendj.ldap.LdapException;
021import org.forgerock.services.context.AbstractContext;
022import org.forgerock.services.context.Context;
023import org.opends.server.types.Entry;
024
025/**
026 * Context provided by a Directory Server. It contains a reference to a
027 * {@link InternalConnectionFactory} which can be used to perform direct LDAP
028 * operation on this Directory Server without the network overhead.
029 */
030public final class LDAPContext extends AbstractContext
031{
032  private final InternalConnectionFactory internalConnectionFactory;
033
034  /**
035   * Create a new LDAPContext.
036   *
037   * @param parent
038   *          The parent context.
039   * @param internalConnectionFactory
040   *          Internal connection factory of this LDAP server.
041   */
042  public LDAPContext(final Context parent, InternalConnectionFactory internalConnectionFactory)
043  {
044    super(parent, "LDAP context");
045    this.internalConnectionFactory = internalConnectionFactory;
046  }
047
048  /**
049   * Get the {@link InternalConnectionFactory} attached to this context.
050   *
051   * @return The {@link InternalConnectionFactory} attached to this context.
052   */
053  public InternalConnectionFactory getInternalConnectionFactory()
054  {
055    return internalConnectionFactory;
056  }
057
058  /**
059   * An internal connection factory providing direct connection to this Directory
060   * Server without the network overhead.
061   */
062  public interface InternalConnectionFactory
063  {
064    /**
065     * Get a direct {@link Connection} to this Directory Server.
066     *
067     * @param userEntry
068     *          The returned connection will be authenticated as userEntry.
069     * @return A direct {@link Connection} to this Directory Server.
070     * @throws LdapException
071     *           If a connection cannot be created (i.e: because an administrative limit has been exceeded).
072     */
073    Connection getAuthenticatedConnection(Entry userEntry) throws LdapException;
074  }
075}