Skip to content

Commit

Permalink
Merge pull request #767 from ShehanDinuka/add-identity-claims-to-audi…
Browse files Browse the repository at this point in the history
…tlog

Add identity claims to audit logs
  • Loading branch information
Inthirakumaaran authored Oct 19, 2023
2 parents 8e2b3a4 + 67e8287 commit b535035
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
* This is an implementation of UserOperationEventListener. This defines
Expand All @@ -63,6 +64,7 @@ public class IdentityMgtEventListener extends AbstractIdentityUserOperationEvent
private static final Log log = LogFactory.getLog(IdentityMgtEventListener.class);
IdentityEventService eventMgtService = IdentityMgtServiceDataHolder.getInstance().getIdentityEventService();
private static String RE_CAPTCHA_USER_DOMAIN = "user-domain-recaptcha";
private static final String USER_IDENTITY_CLAIMS_MAP = "UserIdentityClaimsMap";

/**
* USER_EXIST_THREAD_LOCAL_PROPERTY is used to maintain the state of user existence
Expand Down Expand Up @@ -194,6 +196,12 @@ public boolean doPreAddUser(String userName, Object credential, String[] roleLis
if (log.isDebugEnabled()) {
log.debug("Pre add user is called in IdentityMgtEventListener");
}
IdentityUtil.threadLocalProperties.get().remove(USER_IDENTITY_CLAIMS_MAP);
Map<String, String> identityClaims = claims.entrySet().stream()
.filter(claim -> claim.getKey().contains(UserCoreConstants.ClaimTypeURIs.IDENTITY_CLAIM_URI_PREFIX))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
IdentityUtil.threadLocalProperties.get().put(USER_IDENTITY_CLAIMS_MAP, identityClaims);

String eventName = IdentityEventConstants.Event.PRE_ADD_USER;
HashMap<String, Object> properties = new HashMap<>();
properties.put(IdentityEventConstants.EventProperty.USER_CLAIMS, claims);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public class IdentityStoreEventListener extends AbstractIdentityUserOperationEve
private boolean isHybridDataStoreEnable = false;
private static final String INVALID_OPERATION = "InvalidOperation";
private static final String USER_IDENTITY_CLAIMS = "UserIdentityClaims";
private static final String USER_IDENTITY_CLAIMS_MAP = "UserIdentityClaimsMap";
public static final String STORE_IDENTITY_CLAIMS = "StoreIdentityClaims";

public IdentityStoreEventListener() {
Expand Down Expand Up @@ -193,6 +194,7 @@ public boolean doPostAddUser(String userName,
} finally {
// clear the thread local used to store identity claims
IdentityUtil.threadLocalProperties.get().remove(USER_IDENTITY_CLAIMS);
IdentityUtil.threadLocalProperties.get().remove(USER_IDENTITY_CLAIMS_MAP);
}
}

Expand Down

0 comments on commit b535035

Please sign in to comment.