| | |
| | | import static org.forgerock.opendj.adapter.server3x.Converters.getResponseResult; |
| | | import static org.forgerock.opendj.ldap.LdapException.newLdapException; |
| | | import static org.opends.messages.ProtocolMessages.WARN_CLIENT_DISCONNECT_IN_PROGRESS; |
| | | import static org.opends.server.loggers.CommonAudit.DEFAULT_TRANSACTION_ID; |
| | | import static org.opends.server.loggers.AccessLogger.logDisconnect; |
| | | |
| | | import java.net.InetAddress; |
| | | import java.net.URI; |
| | | import java.net.UnknownHostException; |
| | | import java.util.ArrayList; |
| | | import java.util.Collection; |
| | | import java.util.Map; |
| | | import java.util.concurrent.ConcurrentHashMap; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | import java.util.concurrent.atomic.AtomicLong; |
| | | |
| | | import org.forgerock.http.MutableUri; |
| | | import org.forgerock.http.header.MalformedHeaderException; |
| | | import org.forgerock.http.header.TransactionIdHeader; |
| | | import org.forgerock.http.protocol.Request; |
| | | import org.forgerock.i18n.LocalizableMessage; |
| | | import org.forgerock.i18n.LocalizableMessageBuilder; |
| | | import org.forgerock.i18n.slf4j.LocalizedLogger; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.forgerock.opendj.ldap.LdapException; |
| | | import org.forgerock.opendj.ldap.ResultCode; |
| | | import org.forgerock.opendj.ldap.SearchResultHandler; |
| | |
| | | import org.opends.server.core.ModifyOperation; |
| | | import org.opends.server.core.SearchOperation; |
| | | import org.opends.server.core.ServerContext; |
| | | import org.opends.server.loggers.HTTPAccessLogger; |
| | | import org.opends.server.loggers.HTTPRequestInfo; |
| | | import org.opends.server.protocols.ldap.AddResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.BindResponseProtocolOp; |
| | | import org.opends.server.protocols.ldap.CompareResponseProtocolOp; |
| | |
| | | import org.opends.server.protocols.ldap.SearchResultReferenceProtocolOp; |
| | | import org.opends.server.types.CancelRequest; |
| | | import org.opends.server.types.CancelResult; |
| | | import org.forgerock.opendj.ldap.DN; |
| | | import org.opends.server.types.DirectoryException; |
| | | import org.opends.server.types.DisconnectReason; |
| | | import org.opends.server.types.IntermediateResponse; |
| | |
| | | * connection that will be accepted by an instance of the HTTP connection |
| | | * handler. |
| | | */ |
| | | final class HTTPClientConnection extends ClientConnection implements HTTPRequestInfo |
| | | final class HTTPClientConnection extends ClientConnection |
| | | { |
| | | |
| | | // TODO JNR Confirm with Matt that persistent searches are inapplicable to Rest2LDAP. |
| | |
| | | private final String method; |
| | | /** The URI issued by the client. */ |
| | | private final MutableUri uri; |
| | | /** The user agent used by the client. */ |
| | | private final String userAgent; |
| | | |
| | | /** The username that was used to authenticate. */ |
| | | private String authUser; |
| | | /** |
| | | * The HTTP status code returned to the client. Using 0 to say no status code |
| | | * was set since it is not . |
| | | */ |
| | | private final AtomicInteger statusCode = new AtomicInteger(0); |
| | | |
| | | /** The client (remote) address. */ |
| | | private final String clientAddress; |
| | |
| | | /** Security-Strength Factor extracted from the request attribute. */ |
| | | private final int securityStrengthFactor; |
| | | |
| | | /** TransactionId for tracking of ForgeRock stack transactions. */ |
| | | private final String transactionId; |
| | | |
| | | /** |
| | | * Constructs an instance of this class. |
| | | * @param serverContext |
| | |
| | | context.asContext(AttributesContext.class).getAttributes().get(SERVLET_SSF_CONSTANT)); |
| | | this.method = request.getMethod(); |
| | | this.protocol = request.getVersion(); |
| | | this.userAgent = clientCtx.getUserAgent(); |
| | | |
| | | this.statTracker = this.connectionHandler.getStatTracker(); |
| | | |
| | |
| | | this.statTracker.updateConnect(); |
| | | this.useNanoTime = DirectoryServer.getUseNanoTime(); |
| | | } |
| | | this.transactionId = getTransactionId(serverContext, request); |
| | | this.connectionID = DirectoryServer.newConnectionAccepted(this); |
| | | } |
| | | |
| | | private String getTransactionId(ServerContext serverContext, Request request) |
| | | { |
| | | if (serverContext.getCommonAudit().shouldTrustTransactionIds()) |
| | | { |
| | | try |
| | | { |
| | | TransactionIdHeader txHeader = request.getHeaders().get(TransactionIdHeader.class); |
| | | return txHeader == null ? DEFAULT_TRANSACTION_ID : txHeader.getTransactionId().getValue(); |
| | | } |
| | | catch (MalformedHeaderException e) |
| | | { |
| | | // ignore it |
| | | } |
| | | } |
| | | return DEFAULT_TRANSACTION_ID; |
| | | } |
| | | |
| | | @Override |
| | | public String getAuthUser() |
| | | { |
| | | return this.authUser; |
| | | context.asContext(HttpLogContext.class).setConnectionID(connectionID); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | |
| | | @Override |
| | | public long getTotalProcessingTime() |
| | | { |
| | | return totalProcessingTime.get(); |
| | | } |
| | | |
| | | @Override |
| | | public String getProtocol() |
| | | { |
| | | return protocol; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String getClientHost() |
| | | { |
| | | return clientAddress; // Avoid reverse lookups. |
| | | } |
| | | |
| | | @Override |
| | | public int getClientPort() |
| | | { |
| | | return clientPort; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String getServerHost() |
| | | { |
| | | return serverAddress; // Avoid reverse lookups. |
| | | } |
| | | |
| | | @Override |
| | | public int getServerPort() |
| | | { |
| | | return serverPort; |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String getTransactionId() |
| | | { |
| | | return transactionId; |
| | | } |
| | | |
| | | @Override |
| | | public boolean isSecure() |
| | | { |
| | | return isSecure; |
| | |
| | | |
| | | if (keepStats) |
| | | { |
| | | this.statTracker.updateRequestMonitoringData(getMethod(), time); |
| | | this.statTracker.updateRequestMonitoringData(method, time); |
| | | this.statTracker.updateOperationMonitoringData(operation.getOperationType(), time); |
| | | } |
| | | |
| | |
| | | throw new RuntimeException("Not implemented"); |
| | | } |
| | | |
| | | @Override |
| | | public void setAuthUser(String authUser) |
| | | { |
| | | this.authUser = authUser; |
| | | } |
| | | |
| | | /** |
| | | * {@inheritDoc} |
| | | * |
| | |
| | | } |
| | | |
| | | @Override |
| | | public String getMethod() |
| | | { |
| | | return this.method; |
| | | } |
| | | |
| | | @Override |
| | | public URI getUri() |
| | | { |
| | | return this.uri.asURI(); |
| | | } |
| | | |
| | | @Override |
| | | public int getStatusCode() |
| | | { |
| | | return this.statusCode.get(); |
| | | } |
| | | |
| | | @Override |
| | | public String getUserAgent() |
| | | { |
| | | return this.userAgent; |
| | | } |
| | | |
| | | @Override |
| | | public Collection<Operation> getOperationsInProgress() |
| | | { |
| | | Collection<OperationWithPromise> values = operationsInProgress.values(); |
| | |
| | | { |
| | | return true; |
| | | } |
| | | |
| | | @Override |
| | | public void log(int statusCode) |
| | | { |
| | | if (this.statusCode.compareAndSet(0, statusCode)) |
| | | { // This request was not logged before |
| | | HTTPAccessLogger.logRequestInfo(this); |
| | | } |
| | | } |
| | | } |