use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class ControlBasedOperationInterceptor method processDeleteRequest.
/**
* {@inheritDoc}
*/
@Override()
public void processDeleteRequest(final InMemoryInterceptedDeleteRequest 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();
final DeleteRequest deleteRequest = 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)) {
deleteRequest.setDN("ou=altered,dc=example,dc=com");
}
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(deleteRequest);
}
use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class ControlBasedOperationInterceptor method processModifyDNRequest.
/**
* {@inheritDoc}
*/
@Override()
public void processModifyDNRequest(final InMemoryInterceptedModifyDNRequest 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();
final ModifyDNRequest modifyDNRequest = 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)) {
modifyDNRequest.setDN("ou=altered,dc=example,dc=com");
}
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(modifyDNRequest);
}
use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class ControlBasedOperationInterceptor method processSearchRequest.
/**
* {@inheritDoc}
*/
@Override()
public void processSearchRequest(final InMemoryInterceptedSearchRequest 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();
final SearchRequest searchRequest = 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)) {
searchRequest.setBaseDN("ou=altered,dc=example,dc=com");
}
if (transformTypes.contains(TransformType.INJECT_ENTRY)) {
try {
request.sendSearchEntry(new Entry("dn: ou=Request,ou=injected,dc=example,dc=com", "objectClass: top", "objectClass: organizationalUnit", "ou: Request"));
} catch (final Exception e) {
}
}
if (transformTypes.contains(TransformType.INJECT_REFERENCE)) {
try {
final String[] referralURLs = { "ldap://" + request.getConnectedAddress() + ':' + request.getConnectedPort() + "/ou=Request,ou=injected,dc=example,dc=com" };
request.sendSearchReference(new SearchResultReference(referralURLs, null));
} catch (final Exception e) {
}
}
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(searchRequest);
}
use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class ControlBasedOperationInterceptor method processCompareRequest.
/**
* {@inheritDoc}
*/
@Override()
public void processCompareRequest(final InMemoryInterceptedCompareRequest 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();
final CompareRequest compareRequest = 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)) {
compareRequest.setDN("ou=altered,dc=example,dc=com");
}
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(compareRequest);
}
use of com.unboundid.ldap.sdk.IntermediateResponse in project ldapsdk by pingidentity.
the class ControlBasedOperationInterceptor method processModifyRequest.
/**
* {@inheritDoc}
*/
@Override()
public void processModifyRequest(final InMemoryInterceptedModifyRequest 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();
final ModifyRequest modifyRequest = 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)) {
modifyRequest.setDN("ou=altered,dc=example,dc=com");
}
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(modifyRequest);
}
Aggregations