Skip to content

Commit

Permalink
util: make sure to not drop context information in InternalCallContex…
Browse files Browse the repository at this point in the history
…tFactory

This is important for audits.

Signed-off-by: Pierre-Alexandre Meyer <pierre@ning.com>
  • Loading branch information
Pierre-Alexandre Meyer committed Oct 6, 2012
1 parent 82ca1c0 commit bd64c88
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 5 deletions.
Expand Up @@ -23,6 +23,7 @@
import javax.annotation.Nullable;
import javax.inject.Inject;

import org.joda.time.DateTime;
import org.skife.jdbi.v2.Handle;
import org.skife.jdbi.v2.IDBI;
import org.skife.jdbi.v2.tweak.HandleCallback;
Expand Down Expand Up @@ -90,7 +91,8 @@ public InternalCallContext createInternalCallContext(final UUID objectId, final
// "tenant of the pointed object (%s) and the context (%s) don't match!", tenantRecordIdFromObject, tenantRecordIdFromContext);

return createInternalCallContext(objectId, objectType, context.getUserName(), context.getCallOrigin(),
context.getUserType(), context.getUserToken());
context.getUserType(), context.getUserToken(), context.getReasonCode(), context.getComment(),
context.getCreatedDate(), context.getUpdatedDate());
}

/**
Expand All @@ -103,8 +105,9 @@ public InternalCallContext createInternalCallContext(final UUID objectId, final
* @return internal call context
*/
public InternalCallContext createInternalCallContext(final UUID accountId, final CallContext context) {
return createInternalCallContext(accountId, context.getUserName(), context.getCallOrigin(),
context.getUserType(), context.getUserToken());
return createInternalCallContext(accountId, ObjectType.ACCOUNT, context.getUserName(), context.getCallOrigin(),
context.getUserType(), context.getUserToken(), context.getReasonCode(), context.getComment(),
context.getCreatedDate(), context.getUpdatedDate());
}

/**
Expand Down Expand Up @@ -135,9 +138,17 @@ public InternalCallContext createInternalCallContext(final UUID accountId, final
*/
public InternalCallContext createInternalCallContext(final UUID objectId, final ObjectType objectType, final String userName,
final CallOrigin callOrigin, final UserType userType, @Nullable final UUID userToken) {
return createInternalCallContext(objectId, objectType, userName, callOrigin, userType, userToken, null, null, clock.getUTCNow(), clock.getUTCNow());
}

public InternalCallContext createInternalCallContext(final UUID objectId, final ObjectType objectType, final String userName,
final CallOrigin callOrigin, final UserType userType, @Nullable final UUID userToken,
@Nullable final String reasonCode, @Nullable final String comment, final DateTime createdDate,
final DateTime updatedDate) {
final Long tenantRecordId = retrieveTenantRecordIdFromObject(objectId, objectType);
final Long accountRecordId = retrieveAccountRecordIdFromObject(objectId, objectType);
return createInternalCallContext(tenantRecordId, accountRecordId, userName, callOrigin, userType, userToken);
return createInternalCallContext(tenantRecordId, accountRecordId, userName, callOrigin, userType, userToken,
reasonCode, comment, createdDate, updatedDate);
}

/**
Expand All @@ -155,10 +166,19 @@ public InternalCallContext createInternalCallContext(final UUID objectId, final
*/
public InternalCallContext createInternalCallContext(@Nullable final Long tenantRecordId, final Long accountRecordId, final String userName,
final CallOrigin callOrigin, final UserType userType, @Nullable final UUID userToken) {
return new InternalCallContext(tenantRecordId, accountRecordId, userToken, userName, callOrigin, userType, null, null,
clock.getUTCNow(), clock.getUTCNow());
}

private InternalCallContext createInternalCallContext(@Nullable final Long tenantRecordId, final Long accountRecordId, final String userName,
final CallOrigin callOrigin, final UserType userType, @Nullable final UUID userToken,
@Nullable final String reasonCode, @Nullable final String comment, final DateTime createdDate,
final DateTime updatedDate) {
//Preconditions.checkNotNull(accountRecordId, "accountRecordId cannot be null");
final Long nonNulTenantRecordId = Objects.firstNonNull(tenantRecordId, INTERNAL_TENANT_RECORD_ID);

return new InternalCallContext(nonNulTenantRecordId, accountRecordId, userToken, userName, callOrigin, userType, null, null, clock.getUTCNow(), clock.getUTCNow());
return new InternalCallContext(nonNulTenantRecordId, accountRecordId, userToken, userName, callOrigin, userType, reasonCode, comment,
createdDate, updatedDate);
}

/**
Expand Down
Expand Up @@ -94,6 +94,10 @@ public Void withHandle(final Handle handle) throws Exception {

private void verifyInternalCallContext(final InternalCallContext context) {
Assert.assertEquals(context.getCallOrigin(), callContext.getCallOrigin());
Assert.assertEquals(context.getComment(), callContext.getComment());
Assert.assertEquals(context.getCreatedDate(), callContext.getCreatedDate());
Assert.assertEquals(context.getReasonCode(), callContext.getReasonCode());
Assert.assertEquals(context.getUpdatedDate(), callContext.getUpdatedDate());
Assert.assertEquals(context.getUserName(), callContext.getUserName());
Assert.assertEquals(context.getUserToken(), callContext.getUserToken());
Assert.assertEquals(context.getUserType(), callContext.getUserType());
Expand Down

0 comments on commit bd64c88

Please sign in to comment.