use of com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest in project ldapsdk by pingidentity.
the class LDAPThreadLocalConnectionPoolTestCase method assertBoundAs.
/**
* Ensures that the provided connection is bound as the user with the
* specified DN.
*
* @param conn The connection to examine.
* @param dn The expected DN of the authenticated user.
*
* @throws Exception If an unexpected problem occurs.
*/
private void assertBoundAs(final LDAPConnection conn, final String dn) throws Exception {
final WhoAmIExtendedResult whoAmIResult = (WhoAmIExtendedResult) conn.processExtendedOperation(new WhoAmIExtendedRequest());
assertResultCodeEquals(whoAmIResult, ResultCode.SUCCESS);
final String authzID = whoAmIResult.getAuthorizationID();
assertNotNull(authzID);
assertTrue(authzID.startsWith("dn:"));
assertDNsEqual(authzID.substring(3), dn);
}
use of com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest in project ldapsdk by pingidentity.
the class OperationTypeTestCase method testRequestGetOperationType.
/**
* Provides test coverage for the {@code Request.getOperationType} method.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testRequestGetOperationType() throws Exception {
final AddRequest addRequest = new AddRequest("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example");
assertEquals(addRequest.getOperationType(), OperationType.ADD);
final SimpleBindRequest simpleBindRequest = new SimpleBindRequest("cn=Directory Manager", "password");
assertEquals(simpleBindRequest.getOperationType(), OperationType.BIND);
final PLAINBindRequest plainBindRequest = new PLAINBindRequest("u:test.user", "password");
assertEquals(plainBindRequest.getOperationType(), OperationType.BIND);
final CompareRequest compareRequest = new CompareRequest("dc=example,dc=com", "foo", "bar");
assertEquals(compareRequest.getOperationType(), OperationType.COMPARE);
final DeleteRequest deleteRequest = new DeleteRequest("dc=example,dc=com");
assertEquals(deleteRequest.getOperationType(), OperationType.DELETE);
final CancelExtendedRequest cancelRequest = new CancelExtendedRequest(1);
assertEquals(cancelRequest.getOperationType(), OperationType.EXTENDED);
final WhoAmIExtendedRequest whoAmIRequest = new WhoAmIExtendedRequest();
assertEquals(whoAmIRequest.getOperationType(), OperationType.EXTENDED);
final ModifyRequest modifyRequest = new ModifyRequest("dn: dc=example,dc=com", "changetype: modify", "replace: description", "description: foo");
assertEquals(modifyRequest.getOperationType(), OperationType.MODIFY);
final ModifyDNRequest modifyDNRequest = new ModifyDNRequest("ou=People,dc=example,dc=com", "ou=Users", true);
assertEquals(modifyDNRequest.getOperationType(), OperationType.MODIFY_DN);
final SearchRequest searchRequest = new SearchRequest("dc=example,dc=com", SearchScope.BASE, "(objectClass=*)");
assertEquals(searchRequest.getOperationType(), OperationType.SEARCH);
}
use of com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest in project ldapsdk by pingidentity.
the class RetainIdentityRequestControlTestCase method testSendAnoonymousSimpleRequest.
/**
* Sends a request to the server containing the retain identity request
* control. It will establish an authenticated connection, then send an
* anonymous simple bind including the retain identity request control It
* will verify that the identity of the client connection has not changed.
* <BR><BR>
* Access to a Directory Server instance is required for complete processing.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSendAnoonymousSimpleRequest() throws Exception {
if (!isDirectoryInstanceAvailable()) {
return;
}
LDAPConnection conn = getAdminConnection();
// First, use the "Who Am I?" request to get the current authorization
// identity.
WhoAmIExtendedResult whoAmIResult = (WhoAmIExtendedResult) conn.processExtendedOperation(new WhoAmIExtendedRequest());
String authzID = whoAmIResult.getAuthorizationID();
assertNotNull(authzID);
// Perform an anonymous simple bind that includes both the retain identity
// request control and the authorization identity request control.
Control[] controls = { new RetainIdentityRequestControl(), new AuthorizationIdentityRequestControl() };
SimpleBindRequest bindRequest = new SimpleBindRequest("", "", controls);
BindResult bindResult = conn.bind(bindRequest);
assertEquals(bindResult.getResultCode(), ResultCode.SUCCESS);
boolean authzIDFound = false;
for (Control c : bindResult.getResponseControls()) {
if (c instanceof AuthorizationIdentityResponseControl) {
authzIDFound = true;
String bindAuthzID = ((AuthorizationIdentityResponseControl) c).getAuthorizationID();
assertNotNull(bindAuthzID);
assertTrue(bindAuthzID.equals("") || bindAuthzID.equals("dn:"));
assertFalse(bindAuthzID.equals(authzID));
break;
}
}
assertTrue(authzIDFound);
// Use the "Who Am I?" request again to verify that the client identity
// hasn't really changed.
whoAmIResult = (WhoAmIExtendedResult) conn.processExtendedOperation(new WhoAmIExtendedRequest());
assertNotNull(whoAmIResult.getAuthorizationID());
assertEquals(whoAmIResult.getAuthorizationID(), authzID);
conn.close();
}
use of com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest in project ldapsdk by pingidentity.
the class RetainIdentityRequestControlTestCase method testSendAuthenticatedSimpleRequest.
/**
* Sends a request to the server containing the retain identity request
* control. It will establish an unauthenticated connection, then send an
* authenticated simple bind including the retain identity request control It
* will verify that the identity of the client connection has not changed.
* <BR><BR>
* Access to a Directory Server instance is required for complete processing.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testSendAuthenticatedSimpleRequest() throws Exception {
if (!isDirectoryInstanceAvailable()) {
return;
}
LDAPConnection conn = getAdminConnection();
conn.add(getTestBaseDN(), getBaseEntryAttributes());
conn.add("dn: uid=test," + getTestBaseDN(), "objectClass: top", "objectClass: person", "objectClass: organizationalPerson", "objectClass: inetOrgPerson", "givenName: Test", "sn: User", "cn: Test User", "uid: test", "userPassword: password");
// First, use the "Who Am I?" request to get the current authorization
// identity.
WhoAmIExtendedResult whoAmIResult = (WhoAmIExtendedResult) conn.processExtendedOperation(new WhoAmIExtendedRequest());
String authzID = whoAmIResult.getAuthorizationID();
assertNotNull(authzID);
// Perform an authenticated simple bind that includes both the retain
// identity request control and the authorization identity request control.
Control[] controls = { new RetainIdentityRequestControl(), new AuthorizationIdentityRequestControl() };
SimpleBindRequest bindRequest = new SimpleBindRequest("uid=test," + getTestBaseDN(), "password", controls);
BindResult bindResult = conn.bind(bindRequest);
assertEquals(bindResult.getResultCode(), ResultCode.SUCCESS);
boolean authzIDFound = false;
for (Control c : bindResult.getResponseControls()) {
if (c instanceof AuthorizationIdentityResponseControl) {
authzIDFound = true;
String bindAuthzID = ((AuthorizationIdentityResponseControl) c).getAuthorizationID();
assertNotNull(bindAuthzID);
assertFalse(bindAuthzID.equals(authzID));
break;
}
}
assertTrue(authzIDFound);
// Use the "Who Am I?" request again to verify that the client identity
// hasn't really changed.
whoAmIResult = (WhoAmIExtendedResult) conn.processExtendedOperation(new WhoAmIExtendedRequest());
assertNotNull(whoAmIResult.getAuthorizationID());
assertEquals(whoAmIResult.getAuthorizationID(), authzID);
conn.delete("uid=test," + getTestBaseDN());
conn.delete(getTestBaseDN());
conn.close();
}
use of com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest in project ldapsdk by pingidentity.
the class LDAPConnectionPoolTestCase method testProcessExtendedOperation.
/**
* Tests the methods used to process extended operations.
* <BR><BR>
* Access to a Directory Server instance is required for complete processing.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testProcessExtendedOperation() throws Exception {
if (!isDirectoryInstanceAvailable()) {
return;
}
pool.processExtendedOperation(WhoAmIExtendedRequest.WHO_AM_I_REQUEST_OID);
pool.processExtendedOperation(WhoAmIExtendedRequest.WHO_AM_I_REQUEST_OID, null);
pool.processExtendedOperation(new WhoAmIExtendedRequest());
}
Aggregations