70 lines
4.6 KiB
HTML
70 lines
4.6 KiB
HTML
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><html xmlns="http://www.w3.org/1999/xhtml" lang="en"><head><meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/><link rel="stylesheet" href="../jacoco-resources/report.css" type="text/css"/><link rel="shortcut icon" href="../jacoco-resources/report.gif" type="image/gif"/><title>AuthAuditFields.java</title><link rel="stylesheet" href="../jacoco-resources/prettify.css" type="text/css"/><script type="text/javascript" src="../jacoco-resources/prettify.js"></script></head><body onload="window['PR_TAB_WIDTH']=4;prettyPrint()"><div class="breadcrumb" id="breadcrumb"><span class="info"><a href="../jacoco-sessions.html" class="el_session">Sessions</a></span><a href="../index.html" class="el_report">project-auth-server</a> > <a href="index.source.html" class="el_package">com.project.auth.application.support.audit</a> > <span class="el_source">AuthAuditFields.java</span></div><h1>AuthAuditFields.java</h1><pre class="source lang-java linenums">package com.project.auth.application.support.audit;
|
|
|
|
import com.project.auth.domain.user.model.UserEmail;
|
|
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.security.MessageDigest;
|
|
import java.security.NoSuchAlgorithmException;
|
|
import java.util.HexFormat;
|
|
import java.util.Objects;
|
|
import java.util.UUID;
|
|
|
|
public final class AuthAuditFields {
|
|
|
|
public static final String EVENT_TYPE = "eventType";
|
|
public static final String ACTOR_ID = "actorId";
|
|
public static final String USER_ID_HASH = "userIdHash";
|
|
public static final String EMAIL_MASKED = "emailMasked";
|
|
public static final String PROVIDER = "provider";
|
|
public static final String REASON = "reason";
|
|
public static final String METHOD = "method";
|
|
public static final String REQUEST_PATH = "requestPath";
|
|
public static final String KEY_ID = "keyId";
|
|
public static final String EXPIRES_IN_SECONDS = "expiresInSeconds";
|
|
public static final String SUBJECT = "subject";
|
|
|
|
private static final String HASH_PREFIX = "sha256:";
|
|
private static final int HASH_HEX_LENGTH = 16;
|
|
<span class="nc" id="L28"> private static final HexFormat HEX_FORMAT = HexFormat.of();</span>
|
|
|
|
private AuthAuditFields() {
|
|
}
|
|
|
|
public static String maskedEmail(UserEmail email) {
|
|
<span class="nc" id="L34"> Objects.requireNonNull(email, "email must not be null");</span>
|
|
<span class="nc" id="L35"> return maskEmail(email.value());</span>
|
|
}
|
|
|
|
public static String userIdHash(UUID userId) {
|
|
<span class="nc" id="L39"> Objects.requireNonNull(userId, "userId must not be null");</span>
|
|
<span class="nc" id="L40"> return HASH_PREFIX + sha256Hex(userId.toString()).substring(0, HASH_HEX_LENGTH);</span>
|
|
}
|
|
|
|
private static String maskEmail(String email) {
|
|
<span class="nc" id="L44"> int atIndex = email.indexOf('@');</span>
|
|
<span class="nc bnc" id="L45" title="All 4 branches missed."> if (atIndex <= 0 || atIndex == email.length() - 1) {</span>
|
|
<span class="nc" id="L46"> return "***";</span>
|
|
}
|
|
|
|
<span class="nc" id="L49"> String localPart = email.substring(0, atIndex);</span>
|
|
<span class="nc" id="L50"> String domain = email.substring(atIndex + 1);</span>
|
|
<span class="nc" id="L51"> return localPartPrefix(localPart) + "***@" + domain;</span>
|
|
}
|
|
|
|
private static String localPartPrefix(String localPart) {
|
|
<span class="nc bnc" id="L55" title="All 2 branches missed."> if (localPart.length() == 1) {</span>
|
|
<span class="nc" id="L56"> return localPart;</span>
|
|
}
|
|
<span class="nc" id="L58"> return localPart.substring(0, Math.min(localPart.length(), 2));</span>
|
|
}
|
|
|
|
private static String sha256Hex(String value) {
|
|
try {
|
|
<span class="nc" id="L63"> MessageDigest digest = MessageDigest.getInstance("SHA-256");</span>
|
|
<span class="nc" id="L64"> return HEX_FORMAT.formatHex(digest.digest(value.getBytes(StandardCharsets.UTF_8)));</span>
|
|
<span class="nc" id="L65"> } catch (NoSuchAlgorithmException exception) {</span>
|
|
<span class="nc" id="L66"> throw new IllegalStateException("SHA-256 digest is not available.", exception);</span>
|
|
}
|
|
}
|
|
}
|
|
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.14.202510111229</span></div></body></html> |