001/* 002 * CDDL HEADER START 003 * 004 * The contents of this file are subject to the terms of the 005 * Common Development and Distribution License, Version 1.0 only 006 * (the "License"). You may not use this file except in compliance 007 * with the License. 008 * 009 * You can obtain a copy of the license at legal-notices/CDDLv1_0.txt 010 * or http://forgerock.org/license/CDDLv1.0.html. 011 * See the License for the specific language governing permissions 012 * and limitations under the License. 013 * 014 * When distributing Covered Code, include this CDDL HEADER in each 015 * file and include the License file at legal-notices/CDDLv1_0.txt. 016 * If applicable, add the following below this CDDL HEADER, with the 017 * fields enclosed by brackets "[]" replaced with your own identifying 018 * information: 019 * Portions Copyright [yyyy] [name of copyright owner] 020 * 021 * CDDL HEADER END 022 * 023 * 024 * Copyright 2009-2010 Sun Microsystems, Inc. 025 * Portions copyright 2011-2014 ForgeRock AS. 026 */ 027 028package org.forgerock.opendj.ldap.spi; 029 030import org.forgerock.opendj.ldap.Connection; 031import org.forgerock.opendj.ldap.IntermediateResponseHandler; 032import org.forgerock.opendj.ldap.LdapException; 033import org.forgerock.opendj.ldap.ResultCode; 034import org.forgerock.opendj.ldap.requests.BindClient; 035import org.forgerock.opendj.ldap.requests.BindRequest; 036import org.forgerock.opendj.ldap.responses.BindResult; 037import org.forgerock.opendj.ldap.responses.Responses; 038import org.forgerock.util.promise.PromiseImpl; 039 040/** 041 * Bind result promise implementation. 042 */ 043public final class BindResultLdapPromiseImpl extends ResultLdapPromiseImpl<BindRequest, BindResult> { 044 private final BindClient bindClient; 045 046 BindResultLdapPromiseImpl(final int requestID, final BindRequest request, final BindClient bindClient, 047 final IntermediateResponseHandler intermediateResponseHandler, 048 final Connection connection) { 049 super(new PromiseImpl<BindResult, LdapException>() { 050 protected LdapException tryCancel(boolean mayInterruptIfRunning) { 051 /* 052 * No other operations can be performed while a bind is active. 053 * Therefore it is not possible to cancel bind or requests, 054 * since doing so will leave the connection in a state which 055 * prevents other operations from being performed. 056 */ 057 return null; 058 } 059 }, requestID, request, intermediateResponseHandler, connection); 060 this.bindClient = bindClient; 061 } 062 063 @Override 064 public boolean isBindOrStartTLS() { 065 return true; 066 } 067 068 /** 069 * Returns the bind client. 070 * 071 * @return The bind client. 072 */ 073 public BindClient getBindClient() { 074 return bindClient; 075 } 076 077 @Override 078 BindResult newErrorResult(final ResultCode resultCode, final String diagnosticMessage, 079 final Throwable cause) { 080 return Responses.newBindResult(resultCode).setDiagnosticMessage(diagnosticMessage) 081 .setCause(cause); 082 } 083}