use of org.apache.directory.api.ldap.model.message.CompareResponse in project directory-ldap-api by apache.
the class CompareResponseTest method testResponseWith2Controls.
/**
* Test parsing of a response with 2 (optional) Control elements
*/
@Test
public void testResponseWith2Controls() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(CompareResponseTest.class.getResource("response_with_2_controls.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
CompareResponse compareResponse = (CompareResponse) parser.getBatchResponse().getCurrentResponse();
Map<String, Control> controls = compareResponse.getControls();
assertEquals(2, compareResponse.getControls().size());
Control control = controls.get("1.2.840.113556.1.4.789");
assertNotNull(control);
assertFalse(control.isCritical());
assertEquals("1.2.840.113556.1.4.789", control.getOid());
assertEquals("Some other text", Strings.utf8ToString(((DsmlControl<?>) control).getValue()));
}
use of org.apache.directory.api.ldap.model.message.CompareResponse in project directory-ldap-api by apache.
the class CompareResponseTest method testResponseWith1EmptyReferral.
/**
* Test parsing of a response with an empty Referral
*/
@Test
public void testResponseWith1EmptyReferral() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(CompareResponseTest.class.getResource("response_with_1_empty_referral.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
CompareResponse compareResponse = (CompareResponse) parser.getBatchResponse().getCurrentResponse();
LdapResult ldapResult = compareResponse.getLdapResult();
Collection<String> referrals = ldapResult.getReferral().getLdapUrls();
assertEquals(0, referrals.size());
}
use of org.apache.directory.api.ldap.model.message.CompareResponse in project directory-ldap-api by apache.
the class CompareResponseTest method testResponseWith1Control.
/**
* Test parsing of a response with a (optional) Control element
*/
@Test
public void testResponseWith1Control() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(CompareResponseTest.class.getResource("response_with_1_control.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
CompareResponse compareResponse = (CompareResponse) parser.getBatchResponse().getCurrentResponse();
Map<String, Control> controls = compareResponse.getControls();
assertEquals(1, compareResponse.getControls().size());
Control control = controls.get("1.2.840.113556.1.4.643");
assertNotNull(control);
assertTrue(control.isCritical());
assertEquals("1.2.840.113556.1.4.643", control.getOid());
assertEquals("Some text", Strings.utf8ToString(((DsmlControl<?>) control).getValue()));
}
use of org.apache.directory.api.ldap.model.message.CompareResponse in project directory-ldap-api by apache.
the class CompareResponseTest method testResponseWithErrorMessage.
/**
* Test parsing of a response with Error Message
*/
@Test
public void testResponseWithErrorMessage() {
Dsmlv2ResponseParser parser = null;
try {
parser = new Dsmlv2ResponseParser(getCodec());
parser.setInput(CompareResponseTest.class.getResource("response_with_error_message.xml").openStream(), "UTF-8");
parser.parse();
} catch (Exception e) {
fail(e.getMessage());
}
CompareResponse compareResponse = (CompareResponse) parser.getBatchResponse().getCurrentResponse();
LdapResult ldapResult = compareResponse.getLdapResult();
assertEquals("Unrecognized extended operation EXTENSION_OID: 1.2.6.1.4.1.18060.1.1.1.100.2", ldapResult.getDiagnosticMessage());
}
use of org.apache.directory.api.ldap.model.message.CompareResponse in project directory-fortress-core by apache.
the class LdapDataProvider method compareNode.
/**
* This method uses the compare ldap func to assert audit record into the directory server's configured audit
* logger.
*
* This is for one reason - to force the ldap server to maintain an audit trail on checkAccess api.
*
* Use proxy authz control (RFC4370) to assert the caller's id onto the record.
*
* @param connection is LdapConnection object used for all communication with host.
* @param dn contains address of distinguished name to begin ldap search
* @param userDn dn for user node
* @param attribute attribute used for compare
* @return true if compare operation succeeds
* @throws LdapException thrown in the event of error in ldap client or server code.
* @throws UnsupportedEncodingException in the event the server cannot perform the operation.
*/
protected boolean compareNode(LdapConnection connection, String dn, String userDn, Attribute attribute) throws LdapException, UnsupportedEncodingException {
COUNTERS.incrementCompare();
CompareRequest compareRequest = new CompareRequestImpl();
compareRequest.setName(new Dn(dn));
compareRequest.setAttributeId(attribute.getId());
compareRequest.setAssertionValue(attribute.getString());
// Assert the end user's dn onto the reqest using proxy authZ control so openldap can log who the user was (for authZ audit trail)
ProxiedAuthz proxiedAuthzControl = new ProxiedAuthzImpl();
proxiedAuthzControl.setAuthzId("dn: " + userDn);
compareRequest.addControl(proxiedAuthzControl);
CompareResponse response = connection.compare(compareRequest);
return response.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS;
}
Aggregations