use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class ControlBasedOperationInterceptor method processCompareResult.
/**
* {@inheritDoc}
*/
@Override()
public void processCompareResult(final InMemoryInterceptedCompareResult result) {
// See if there are any transformations that should be applied.
final Object transformTypesObj = result.getProperty(STATE_KEY_TRANSFORM_TYPES);
if (transformTypesObj == null) {
return;
}
@SuppressWarnings("unchecked") final Set<TransformType> transformTypes = (Set<TransformType>) transformTypesObj;
if (transformTypes.contains(TransformType.INJECT_INTERMEDIATE_RESPONSE)) {
try {
result.sendIntermediateResponse(new IntermediateResponse(INTERMEDIATE_RESPONSE_OID, new ASN1OctetString("Injected in Response")));
} catch (final Exception e) {
}
}
if (transformTypes.contains(TransformType.INJECT_UNSOLICITED_NOTIFICATION)) {
try {
result.sendUnsolicitedNotification(new ExtendedResult(0, ResultCode.SUCCESS, "Injected by Result", null, null, UNSOLICITED_NOTIFICATION_OID, null, null));
} catch (final Exception e) {
}
}
if (transformTypes.contains(TransformType.ERROR_RESULT)) {
result.setResult(new LDAPResult(result.getMessageID(), ResultCode.UNWILLING_TO_PERFORM, "Error result by transformation", null, StaticUtils.NO_STRINGS, StaticUtils.NO_CONTROLS));
}
if (transformTypes.contains(TransformType.RESULT_RUNTIME_EXCEPTION)) {
throw new RuntimeException();
}
}
use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class ControlBasedOperationInterceptor method processExtendedResult.
/**
* {@inheritDoc}
*/
@Override()
public void processExtendedResult(final InMemoryInterceptedExtendedResult result) {
// See if there are any transformations that should be applied.
final Object transformTypesObj = result.getProperty(STATE_KEY_TRANSFORM_TYPES);
if (transformTypesObj == null) {
return;
}
@SuppressWarnings("unchecked") final Set<TransformType> transformTypes = (Set<TransformType>) transformTypesObj;
if (transformTypes.contains(TransformType.INJECT_INTERMEDIATE_RESPONSE)) {
try {
result.sendIntermediateResponse(new IntermediateResponse(INTERMEDIATE_RESPONSE_OID, new ASN1OctetString("Injected in Response")));
} catch (final Exception e) {
}
}
if (transformTypes.contains(TransformType.INJECT_UNSOLICITED_NOTIFICATION)) {
try {
result.sendUnsolicitedNotification(new ExtendedResult(0, ResultCode.SUCCESS, "Injected by Result", null, null, UNSOLICITED_NOTIFICATION_OID, null, null));
} catch (final Exception e) {
}
}
if (transformTypes.contains(TransformType.ERROR_RESULT)) {
result.setResult(new ExtendedResult(result.getMessageID(), ResultCode.UNWILLING_TO_PERFORM, "Error result by transformation", null, StaticUtils.NO_STRINGS, null, null, StaticUtils.NO_CONTROLS));
}
if (transformTypes.contains(TransformType.RESULT_RUNTIME_EXCEPTION)) {
throw new RuntimeException();
}
}
use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class ControlBasedOperationInterceptor method processModifyDNResult.
/**
* {@inheritDoc}
*/
@Override()
public void processModifyDNResult(final InMemoryInterceptedModifyDNResult result) {
// See if there are any transformations that should be applied.
final Object transformTypesObj = result.getProperty(STATE_KEY_TRANSFORM_TYPES);
if (transformTypesObj == null) {
return;
}
@SuppressWarnings("unchecked") final Set<TransformType> transformTypes = (Set<TransformType>) transformTypesObj;
if (transformTypes.contains(TransformType.INJECT_INTERMEDIATE_RESPONSE)) {
try {
result.sendIntermediateResponse(new IntermediateResponse(INTERMEDIATE_RESPONSE_OID, new ASN1OctetString("Injected in Response")));
} catch (final Exception e) {
}
}
if (transformTypes.contains(TransformType.INJECT_UNSOLICITED_NOTIFICATION)) {
try {
result.sendUnsolicitedNotification(new ExtendedResult(0, ResultCode.SUCCESS, "Injected by Result", null, null, UNSOLICITED_NOTIFICATION_OID, null, null));
} catch (final Exception e) {
}
}
if (transformTypes.contains(TransformType.ERROR_RESULT)) {
result.setResult(new LDAPResult(result.getMessageID(), ResultCode.UNWILLING_TO_PERFORM, "Error result by transformation", null, StaticUtils.NO_STRINGS, StaticUtils.NO_CONTROLS));
}
if (transformTypes.contains(TransformType.RESULT_RUNTIME_EXCEPTION)) {
throw new RuntimeException();
}
}
use of com.unboundid.ldap.sdk.IntermediateResponse 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.IntermediateResponse in project ldapsdk by pingidentity.
the class ControlBasedOperationInterceptor method processIntermediateResponse.
/**
* {@inheritDoc}
*/
@Override()
public void processIntermediateResponse(final InMemoryInterceptedIntermediateResponse response) {
// See if there are any transformations that should be applied.
final Object transformTypesObj = response.getProperty(STATE_KEY_TRANSFORM_TYPES);
if (transformTypesObj == null) {
return;
}
@SuppressWarnings("unchecked") final Set<TransformType> transformTypes = (Set<TransformType>) transformTypesObj;
if (transformTypes.contains(TransformType.SUPPRESS_INTERMEDIATE_RESPONSE)) {
response.setIntermediateResponse(null);
return;
}
if (transformTypes.contains(TransformType.INTERMEDIATE_RESPONSE_RUNTIME_EXCEPTION)) {
throw new RuntimeException();
}
if (transformTypes.contains(TransformType.ALTER_INTERMEDIATE_RESPONSE)) {
response.setIntermediateResponse(new IntermediateResponse(INTERMEDIATE_RESPONSE_OID, new ASN1OctetString("Altered Value"), response.getIntermediateResponse().getControls()));
}
}
Aggregations