Search in sources :

Example 26 with WhoAmIExtendedRequest

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);
}
Also used : WhoAmIExtendedResult(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedResult) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest)

Example 27 with WhoAmIExtendedRequest

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);
}
Also used : WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) CancelExtendedRequest(com.unboundid.ldap.sdk.extensions.CancelExtendedRequest) Test(org.testng.annotations.Test)

Example 28 with WhoAmIExtendedRequest

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();
}
Also used : WhoAmIExtendedResult(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedResult) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) Control(com.unboundid.ldap.sdk.Control) AuthorizationIdentityResponseControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) AuthorizationIdentityResponseControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) BindResult(com.unboundid.ldap.sdk.BindResult) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 29 with WhoAmIExtendedRequest

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();
}
Also used : WhoAmIExtendedResult(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedResult) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) Control(com.unboundid.ldap.sdk.Control) AuthorizationIdentityResponseControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) AuthorizationIdentityResponseControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) BindResult(com.unboundid.ldap.sdk.BindResult) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 30 with WhoAmIExtendedRequest

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());
}
Also used : WhoAmIExtendedRequest(com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest) Test(org.testng.annotations.Test)

Aggregations

WhoAmIExtendedRequest (com.unboundid.ldap.sdk.extensions.WhoAmIExtendedRequest)37 Test (org.testng.annotations.Test)31 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)21 WhoAmIExtendedResult (com.unboundid.ldap.sdk.extensions.WhoAmIExtendedResult)15 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)9 Control (com.unboundid.ldap.sdk.Control)8 LDAPException (com.unboundid.ldap.sdk.LDAPException)7 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)7 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)6 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)6 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)4 BindResult (com.unboundid.ldap.sdk.BindResult)4 AddRequest (com.unboundid.ldap.sdk.AddRequest)3 CompareRequest (com.unboundid.ldap.sdk.CompareRequest)3 DeleteRequest (com.unboundid.ldap.sdk.DeleteRequest)3 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)3 LDAPConnectionOptions (com.unboundid.ldap.sdk.LDAPConnectionOptions)3 ModifyDNRequest (com.unboundid.ldap.sdk.ModifyDNRequest)3 ModifyRequest (com.unboundid.ldap.sdk.ModifyRequest)3 PLAINBindRequest (com.unboundid.ldap.sdk.PLAINBindRequest)3