use of org.apache.directory.api.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.
the class StoreExtendedResponseName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ExtendedResponseDecorator<?>> container) throws DecoderException {
// We can allocate the ExtendedResponse Object
ExtendedResponse extendedResponse;
// Get the Value and store it in the ExtendedResponse
TLV tlv = container.getCurrentTLV();
// OID
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04017);
LOG.error(msg);
throw new DecoderException(msg);
} else {
String responseName = Oid.fromString(Strings.asciiBytesToString(tlv.getValue().getData())).toString();
extendedResponse = LdapApiServiceFactory.getSingleton().newExtendedResponse(responseName, container.getMessageId(), null);
((ExtendedResponseDecorator<?>) extendedResponse).setLdapResult((LdapResultDecorator) (container.getMessage().getLdapResult()));
container.setMessage(LdapApiServiceFactory.getSingleton().decorate(extendedResponse));
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("OID read : {}", extendedResponse.getResponseName());
}
}
use of org.apache.directory.api.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.
the class LdapNetworkConnection method startTls.
/**
* Sends the StartTLS extended request to server and adds a security layer
* upon receiving a response with successful result. Note that we will use
* the default LDAP connection.
*
* @throws LdapException If the StartTLS operation failed
*/
public void startTls() throws LdapException {
try {
if (config.isUseSsl()) {
throw new LdapException("Cannot use TLS when the useSsl flag is set true in the configuration");
}
// try to connect, if we aren't already connected.
connect();
checkSession();
IoFilter sslFilter = ldapSession.getFilterChain().get(SSL_FILTER_KEY);
if (sslFilter != null) {
if (LOG.isDebugEnabled()) {
LOG.debug(I18n.msg(I18n.MSG_03222_LDAP_ALREADY_USING_START_TLS));
}
return;
}
ExtendedResponse resp = extended(new StartTlsRequestImpl());
LdapResult result = resp.getLdapResult();
if (result.getResultCode() == ResultCodeEnum.SUCCESS) {
addSslFilter();
} else {
throw new LdapOperationException(result.getResultCode(), result.getDiagnosticMessage());
}
} catch (LdapException e) {
throw e;
} catch (Exception e) {
throw new LdapException(e);
}
}
use of org.apache.directory.api.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.
the class BatchResponseTest method testResponseWith2ExtendedResponse.
/**
* Test parsing of a Response with the 2 ExtendedResponse
*/
@Test
public void testResponseWith2ExtendedResponse() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(BatchResponseTest.class.getResource("response_with_2_ExtendedResponse.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
BatchResponseDsml batchResponse = parser.getBatchResponse();
assertEquals(2, batchResponse.getResponses().size());
DsmlDecorator<? extends Response> response = batchResponse.getCurrentResponse();
if (response instanceof ExtendedResponse) {
assertTrue(true);
} else {
fail();
}
}
use of org.apache.directory.api.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.
the class ExtendedResponseTest method testResponseWithResultCode.
/**
* Test parsing of a response with Result Code
*/
@Test
public void testResponseWithResultCode() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(ExtendedResponseTest.class.getResource("response_with_result_code.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ExtendedResponse extendedResponse = (ExtendedResponse) parser.getBatchResponse().getCurrentResponse();
LdapResult ldapResult = extendedResponse.getLdapResult();
assertEquals(ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode());
}
use of org.apache.directory.api.ldap.model.message.ExtendedResponse in project directory-ldap-api by apache.
the class ExtendedResponseTest method testResponseWith1Referral.
/**
* Test parsing of a response with a Referral
*/
@Test
public void testResponseWith1Referral() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(ExtendedResponseTest.class.getResource("response_with_1_referral.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
ExtendedResponse extendedResponse = (ExtendedResponse) parser.getBatchResponse().getCurrentResponse();
LdapResult ldapResult = extendedResponse.getLdapResult();
Collection<String> referrals = ldapResult.getReferral().getLdapUrls();
assertEquals(1, referrals.size());
try {
assertTrue(referrals.contains(new LdapUrl("ldap://www.apache.org/").toString()));
} catch (LdapURLEncodingException e) {
fail();
}
}
Aggregations