Search in sources :

Example 1 with GenericSASLBindRequest

use of com.unboundid.ldap.sdk.GenericSASLBindRequest in project ldapsdk by pingidentity.

the class BindRequestProtocolOpTestCase method testBindRequestProtocolOpGenericSASLMechanism.

/**
 * Provides test coverage for the bind request protocol op when using a
 * generic SASL bind request.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBindRequestProtocolOpGenericSASLMechanism() throws Exception {
    BindRequestProtocolOp op = new BindRequestProtocolOp("", "TEST", new ASN1OctetString(BindRequestProtocolOp.CRED_TYPE_SASL, "foo"));
    ASN1Buffer buffer = new ASN1Buffer();
    op.writeTo(buffer);
    byte[] opBytes = buffer.toByteArray();
    ByteArrayInputStream inputStream = new ByteArrayInputStream(opBytes);
    ASN1StreamReader reader = new ASN1StreamReader(inputStream);
    op = new BindRequestProtocolOp(reader);
    op = BindRequestProtocolOp.decodeProtocolOp(op.encodeProtocolOp());
    op = new BindRequestProtocolOp((GenericSASLBindRequest) op.toBindRequest());
    assertEquals(op.getVersion(), 3);
    assertNotNull(op.getBindDN());
    assertEquals(op.getBindDN(), "");
    assertEquals(op.getCredentialsType(), BindRequestProtocolOp.CRED_TYPE_SASL);
    assertNull(op.getSimplePassword());
    assertNotNull(op.getSASLMechanism());
    assertEquals(op.getSASLMechanism(), "TEST");
    assertNotNull(op.getSASLCredentials());
    assertEquals(op.getSASLCredentials().stringValue(), "foo");
    assertEquals(op.getProtocolOpType(), (byte) 0x60);
    assertNotNull(op.toString());
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ByteArrayInputStream(java.io.ByteArrayInputStream) ASN1Buffer(com.unboundid.asn1.ASN1Buffer) GenericSASLBindRequest(com.unboundid.ldap.sdk.GenericSASLBindRequest) ASN1StreamReader(com.unboundid.asn1.ASN1StreamReader) Test(org.testng.annotations.Test)

Example 2 with GenericSASLBindRequest

use of com.unboundid.ldap.sdk.GenericSASLBindRequest in project ldapsdk by pingidentity.

the class ControlBasedOperationInterceptor method processSASLBindRequest.

/**
 * {@inheritDoc}
 */
@Override()
public void processSASLBindRequest(final InMemoryInterceptedSASLBindRequest request) throws LDAPException {
    final ObjectPair<Set<TransformType>, Control[]> transformationData = getTransformTypes(request.getRequest());
    // If there are no transformation types to apply, then return without doing
    // anything.
    final Set<TransformType> transformTypes = transformationData.getFirst();
    if (transformTypes.isEmpty()) {
        return;
    }
    // Store the set of transformation types in the operation state for any
    // necessary result processing.
    request.setProperty(STATE_KEY_TRANSFORM_TYPES, transformTypes);
    // Update the request to remove the transformation controls.
    final Control[] remainingControls = transformationData.getSecond();
    GenericSASLBindRequest bindRequest = request.getRequest().duplicate(remainingControls);
    // Apply any necessary transformations to the request.
    if (transformTypes.contains(TransformType.REJECT_REQUEST)) {
        throw new LDAPException(ResultCode.UNWILLING_TO_PERFORM, "Rejected by transformation control");
    }
    if (transformTypes.contains(TransformType.REQUEST_RUNTIME_EXCEPTION)) {
        throw new RuntimeException();
    }
    if (transformTypes.contains(TransformType.ALTER_DN)) {
        final long responseTimeout = bindRequest.getResponseTimeoutMillis(null);
        bindRequest = new GenericSASLBindRequest("ou=altered,dc=example,dc=com", bindRequest.getSASLMechanismName(), bindRequest.getCredentials(), bindRequest.getControls());
        bindRequest.setResponseTimeoutMillis(responseTimeout);
    }
    if (transformTypes.contains(TransformType.INJECT_INTERMEDIATE_RESPONSE)) {
        try {
            request.sendIntermediateResponse(new IntermediateResponse(INTERMEDIATE_RESPONSE_OID, new ASN1OctetString("Injected in Request")));
        } catch (final Exception e) {
        }
    }
    if (transformTypes.contains(TransformType.INJECT_UNSOLICITED_NOTIFICATION)) {
        try {
            request.sendUnsolicitedNotification(new ExtendedResult(0, ResultCode.SUCCESS, "Injected by Request", null, null, UNSOLICITED_NOTIFICATION_OID, null, null));
        } catch (final Exception e) {
        }
    }
    // Update the add request to be processed.
    request.setRequest(bindRequest);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) EnumSet(java.util.EnumSet) Set(java.util.Set) LDAPException(com.unboundid.ldap.sdk.LDAPException) Control(com.unboundid.ldap.sdk.Control) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) LDAPException(com.unboundid.ldap.sdk.LDAPException) GenericSASLBindRequest(com.unboundid.ldap.sdk.GenericSASLBindRequest) ExtendedResult(com.unboundid.ldap.sdk.ExtendedResult)

Example 3 with GenericSASLBindRequest

use of com.unboundid.ldap.sdk.GenericSASLBindRequest in project ldapsdk by pingidentity.

the class InterceptedSASLBindOperationTestCase method testBasics.

/**
 * Provides basic test coverage for an intercepted SASL bind operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBasics() throws Exception {
    // Create an intercepted SASL bind operation.  We'll use a null connection,
    // which shouldn't happen naturally but will be sufficient for this test.
    final BindRequestProtocolOp requestOp = new BindRequestProtocolOp(new GenericSASLBindRequest(null, "MECH-A", null));
    final InterceptedSASLBindOperation o = new InterceptedSASLBindOperation(null, 1, requestOp);
    assertNotNull(o.toString());
    // Test methods for a generic intercepted operation.
    assertNull(o.getClientConnection());
    assertEquals(o.getConnectionID(), -1L);
    assertNull(o.getConnectedAddress());
    assertEquals(o.getConnectedPort(), -1);
    assertEquals(o.getMessageID(), 1);
    assertNull(o.getProperty("propX"));
    o.setProperty("propX", "valX");
    assertNotNull(o.getProperty("propX"));
    assertEquals(o.getProperty("propX"), "valX");
    assertNotNull(o.toString());
    o.setProperty("propX", null);
    assertNull(o.getProperty("propX"));
    // Test methods specific to an intercepted SASL bind operation.
    assertNotNull(o.getRequest());
    assertEquals(o.getRequest().getSASLMechanismName(), "MECH-A");
    assertNotNull(o.toString());
    final GenericSASLBindRequest r = new GenericSASLBindRequest(null, "MECH-B", null);
    o.setRequest(r);
    assertNotNull(o.getRequest());
    assertEquals(o.getRequest().getSASLMechanismName(), "MECH-B");
    assertNotNull(o.toString());
    assertNull(o.getResult());
    o.setResult(new BindResult(o.getMessageID(), ResultCode.SUCCESS, null, null, null, null));
    assertNotNull(o.getResult());
    assertNotNull(o.toString());
}
Also used : GenericSASLBindRequest(com.unboundid.ldap.sdk.GenericSASLBindRequest) BindRequestProtocolOp(com.unboundid.ldap.protocol.BindRequestProtocolOp) BindResult(com.unboundid.ldap.sdk.BindResult) Test(org.testng.annotations.Test)

Example 4 with GenericSASLBindRequest

use of com.unboundid.ldap.sdk.GenericSASLBindRequest in project ldapsdk by pingidentity.

the class ProxyRequestHandler method processBindRequest.

/**
 * {@inheritDoc}
 */
@Override()
@NotNull()
public LDAPMessage processBindRequest(final int messageID, @NotNull final BindRequestProtocolOp request, @NotNull final List<Control> controls) {
    final Control[] controlArray;
    if ((controls == null) || (controls.isEmpty())) {
        controlArray = StaticUtils.NO_CONTROLS;
    } else {
        controlArray = new Control[controls.size()];
        controls.toArray(controlArray);
    }
    final BindRequest bindRequest;
    if (request.getCredentialsType() == BindRequestProtocolOp.CRED_TYPE_SIMPLE) {
        bindRequest = new SimpleBindRequest(request.getBindDN(), request.getSimplePassword().getValue(), controlArray);
    } else {
        bindRequest = new GenericSASLBindRequest(request.getBindDN(), request.getSASLMechanism(), request.getSASLCredentials(), controlArray);
    }
    bindRequest.setIntermediateResponseListener(this);
    LDAPResult bindResult;
    try {
        bindResult = ldapConnection.bind(bindRequest);
    } catch (final LDAPException le) {
        Debug.debugException(le);
        bindResult = le.toLDAPResult();
    }
    final BindResponseProtocolOp bindResponseProtocolOp = new BindResponseProtocolOp(bindResult.getResultCode().intValue(), bindResult.getMatchedDN(), bindResult.getDiagnosticMessage(), Arrays.asList(bindResult.getReferralURLs()), null);
    return new LDAPMessage(messageID, bindResponseProtocolOp, Arrays.asList(bindResult.getResponseControls()));
}
Also used : Control(com.unboundid.ldap.sdk.Control) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) BindResponseProtocolOp(com.unboundid.ldap.protocol.BindResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) GenericSASLBindRequest(com.unboundid.ldap.sdk.GenericSASLBindRequest) BindRequest(com.unboundid.ldap.sdk.BindRequest) GenericSASLBindRequest(com.unboundid.ldap.sdk.GenericSASLBindRequest) SimpleBindRequest(com.unboundid.ldap.sdk.SimpleBindRequest) LDAPResult(com.unboundid.ldap.sdk.LDAPResult) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) NotNull(com.unboundid.util.NotNull)

Aggregations

GenericSASLBindRequest (com.unboundid.ldap.sdk.GenericSASLBindRequest)4 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)2 Control (com.unboundid.ldap.sdk.Control)2 LDAPException (com.unboundid.ldap.sdk.LDAPException)2 Test (org.testng.annotations.Test)2 ASN1Buffer (com.unboundid.asn1.ASN1Buffer)1 ASN1StreamReader (com.unboundid.asn1.ASN1StreamReader)1 BindRequestProtocolOp (com.unboundid.ldap.protocol.BindRequestProtocolOp)1 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)1 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)1 BindRequest (com.unboundid.ldap.sdk.BindRequest)1 BindResult (com.unboundid.ldap.sdk.BindResult)1 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)1 IntermediateResponse (com.unboundid.ldap.sdk.IntermediateResponse)1 LDAPResult (com.unboundid.ldap.sdk.LDAPResult)1 SimpleBindRequest (com.unboundid.ldap.sdk.SimpleBindRequest)1 NotNull (com.unboundid.util.NotNull)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 EnumSet (java.util.EnumSet)1 Set (java.util.Set)1