use of org.apache.directory.api.ldap.model.message.LdapResult in project directory-ldap-api by apache.
the class StoreResultCode method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
// The current TLV should be a integer
// We get it and store it in MessageId
TLV tlv = container.getCurrentTLV();
BerValue value = tlv.getValue();
ResultCodeEnum resultCode = ResultCodeEnum.SUCCESS;
try {
resultCode = ResultCodeEnum.getResultCode(IntegerDecoder.parse(value, 0, ResultCodeEnum.E_SYNC_REFRESH_REQUIRED.getResultCode()));
} catch (IntegerDecoderException ide) {
LOG.error(I18n.err(I18n.ERR_04018, Strings.dumpBytes(value.getData()), ide.getMessage()));
throw new DecoderException(ide.getMessage(), ide);
}
if (IS_DEBUG) {
LOG.debug("The result code is set to " + resultCode);
}
ResultResponse response = (ResultResponse) container.getMessage();
LdapResult ldapResult = response.getLdapResult();
ldapResult.setResultCode(resultCode);
}
use of org.apache.directory.api.ldap.model.message.LdapResult in project directory-ldap-api by apache.
the class AddReferral method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
TLV tlv = container.getCurrentTLV();
Message response = container.getMessage();
LdapResult ldapResult = ((ResultResponse) response).getLdapResult();
Referral referral = ldapResult.getReferral();
if (tlv.getLength() == 0) {
referral.addLdapUrl("");
} else {
if (ldapResult.getResultCode() == ResultCodeEnum.REFERRAL) {
try {
String url = Strings.utf8ToString(tlv.getValue().getData());
referral.addLdapUrl(new LdapUrl(url).toString());
} catch (LdapURLEncodingException luee) {
String badUrl = Strings.utf8ToString(tlv.getValue().getData());
LOG.error(I18n.err(I18n.ERR_04015, badUrl, luee.getMessage()));
throw new DecoderException(I18n.err(I18n.ERR_04016, luee.getMessage()), luee);
}
} else {
LOG.warn("The Referral error message is not allowed when havind an error code no equals to REFERRAL");
referral.addLdapUrl(LdapUrl.EMPTY_URL.toString());
}
}
if (IS_DEBUG) {
StringBuilder sb = new StringBuilder();
boolean isFirst = true;
for (String url : ldapResult.getReferral().getLdapUrls()) {
if (isFirst) {
isFirst = false;
} else {
sb.append(", ");
}
sb.append(url);
}
LOG.debug("The referral error message is set to " + sb.toString());
}
// We can have an END transition
container.setGrammarEndAllowed(true);
}
use of org.apache.directory.api.ldap.model.message.LdapResult 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.LdapResult in project directory-ldap-api by apache.
the class SearchResultDoneTest method testResponseWithMatchedDNAttribute.
/**
* Test parsing of a response with MatchedDN attribute
*/
@Test
public void testResponseWithMatchedDNAttribute() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(SearchResultDoneTest.class.getResource("response_with_matchedDN_attribute.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchResultDone searchResultDone = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getSearchResultDone();
LdapResult ldapResult = searchResultDone.getLdapResult();
assertTrue(ldapResult.getMatchedDn().equals("cn=Bob Rush,ou=Dev,dc=Example,dc=COM"));
}
use of org.apache.directory.api.ldap.model.message.LdapResult in project directory-ldap-api by apache.
the class SearchResultDoneTest method testResponseWithResultCode.
/**
* Test parsing of a response with Result Code
*/
@Test
public void testResponseWithResultCode() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(SearchResultDoneTest.class.getResource("response_with_result_code.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
SearchResultDone searchResultDone = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getSearchResultDone();
LdapResult ldapResult = searchResultDone.getLdapResult();
assertEquals(ResultCodeEnum.PROTOCOL_ERROR, ldapResult.getResultCode());
}
Aggregations