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());
}
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);
}
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());
}
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()));
}
Aggregations