private void populateContextFromTokenId(String tokenId) { try { SSOToken token = SSOTokenManager.getInstance().createSSOToken(tokenId); AuditRequestContext.putProperty(USER_ID, getUserId(token)); AuditRequestContext.putProperty(SESSION.toString(), getContextFromSSOToken(token)); } catch (SSOException e) { debug.warning("No SSO Token found when trying to audit an authentication request."); } }
@Override protected Map<String, String> getContextsForAccessOutcome(Response response) { String tokenId = AuditRequestContext.getProperty(TOKEN_ID); String sessionId = AuditRequestContext.getProperty(SESSION_ID); String authId = AuditRequestContext.getProperty(AUTH_ID); if (isNotEmpty(tokenId)) { populateContextFromTokenId(tokenId); } else if (isNotEmpty(sessionId)) { AuditRequestContext.putProperty(AUTH.toString(), getContextIdFromSessionId(sessionId)); } else if (isNotEmpty(authId)) { populateContextFromAuthId(authId); } return super.getContextsForAccessOutcome(response); }
/** * Get all available {@link AuditConstants.Context} values from the possible list of {@link * AuditConstants.Context} values, from the {@link AuditRequestContext}. * * @return All the available {@link AuditConstants.Context} values. */ public static Map<String, String> getAllAvailableContexts() { Map<String, String> map = new HashMap<>(); for (AuditConstants.Context context : AuditConstants.Context.values()) { String contextKey = context.toString(); String contextValue = AuditRequestContext.getProperty(contextKey); if (StringUtils.isNotEmpty(contextValue)) { map.put(contextKey, contextValue); } } return map; }
@Override protected String getUserIdForAccessOutcome(Response response) { String userId = super.getUserIdForAccessOutcome(response); if (isNotEmpty(userId)) { return userId; } String tokenId = AuditRequestContext.getProperty(TOKEN_ID); if (isNotEmpty(tokenId)) { populateContextFromTokenId(tokenId); } return super.getUserIdForAccessOutcome(response); }
private void populateContextFromAuthId(String authId) { try { String sessionId = authIdHelper.reconstructAuthId(authId).getClaimsSet().getClaim(SESSION_ID, String.class); if (isEmpty(sessionId)) { return; } String contextId = getContextIdFromSessionId(sessionId); if (isNotEmpty(contextId)) { AuditRequestContext.putProperty(AUTH.toString(), contextId); } } catch (RestAuthException e) { debug.warning("No session ID found when trying to audit an authentication request."); } }