Search in sources :

Example 6 with BindResponseProtocolOp

use of com.unboundid.ldap.protocol.BindResponseProtocolOp in project ldapsdk by pingidentity.

the class LDAPDebuggerTestCase method testSuccessfulSimpleBind.

/**
 * Provides test coverage for a successful simple bind operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testSuccessfulSimpleBind() throws Exception {
    TestRequestHandler.setReturnOp(new BindResponseProtocolOp(0, null, null, null, null));
    final SimpleBindRequest r = new SimpleBindRequest("uid=admin,dc=example,dc=com", "password", new Control("1.2.3.4"));
    conn.bind(r);
}
Also used : BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) Control(com.unboundid.ldap.sdk.Control) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) Test(org.testng.annotations.Test)

Example 7 with BindResponseProtocolOp

use of com.unboundid.ldap.protocol.BindResponseProtocolOp in project ldapsdk by pingidentity.

the class InMemoryDirectoryServer method bind.

/**
 * Processes the provided bind request.  Only simple and SASL PLAIN bind
 * requests are supported.  Note that the bind processing will verify that the
 * provided credentials are valid, but it will not alter the server in any
 * way.
 *
 * @param  bindRequest  The bind request to be processed.  It must not be
 *                      {@code null}.
 *
 * @return  The result of processing the bind operation.
 *
 * @throws  LDAPException  If the server rejects the bind request, or if a
 *                         problem occurs while sending the request or reading
 *                         the response.
 */
@NotNull()
public BindResult bind(@NotNull final BindRequest bindRequest) throws LDAPException {
    final ArrayList<Control> requestControlList = new ArrayList<>(bindRequest.getControlList());
    requestControlList.add(new Control(InMemoryRequestHandler.OID_INTERNAL_OPERATION_REQUEST_CONTROL, false));
    final BindRequestProtocolOp bindOp;
    if (bindRequest instanceof SimpleBindRequest) {
        final SimpleBindRequest r = (SimpleBindRequest) bindRequest;
        bindOp = new BindRequestProtocolOp(r.getBindDN(), r.getPassword().getValue());
    } else if (bindRequest instanceof PLAINBindRequest) {
        final PLAINBindRequest r = (PLAINBindRequest) bindRequest;
        // Create the byte array that should comprise the credentials.
        final byte[] authZIDBytes = StaticUtils.getBytes(r.getAuthorizationID());
        final byte[] authNIDBytes = StaticUtils.getBytes(r.getAuthenticationID());
        final byte[] passwordBytes = r.getPasswordBytes();
        final byte[] credBytes = new byte[2 + authZIDBytes.length + authNIDBytes.length + passwordBytes.length];
        System.arraycopy(authZIDBytes, 0, credBytes, 0, authZIDBytes.length);
        int pos = authZIDBytes.length + 1;
        System.arraycopy(authNIDBytes, 0, credBytes, pos, authNIDBytes.length);
        pos += authNIDBytes.length + 1;
        System.arraycopy(passwordBytes, 0, credBytes, pos, passwordBytes.length);
        bindOp = new BindRequestProtocolOp(null, "PLAIN", new ASN1OctetString(credBytes));
    } else {
        throw new LDAPException(ResultCode.AUTH_METHOD_NOT_SUPPORTED, ERR_MEM_DS_UNSUPPORTED_BIND_TYPE.get());
    }
    final LDAPMessage responseMessage = inMemoryHandler.processBindRequest(1, bindOp, requestControlList);
    final BindResponseProtocolOp bindResponse = responseMessage.getBindResponseProtocolOp();
    final BindResult bindResult = new BindResult(new LDAPResult(responseMessage.getMessageID(), ResultCode.valueOf(bindResponse.getResultCode()), bindResponse.getDiagnosticMessage(), bindResponse.getMatchedDN(), bindResponse.getReferralURLs(), responseMessage.getControls()));
    switch(bindResponse.getResultCode()) {
        case ResultCode.SUCCESS_INT_VALUE:
            return bindResult;
        default:
            throw new LDAPException(bindResult);
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) ArrayList(java.util.ArrayList) PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) BindRequestProtocolOp(com.unboundid.ldap.protocol.BindRequestProtocolOp) BindResult(com.unboundid.ldap.sdk.BindResult) NotNull(com.unboundid.util.NotNull)

Example 8 with BindResponseProtocolOp

use of com.unboundid.ldap.protocol.BindResponseProtocolOp in project ldapsdk by pingidentity.

the class AccessLogRequestHandler method processBindRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processBindRequest(final int messageID, @NotNull final BindRequestProtocolOp request, @NotNull final List<Control> controls) {
    final long opID = nextOperationID.getAndIncrement();
    final StringBuilder b = getRequestHeader("BIND", opID, messageID);
    b.append(" version=");
    b.append(request.getVersion());
    b.append(" dn=\"");
    b.append(request.getBindDN());
    b.append("\" authType=\"");
    switch(request.getCredentialsType()) {
        case BindRequestProtocolOp.CRED_TYPE_SIMPLE:
            b.append("SIMPLE");
            break;
        case BindRequestProtocolOp.CRED_TYPE_SASL:
            b.append("SASL ");
            b.append(request.getSASLMechanism());
            break;
    }
    b.append('"');
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    final long startTimeNanos = System.nanoTime();
    final LDAPMessage responseMessage = requestHandler.processBindRequest(messageID, request, controls);
    final long eTimeNanos = System.nanoTime() - startTimeNanos;
    final BindResponseProtocolOp protocolOp = responseMessage.getBindResponseProtocolOp();
    generateResponse(b, "BIND", opID, messageID, protocolOp.getResultCode(), protocolOp.getDiagnosticMessage(), protocolOp.getMatchedDN(), protocolOp.getReferralURLs(), eTimeNanos);
    logHandler.publish(new LogRecord(Level.INFO, b.toString()));
    logHandler.flush();
    return responseMessage;
}
Also used : BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) LogRecord(java.util.logging.LogRecord) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) NotNull(com.unboundid.util.NotNull)

Example 9 with BindResponseProtocolOp

use of com.unboundid.ldap.protocol.BindResponseProtocolOp in project ldapsdk by pingidentity.

the class LDAPDebuggerTestCase method testFailedSASLPLAINBind.

/**
 * Provides test coverage for a failed SASL PLAIN bind operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test(expectedExceptions = { LDAPException.class })
public void testFailedSASLPLAINBind() throws Exception {
    TestRequestHandler.setReturnOp(new BindResponseProtocolOp(32, "dc=example,dc=com", "msg", Arrays.asList("ldap://server1.example.com/dc=example,dc=com", "ldap://server2.example.com/dc=example,dc=com"), new ASN1OctetString("foo")));
    conn.bind(new PLAINBindRequest("u:admin", "wrong", new ManageDsaITRequestControl(), new AuthorizationIdentityRequestControl()));
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) PLAINBindRequest(com.unboundid.ldap.sdk.PLAINBindRequest) AuthorizationIdentityRequestControl(com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl) ManageDsaITRequestControl(com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl) Test(org.testng.annotations.Test)

Example 10 with BindResponseProtocolOp

use of com.unboundid.ldap.protocol.BindResponseProtocolOp in project ldapsdk by pingidentity.

the class CannedResponseRequestHandlerTestCase method testDefaultConstructor.

/**
 * Tests the behavior of the request handler with the default configuration.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testDefaultConstructor() throws Exception {
    final CannedResponseRequestHandler handler = new CannedResponseRequestHandler().newInstance(null);
    LDAPMessage m = handler.processAddRequest(1, new AddRequestProtocolOp("dc=example,dc=com", Arrays.asList(new Attribute("objectClass", "top", "domain"), new Attribute("dc", "example"))), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 1);
    assertTrue(m.getProtocolOp() instanceof AddResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processBindRequest(2, new BindRequestProtocolOp("uid=admin,dc=example,dc=com", "password"), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 2);
    assertTrue(m.getProtocolOp() instanceof BindResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processCompareRequest(3, new CompareRequestProtocolOp("dc=example,dc=com", "objectClass", new ASN1OctetString("top")), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 3);
    assertTrue(m.getProtocolOp() instanceof CompareResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processDeleteRequest(4, new DeleteRequestProtocolOp("dc=example,dc=com"), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 4);
    assertTrue(m.getProtocolOp() instanceof DeleteResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processExtendedRequest(5, new ExtendedRequestProtocolOp("1.2.3.4", null), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 5);
    assertTrue(m.getProtocolOp() instanceof ExtendedResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processModifyRequest(6, new ModifyRequestProtocolOp("dc=example,dc=com", Arrays.asList(new Modification(ModificationType.REPLACE, "description", "foo"))), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 6);
    assertTrue(m.getProtocolOp() instanceof ModifyResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processModifyDNRequest(6, new ModifyDNRequestProtocolOp("ou=People,dc=example,dc=com", "ou=Users", true, null), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 6);
    assertTrue(m.getProtocolOp() instanceof ModifyDNResponseProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
    m = handler.processSearchRequest(7, new SearchRequestProtocolOp("dc=example,dc=com", SearchScope.SUB, DereferencePolicy.NEVER, 0, 0, false, Filter.createEqualityFilter("uid", "test"), Arrays.<String>asList()), Collections.<Control>emptyList());
    assertNotNull(m);
    assertEquals(m.getMessageID(), 7);
    assertTrue(m.getProtocolOp() instanceof SearchResultDoneProtocolOp);
    assertNotNull(m.getControls());
    assertTrue(m.getControls().isEmpty());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Modification(com.unboundid.ldap.sdk.Modification) ExtendedResponseProtocolOp(com.unboundid.ldap.protocol.ExtendedResponseProtocolOp) Attribute(com.unboundid.ldap.sdk.Attribute) SearchRequestProtocolOp(com.unboundid.ldap.protocol.SearchRequestProtocolOp) AddRequestProtocolOp(com.unboundid.ldap.protocol.AddRequestProtocolOp) CompareRequestProtocolOp(com.unboundid.ldap.protocol.CompareRequestProtocolOp) DeleteResponseProtocolOp(com.unboundid.ldap.protocol.DeleteResponseProtocolOp) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) AddResponseProtocolOp(com.unboundid.ldap.protocol.AddResponseProtocolOp) BindRequestProtocolOp(com.unboundid.ldap.protocol.BindRequestProtocolOp) ModifyDNResponseProtocolOp(com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp) ExtendedRequestProtocolOp(com.unboundid.ldap.protocol.ExtendedRequestProtocolOp) DeleteRequestProtocolOp(com.unboundid.ldap.protocol.DeleteRequestProtocolOp) ModifyRequestProtocolOp(com.unboundid.ldap.protocol.ModifyRequestProtocolOp) Control(com.unboundid.ldap.sdk.Control) BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) ModifyDNRequestProtocolOp(com.unboundid.ldap.protocol.ModifyDNRequestProtocolOp) SearchResultDoneProtocolOp(com.unboundid.ldap.protocol.SearchResultDoneProtocolOp) CompareResponseProtocolOp(com.unboundid.ldap.protocol.CompareResponseProtocolOp) ModifyResponseProtocolOp(com.unboundid.ldap.protocol.ModifyResponseProtocolOp) Test(org.testng.annotations.Test)

Aggregations

BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)13 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)10 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)7 NotNull (com.unboundid.util.NotNull)7 Control (com.unboundid.ldap.sdk.Control)6 LDAPException (com.unboundid.ldap.sdk.LDAPException)5 BindRequestProtocolOp (com.unboundid.ldap.protocol.BindRequestProtocolOp)4 Test (org.testng.annotations.Test)4 SearchResultDoneProtocolOp (com.unboundid.ldap.protocol.SearchResultDoneProtocolOp)3 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)3 AuthorizationIdentityRequestControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityRequestControl)3 ManageDsaITRequestControl (com.unboundid.ldap.sdk.controls.ManageDsaITRequestControl)3 LogRecord (java.util.logging.LogRecord)3 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)2 CompareResponseProtocolOp (com.unboundid.ldap.protocol.CompareResponseProtocolOp)2 DeleteResponseProtocolOp (com.unboundid.ldap.protocol.DeleteResponseProtocolOp)2 ExtendedResponseProtocolOp (com.unboundid.ldap.protocol.ExtendedResponseProtocolOp)2 ModifyDNResponseProtocolOp (com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp)2 ModifyResponseProtocolOp (com.unboundid.ldap.protocol.ModifyResponseProtocolOp)2 SearchRequestProtocolOp (com.unboundid.ldap.protocol.SearchRequestProtocolOp)2