init: 클린 기반 auth 서버 설계
This commit is contained in:
+1
@@ -0,0 +1 @@
|
||||
<?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>JwtTypValidator</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><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">bootstrap</a> > <a href="index.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_class">JwtTypValidator</span></div><h1>JwtTypValidator</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">29 of 38</td><td class="ctr2">23%</td><td class="bar">2 of 2</td><td class="ctr2">0%</td><td class="ctr1">2</td><td class="ctr2">3</td><td class="ctr1">5</td><td class="ctr2">8</td><td class="ctr1">1</td><td class="ctr2">2</td></tr></tfoot><tbody><tr><td id="a1"><a href="JwtTypValidator.java.html#L23" class="el_method">validate(Jwt)</a></td><td class="bar" id="b0"><img src="../jacoco-resources/redbar.gif" width="120" height="10" title="29" alt="29"/></td><td class="ctr2" id="c1">0%</td><td class="bar" id="d0"><img src="../jacoco-resources/redbar.gif" width="120" height="10" title="2" alt="2"/></td><td class="ctr2" id="e0">0%</td><td class="ctr1" id="f0">2</td><td class="ctr2" id="g0">2</td><td class="ctr1" id="h0">5</td><td class="ctr2" id="i0">5</td><td class="ctr1" id="j0">1</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a0"><a href="JwtTypValidator.java.html#L17" class="el_method">JwtTypValidator(String)</a></td><td class="bar" id="b1"><img src="../jacoco-resources/greenbar.gif" width="37" height="10" title="9" alt="9"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">0</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h1">0</td><td class="ctr2" id="i1">3</td><td class="ctr1" id="j1">0</td><td class="ctr2" id="k1">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?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>JwtTypValidator.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">bootstrap</a> > <a href="index.source.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_source">JwtTypValidator.java</span></div><h1>JwtTypValidator.java</h1><pre class="source lang-java linenums">package com.project.auth.config.auth.security;
|
||||
|
||||
import org.springframework.security.oauth2.core.OAuth2Error;
|
||||
import org.springframework.security.oauth2.core.OAuth2TokenValidator;
|
||||
import org.springframework.security.oauth2.core.OAuth2TokenValidatorResult;
|
||||
import org.springframework.security.oauth2.jwt.Jwt;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class JwtTypValidator implements OAuth2TokenValidator<Jwt> {
|
||||
|
||||
private static final String TYP_CLAIM = "typ";
|
||||
private static final String ERROR_CODE = "invalid_token";
|
||||
|
||||
private final String expectedTyp;
|
||||
|
||||
<span class="fc" id="L17"> public JwtTypValidator(String expectedTyp) {</span>
|
||||
<span class="fc" id="L18"> this.expectedTyp = Objects.requireNonNull(expectedTyp, "expectedTyp must not be null");</span>
|
||||
<span class="fc" id="L19"> }</span>
|
||||
|
||||
@Override
|
||||
public OAuth2TokenValidatorResult validate(Jwt jwt) {
|
||||
<span class="nc" id="L23"> String actual = jwt.getClaimAsString(TYP_CLAIM);</span>
|
||||
<span class="nc bnc" id="L24" title="All 2 branches missed."> if (expectedTyp.equals(actual)) {</span>
|
||||
<span class="nc" id="L25"> return OAuth2TokenValidatorResult.success();</span>
|
||||
}
|
||||
<span class="nc" id="L27"> OAuth2Error error = new OAuth2Error(</span>
|
||||
ERROR_CODE,
|
||||
"Expected JWT typ=" + expectedTyp + " but got " + actual,
|
||||
null
|
||||
);
|
||||
<span class="nc" id="L32"> return OAuth2TokenValidatorResult.failure(error);</span>
|
||||
}
|
||||
}
|
||||
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?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>KeycloakAuthenticatedUserFactory</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><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">bootstrap</a> > <a href="index.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_class">KeycloakAuthenticatedUserFactory</span></div><h1>KeycloakAuthenticatedUserFactory</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">4 of 39</td><td class="ctr2">89%</td><td class="bar">2 of 4</td><td class="ctr2">50%</td><td class="ctr1">2</td><td class="ctr2">6</td><td class="ctr1">1</td><td class="ctr2">13</td><td class="ctr1">0</td><td class="ctr2">4</td></tr></tfoot><tbody><tr><td id="a2"><a href="KeycloakAuthenticatedUserFactory.java.html#L27" class="el_method">displayName(Jwt)</a></td><td class="bar" id="b0"><img src="../jacoco-resources/redbar.gif" width="32" height="10" title="4" alt="4"/><img src="../jacoco-resources/greenbar.gif" width="88" height="10" title="11" alt="11"/></td><td class="ctr2" id="c3">73%</td><td class="bar" id="d0"><img src="../jacoco-resources/redbar.gif" width="60" height="10" title="2" alt="2"/><img src="../jacoco-resources/greenbar.gif" width="60" height="10" title="2" alt="2"/></td><td class="ctr2" id="e0">50%</td><td class="ctr1" id="f0">2</td><td class="ctr2" id="g0">3</td><td class="ctr1" id="h0">1</td><td class="ctr2" id="i1">4</td><td class="ctr1" id="j0">0</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a1"><a href="KeycloakAuthenticatedUserFactory.java.html#L18" class="el_method">create(Jwt, Collection)</a></td><td class="bar" id="b1"><img src="../jacoco-resources/greenbar.gif" width="104" height="10" title="13" alt="13"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">0</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h1">0</td><td class="ctr2" id="i0">5</td><td class="ctr1" id="j1">0</td><td class="ctr2" id="k1">1</td></tr><tr><td id="a0"><a href="KeycloakAuthenticatedUserFactory.java.html#L35" class="el_method">authorityNames(Collection)</a></td><td class="bar" id="b2"><img src="../jacoco-resources/greenbar.gif" width="64" height="10" title="8" alt="8"/></td><td class="ctr2" id="c1">100%</td><td class="bar" id="d2"/><td class="ctr2" id="e2">n/a</td><td class="ctr1" id="f2">0</td><td class="ctr2" id="g2">1</td><td class="ctr1" id="h2">0</td><td class="ctr2" id="i2">3</td><td class="ctr1" id="j2">0</td><td class="ctr2" id="k2">1</td></tr><tr><td id="a3"><a href="KeycloakAuthenticatedUserFactory.java.html#L11" class="el_method">KeycloakAuthenticatedUserFactory()</a></td><td class="bar" id="b3"><img src="../jacoco-resources/greenbar.gif" width="24" height="10" title="3" alt="3"/></td><td class="ctr2" id="c2">100%</td><td class="bar" id="d3"/><td class="ctr2" id="e3">n/a</td><td class="ctr1" id="f3">0</td><td class="ctr2" id="g3">1</td><td class="ctr1" id="h3">0</td><td class="ctr2" id="i3">1</td><td class="ctr1" id="j3">0</td><td class="ctr2" id="k3">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
<?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>KeycloakAuthenticatedUserFactory.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">bootstrap</a> > <a href="index.source.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_source">KeycloakAuthenticatedUserFactory.java</span></div><h1>KeycloakAuthenticatedUserFactory.java</h1><pre class="source lang-java linenums">package com.project.auth.config.auth.security;
|
||||
|
||||
import com.project.auth.presentation.auth.current.AuthenticatedUser;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.oauth2.jwt.Jwt;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
<span class="fc" id="L11">public class KeycloakAuthenticatedUserFactory {</span>
|
||||
|
||||
private static final String CLAIM_EMAIL = "email";
|
||||
private static final String CLAIM_NAME = "name";
|
||||
private static final String CLAIM_PREFERRED_USERNAME = "preferred_username";
|
||||
|
||||
public AuthenticatedUser create(Jwt jwt, Collection<? extends GrantedAuthority> authorities) {
|
||||
<span class="fc" id="L18"> return new AuthenticatedUser(</span>
|
||||
<span class="fc" id="L19"> jwt.getSubject(),</span>
|
||||
<span class="fc" id="L20"> jwt.getClaimAsString(CLAIM_EMAIL),</span>
|
||||
<span class="fc" id="L21"> displayName(jwt),</span>
|
||||
<span class="fc" id="L22"> authorityNames(authorities)</span>
|
||||
);
|
||||
}
|
||||
|
||||
private static String displayName(Jwt jwt) {
|
||||
<span class="fc" id="L27"> String name = jwt.getClaimAsString(CLAIM_NAME);</span>
|
||||
<span class="pc bpc" id="L28" title="2 of 4 branches missed."> if (name != null && !name.isBlank()) {</span>
|
||||
<span class="fc" id="L29"> return name;</span>
|
||||
}
|
||||
<span class="nc" id="L31"> return jwt.getClaimAsString(CLAIM_PREFERRED_USERNAME);</span>
|
||||
}
|
||||
|
||||
private static Set<String> authorityNames(Collection<? extends GrantedAuthority> authorities) {
|
||||
<span class="fc" id="L35"> return authorities.stream()</span>
|
||||
<span class="fc" id="L36"> .map(GrantedAuthority::getAuthority)</span>
|
||||
<span class="fc" id="L37"> .collect(Collectors.toUnmodifiableSet());</span>
|
||||
}
|
||||
}
|
||||
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+1
File diff suppressed because one or more lines are too long
+50
@@ -0,0 +1,50 @@
|
||||
<?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>KeycloakGrantedAuthoritiesConverter.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">bootstrap</a> > <a href="index.source.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_source">KeycloakGrantedAuthoritiesConverter.java</span></div><h1>KeycloakGrantedAuthoritiesConverter.java</h1><pre class="source lang-java linenums">package com.project.auth.config.auth.security;
|
||||
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.core.authority.SimpleGrantedAuthority;
|
||||
import org.springframework.security.oauth2.jwt.Jwt;
|
||||
import org.springframework.security.oauth2.server.resource.authentication.JwtGrantedAuthoritiesConverter;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
<span class="fc" id="L15">public class KeycloakGrantedAuthoritiesConverter implements Converter<Jwt, Collection<GrantedAuthority>> {</span>
|
||||
|
||||
private static final String CLAIM_REALM_ACCESS = "realm_access";
|
||||
private static final String CLAIM_ROLES = "roles";
|
||||
private static final String ROLE_PREFIX = "ROLE_";
|
||||
|
||||
<span class="fc" id="L21"> private final JwtGrantedAuthoritiesConverter scopeConverter = new JwtGrantedAuthoritiesConverter();</span>
|
||||
|
||||
@Override
|
||||
public Collection<GrantedAuthority> convert(Jwt jwt) {
|
||||
<span class="fc" id="L25"> Set<GrantedAuthority> authorities = new LinkedHashSet<>(scopeConverter.convert(jwt));</span>
|
||||
<span class="fc bfc" id="L26" title="All 2 branches covered."> for (String role : realmRoles(jwt)) {</span>
|
||||
<span class="fc" id="L27"> authorities.add(new SimpleGrantedAuthority(ROLE_PREFIX + role));</span>
|
||||
<span class="fc" id="L28"> }</span>
|
||||
<span class="fc" id="L29"> return Set.copyOf(authorities);</span>
|
||||
}
|
||||
|
||||
private static List<String> realmRoles(Jwt jwt) {
|
||||
<span class="fc" id="L33"> Map<String, Object> realmAccess = jwt.getClaim(CLAIM_REALM_ACCESS);</span>
|
||||
<span class="pc bpc" id="L34" title="1 of 2 branches missed."> if (realmAccess == null) {</span>
|
||||
<span class="nc" id="L35"> return List.of();</span>
|
||||
}
|
||||
|
||||
<span class="fc" id="L38"> Object roles = realmAccess.get(CLAIM_ROLES);</span>
|
||||
<span class="pc bpc" id="L39" title="1 of 2 branches missed."> if (!(roles instanceof Collection<?> roleValues)) {</span>
|
||||
<span class="nc" id="L40"> return List.of();</span>
|
||||
}
|
||||
|
||||
<span class="fc" id="L43"> return roleValues.stream()</span>
|
||||
<span class="fc" id="L44"> .filter(String.class::isInstance)</span>
|
||||
<span class="fc" id="L45"> .map(String.class::cast)</span>
|
||||
<span class="pc bpc" id="L46" title="1 of 2 branches missed."> .filter(role -> !role.isBlank())</span>
|
||||
<span class="fc" id="L47"> .toList();</span>
|
||||
}
|
||||
}
|
||||
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?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>KeycloakJwtAuthenticationConverter</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><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">bootstrap</a> > <a href="index.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_class">KeycloakJwtAuthenticationConverter</span></div><h1>KeycloakJwtAuthenticationConverter</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">0 of 36</td><td class="ctr2">100%</td><td class="bar">0 of 0</td><td class="ctr2">n/a</td><td class="ctr1">0</td><td class="ctr2">2</td><td class="ctr1">0</td><td class="ctr2">7</td><td class="ctr1">0</td><td class="ctr2">2</td></tr></tfoot><tbody><tr><td id="a0"><a href="KeycloakJwtAuthenticationConverter.java.html#L30" class="el_method">convert(Jwt)</a></td><td class="bar" id="b0"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="21" alt="21"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d0"/><td class="ctr2" id="e0">n/a</td><td class="ctr1" id="f0">0</td><td class="ctr2" id="g0">1</td><td class="ctr1" id="h0">0</td><td class="ctr2" id="i1">3</td><td class="ctr1" id="j0">0</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a1"><a href="KeycloakJwtAuthenticationConverter.java.html#L20" class="el_method">KeycloakJwtAuthenticationConverter(Converter, KeycloakAuthenticatedUserFactory)</a></td><td class="bar" id="b1"><img src="../jacoco-resources/greenbar.gif" width="85" height="10" title="15" alt="15"/></td><td class="ctr2" id="c1">100%</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">0</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h1">0</td><td class="ctr2" id="i0">4</td><td class="ctr1" id="j1">0</td><td class="ctr2" id="k1">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+35
@@ -0,0 +1,35 @@
|
||||
<?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>KeycloakJwtAuthenticationConverter.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">bootstrap</a> > <a href="index.source.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_source">KeycloakJwtAuthenticationConverter.java</span></div><h1>KeycloakJwtAuthenticationConverter.java</h1><pre class="source lang-java linenums">package com.project.auth.config.auth.security;
|
||||
|
||||
import com.project.auth.presentation.auth.current.AuthenticatedUser;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
import org.springframework.security.authentication.AbstractAuthenticationToken;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.oauth2.jwt.Jwt;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
|
||||
public class KeycloakJwtAuthenticationConverter implements Converter<Jwt, AbstractAuthenticationToken> {
|
||||
|
||||
private final Converter<Jwt, Collection<GrantedAuthority>> authoritiesConverter;
|
||||
private final KeycloakAuthenticatedUserFactory authenticatedUserFactory;
|
||||
|
||||
public KeycloakJwtAuthenticationConverter(
|
||||
Converter<Jwt, Collection<GrantedAuthority>> authoritiesConverter,
|
||||
KeycloakAuthenticatedUserFactory authenticatedUserFactory
|
||||
<span class="fc" id="L20"> ) {</span>
|
||||
<span class="fc" id="L21"> this.authoritiesConverter = Objects.requireNonNull(authoritiesConverter, "authoritiesConverter must not be null");</span>
|
||||
<span class="fc" id="L22"> this.authenticatedUserFactory = Objects.requireNonNull(</span>
|
||||
authenticatedUserFactory,
|
||||
"authenticatedUserFactory must not be null"
|
||||
);
|
||||
<span class="fc" id="L26"> }</span>
|
||||
|
||||
@Override
|
||||
public AbstractAuthenticationToken convert(Jwt jwt) {
|
||||
<span class="fc" id="L30"> Collection<GrantedAuthority> authorities = authoritiesConverter.convert(jwt);</span>
|
||||
<span class="fc" id="L31"> AuthenticatedUser principal = authenticatedUserFactory.create(jwt, authorities);</span>
|
||||
<span class="fc" id="L32"> return new KeycloakJwtAuthenticationToken(jwt, authorities, principal, jwt.getSubject());</span>
|
||||
}
|
||||
}
|
||||
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?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>KeycloakJwtAuthenticationToken</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><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">bootstrap</a> > <a href="index.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_class">KeycloakJwtAuthenticationToken</span></div><h1>KeycloakJwtAuthenticationToken</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">0 of 12</td><td class="ctr2">100%</td><td class="bar">0 of 0</td><td class="ctr2">n/a</td><td class="ctr1">0</td><td class="ctr2">2</td><td class="ctr1">0</td><td class="ctr2">4</td><td class="ctr1">0</td><td class="ctr2">2</td></tr></tfoot><tbody><tr><td id="a1"><a href="KeycloakJwtAuthenticationToken.java.html#L20" class="el_method">KeycloakJwtAuthenticationToken(Jwt, Collection, AuthenticatedUser, String)</a></td><td class="bar" id="b0"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="9" alt="9"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d0"/><td class="ctr2" id="e0">n/a</td><td class="ctr1" id="f0">0</td><td class="ctr2" id="g0">1</td><td class="ctr1" id="h0">0</td><td class="ctr2" id="i0">3</td><td class="ctr1" id="j0">0</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a0"><a href="KeycloakJwtAuthenticationToken.java.html#L26" class="el_method">getPrincipal()</a></td><td class="bar" id="b1"><img src="../jacoco-resources/greenbar.gif" width="40" height="10" title="3" alt="3"/></td><td class="ctr2" id="c1">100%</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">0</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h1">0</td><td class="ctr2" id="i1">1</td><td class="ctr1" id="j1">0</td><td class="ctr2" id="k1">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
<?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>KeycloakJwtAuthenticationToken.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">bootstrap</a> > <a href="index.source.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_source">KeycloakJwtAuthenticationToken.java</span></div><h1>KeycloakJwtAuthenticationToken.java</h1><pre class="source lang-java linenums">package com.project.auth.config.auth.security;
|
||||
|
||||
import com.project.auth.presentation.auth.current.AuthenticatedUser;
|
||||
import org.springframework.security.core.GrantedAuthority;
|
||||
import org.springframework.security.oauth2.jwt.Jwt;
|
||||
import org.springframework.security.oauth2.server.resource.authentication.JwtAuthenticationToken;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class KeycloakJwtAuthenticationToken extends JwtAuthenticationToken {
|
||||
|
||||
private final AuthenticatedUser principal;
|
||||
|
||||
public KeycloakJwtAuthenticationToken(
|
||||
Jwt jwt,
|
||||
Collection<? extends GrantedAuthority> authorities,
|
||||
AuthenticatedUser principal,
|
||||
String name
|
||||
) {
|
||||
<span class="fc" id="L20"> super(jwt, authorities, name);</span>
|
||||
<span class="fc" id="L21"> this.principal = principal;</span>
|
||||
<span class="fc" id="L22"> }</span>
|
||||
|
||||
@Override
|
||||
public AuthenticatedUser getPrincipal() {
|
||||
<span class="fc" id="L26"> return principal;</span>
|
||||
}
|
||||
}
|
||||
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?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>SecurityActorIdResolver</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><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">bootstrap</a> > <a href="index.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_class">SecurityActorIdResolver</span></div><h1>SecurityActorIdResolver</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">10 of 30</td><td class="ctr2">66%</td><td class="bar">5 of 8</td><td class="ctr2">37%</td><td class="ctr1">3</td><td class="ctr2">6</td><td class="ctr1">2</td><td class="ctr2">9</td><td class="ctr1">0</td><td class="ctr2">2</td></tr></tfoot><tbody><tr><td id="a0"><a href="SecurityActorIdResolver.java.html#L16" class="el_method">resolve(HttpServletRequest)</a></td><td class="bar" id="b0"><img src="../jacoco-resources/redbar.gif" width="44" height="10" title="10" alt="10"/><img src="../jacoco-resources/greenbar.gif" width="75" height="10" title="17" alt="17"/></td><td class="ctr2" id="c1">62%</td><td class="bar" id="d0"><img src="../jacoco-resources/redbar.gif" width="75" height="10" title="5" alt="5"/><img src="../jacoco-resources/greenbar.gif" width="45" height="10" title="3" alt="3"/></td><td class="ctr2" id="e0">37%</td><td class="ctr1" id="f0">3</td><td class="ctr2" id="g0">5</td><td class="ctr1" id="h0">2</td><td class="ctr2" id="i0">8</td><td class="ctr1" id="j0">0</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a1"><a href="SecurityActorIdResolver.java.html#L11" class="el_method">SecurityActorIdResolver()</a></td><td class="bar" id="b1"><img src="../jacoco-resources/greenbar.gif" width="13" height="10" title="3" alt="3"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">0</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h1">0</td><td class="ctr2" id="i1">1</td><td class="ctr1" id="j1">0</td><td class="ctr2" id="k1">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<?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>SecurityActorIdResolver.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">bootstrap</a> > <a href="index.source.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_source">SecurityActorIdResolver.java</span></div><h1>SecurityActorIdResolver.java</h1><pre class="source lang-java linenums">package com.project.auth.config.auth.security;
|
||||
|
||||
import com.project.auth.application.support.logging.LogSanitizer;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.springframework.security.authentication.AnonymousAuthenticationToken;
|
||||
import org.springframework.security.core.Authentication;
|
||||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
|
||||
import java.security.Principal;
|
||||
|
||||
<span class="fc" id="L11">public class SecurityActorIdResolver {</span>
|
||||
|
||||
private static final String ANONYMOUS_PRINCIPAL = "anonymous";
|
||||
|
||||
public String resolve(HttpServletRequest request) {
|
||||
<span class="fc" id="L16"> Principal principal = request.getUserPrincipal();</span>
|
||||
<span class="fc bfc" id="L17" title="All 2 branches covered."> if (principal != null) {</span>
|
||||
<span class="fc" id="L18"> return LogSanitizer.actorId(principal.getName());</span>
|
||||
}
|
||||
|
||||
<span class="fc" id="L21"> Authentication authentication = SecurityContextHolder.getContext().getAuthentication();</span>
|
||||
<span class="pc bpc" id="L22" title="1 of 2 branches missed."> if (authentication != null</span>
|
||||
<span class="nc bnc" id="L23" title="All 4 branches missed."> && authentication.isAuthenticated()</span>
|
||||
&& !(authentication instanceof AnonymousAuthenticationToken)) {
|
||||
<span class="nc" id="L25"> return LogSanitizer.actorId(authentication.getName());</span>
|
||||
}
|
||||
|
||||
<span class="fc" id="L28"> return LogSanitizer.actorId(ANONYMOUS_PRINCIPAL);</span>
|
||||
}
|
||||
}
|
||||
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+1
@@ -0,0 +1 @@
|
||||
<?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>SecurityAuditTrailWriter</title><script type="text/javascript" src="../jacoco-resources/sort.js"></script></head><body onload="initialSort(['breadcrumb'])"><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">bootstrap</a> > <a href="index.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_class">SecurityAuditTrailWriter</span></div><h1>SecurityAuditTrailWriter</h1><table class="coverage" cellspacing="0" id="coveragetable"><thead><tr><td class="sortable" id="a" onclick="toggleSort(this)">Element</td><td class="down sortable bar" id="b" onclick="toggleSort(this)">Missed Instructions</td><td class="sortable ctr2" id="c" onclick="toggleSort(this)">Cov.</td><td class="sortable bar" id="d" onclick="toggleSort(this)">Missed Branches</td><td class="sortable ctr2" id="e" onclick="toggleSort(this)">Cov.</td><td class="sortable ctr1" id="f" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="g" onclick="toggleSort(this)">Cxty</td><td class="sortable ctr1" id="h" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="i" onclick="toggleSort(this)">Lines</td><td class="sortable ctr1" id="j" onclick="toggleSort(this)">Missed</td><td class="sortable ctr2" id="k" onclick="toggleSort(this)">Methods</td></tr></thead><tfoot><tr><td>Total</td><td class="bar">0 of 64</td><td class="ctr2">100%</td><td class="bar">0 of 0</td><td class="ctr2">n/a</td><td class="ctr1">0</td><td class="ctr2">3</td><td class="ctr1">0</td><td class="ctr2">16</td><td class="ctr1">0</td><td class="ctr2">3</td></tr></tfoot><tbody><tr><td id="a0"><a href="SecurityAuditTrailWriter.java.html#L22" class="el_method">record(HttpServletRequest, AuthAuditEventType, String)</a></td><td class="bar" id="b0"><img src="../jacoco-resources/greenbar.gif" width="120" height="10" title="51" alt="51"/></td><td class="ctr2" id="c0">100%</td><td class="bar" id="d0"/><td class="ctr2" id="e0">n/a</td><td class="ctr1" id="f0">0</td><td class="ctr2" id="g0">1</td><td class="ctr1" id="h0">0</td><td class="ctr2" id="i0">11</td><td class="ctr1" id="j0">0</td><td class="ctr2" id="k0">1</td></tr><tr><td id="a2"><a href="SecurityAuditTrailWriter.java.html#L12" class="el_method">static {...}</a></td><td class="bar" id="b1"><img src="../jacoco-resources/greenbar.gif" width="16" height="10" title="7" alt="7"/></td><td class="ctr2" id="c1">100%</td><td class="bar" id="d1"/><td class="ctr2" id="e1">n/a</td><td class="ctr1" id="f1">0</td><td class="ctr2" id="g1">1</td><td class="ctr1" id="h1">0</td><td class="ctr2" id="i2">2</td><td class="ctr1" id="j1">0</td><td class="ctr2" id="k1">1</td></tr><tr><td id="a1"><a href="SecurityAuditTrailWriter.java.html#L17" class="el_method">SecurityAuditTrailWriter(SecurityActorIdResolver)</a></td><td class="bar" id="b2"><img src="../jacoco-resources/greenbar.gif" width="14" height="10" title="6" alt="6"/></td><td class="ctr2" id="c2">100%</td><td class="bar" id="d2"/><td class="ctr2" id="e2">n/a</td><td class="ctr1" id="f2">0</td><td class="ctr2" id="g2">1</td><td class="ctr1" id="h2">0</td><td class="ctr2" id="i1">3</td><td class="ctr1" id="j2">0</td><td class="ctr2" id="k2">1</td></tr></tbody></table><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
<?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>SecurityAuditTrailWriter.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">bootstrap</a> > <a href="index.source.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_source">SecurityAuditTrailWriter.java</span></div><h1>SecurityAuditTrailWriter.java</h1><pre class="source lang-java linenums">package com.project.auth.config.auth.security;
|
||||
|
||||
import com.project.auth.application.support.audit.AuthAuditEventType;
|
||||
import com.project.auth.application.support.audit.AuthAuditFields;
|
||||
import com.project.auth.application.support.logging.LogSanitizer;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class SecurityAuditTrailWriter {
|
||||
|
||||
<span class="fc" id="L12"> private static final Logger log = LoggerFactory.getLogger(SecurityAuditTrailWriter.class);</span>
|
||||
<span class="fc" id="L13"> private static final Logger audit = LoggerFactory.getLogger("audit.auth");</span>
|
||||
|
||||
private final SecurityActorIdResolver actorIdResolver;
|
||||
|
||||
<span class="fc" id="L17"> public SecurityAuditTrailWriter(SecurityActorIdResolver actorIdResolver) {</span>
|
||||
<span class="fc" id="L18"> this.actorIdResolver = actorIdResolver;</span>
|
||||
<span class="fc" id="L19"> }</span>
|
||||
|
||||
public void record(HttpServletRequest request, AuthAuditEventType eventType, String message) {
|
||||
<span class="fc" id="L22"> String actorId = actorIdResolver.resolve(request);</span>
|
||||
<span class="fc" id="L23"> String requestPath = LogSanitizer.requestPath(request.getRequestURI());</span>
|
||||
<span class="fc" id="L24"> log.warn(</span>
|
||||
"{} actorId={} method={} requestPath={}",
|
||||
message,
|
||||
actorId,
|
||||
<span class="fc" id="L28"> request.getMethod(),</span>
|
||||
requestPath
|
||||
);
|
||||
<span class="fc" id="L31"> audit.atWarn()</span>
|
||||
<span class="fc" id="L32"> .addKeyValue(AuthAuditFields.EVENT_TYPE, eventType.code())</span>
|
||||
<span class="fc" id="L33"> .addKeyValue(AuthAuditFields.ACTOR_ID, actorId)</span>
|
||||
<span class="fc" id="L34"> .addKeyValue(AuthAuditFields.METHOD, request.getMethod())</span>
|
||||
<span class="fc" id="L35"> .addKeyValue(AuthAuditFields.REQUEST_PATH, requestPath)</span>
|
||||
<span class="fc" id="L36"> .log(eventType.code());</span>
|
||||
<span class="fc" id="L37"> }</span>
|
||||
}
|
||||
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+1
File diff suppressed because one or more lines are too long
+77
@@ -0,0 +1,77 @@
|
||||
<?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>SecurityExceptionHandler.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">bootstrap</a> > <a href="index.source.html" class="el_package">com.project.auth.config.auth.security</a> > <span class="el_source">SecurityExceptionHandler.java</span></div><h1>SecurityExceptionHandler.java</h1><pre class="source lang-java linenums">package com.project.auth.config.auth.security;
|
||||
|
||||
import com.project.auth.application.support.audit.AuthAuditEventType;
|
||||
import com.project.auth.application.support.logging.LogSanitizer;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.security.access.AccessDeniedException;
|
||||
import org.springframework.security.core.AuthenticationException;
|
||||
import org.springframework.security.web.AuthenticationEntryPoint;
|
||||
import org.springframework.security.web.access.AccessDeniedHandler;
|
||||
import org.springframework.web.servlet.HandlerExceptionResolver;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
public class SecurityExceptionHandler implements AuthenticationEntryPoint, AccessDeniedHandler {
|
||||
|
||||
<span class="fc" id="L19"> private static final Logger log = LoggerFactory.getLogger(SecurityExceptionHandler.class);</span>
|
||||
|
||||
private final HandlerExceptionResolver handlerExceptionResolver;
|
||||
private final SecurityAuditTrailWriter securityAuditTrailWriter;
|
||||
|
||||
public SecurityExceptionHandler(
|
||||
HandlerExceptionResolver handlerExceptionResolver,
|
||||
SecurityAuditTrailWriter securityAuditTrailWriter
|
||||
<span class="fc" id="L27"> ) {</span>
|
||||
<span class="fc" id="L28"> this.handlerExceptionResolver = Objects.requireNonNull(</span>
|
||||
handlerExceptionResolver,
|
||||
"handlerExceptionResolver must not be null"
|
||||
);
|
||||
<span class="fc" id="L32"> this.securityAuditTrailWriter = Objects.requireNonNull(</span>
|
||||
securityAuditTrailWriter,
|
||||
"securityAuditTrailWriter must not be null"
|
||||
);
|
||||
<span class="fc" id="L36"> }</span>
|
||||
|
||||
@Override
|
||||
public void commence(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
AuthenticationException authException
|
||||
) {
|
||||
<span class="fc" id="L44"> recordAudit(request, AuthAuditEventType.AUTHENTICATION_REQUIRED, "Authentication required.");</span>
|
||||
<span class="pc bpc" id="L45" title="1 of 2 branches missed."> if (response.isCommitted()) {</span>
|
||||
<span class="nc" id="L46"> log.warn("Response already committed; cannot render authentication error body. requestPath={}",</span>
|
||||
<span class="nc" id="L47"> LogSanitizer.requestPath(request.getRequestURI()));</span>
|
||||
<span class="nc" id="L48"> return;</span>
|
||||
}
|
||||
<span class="fc" id="L50"> handlerExceptionResolver.resolveException(request, response, null, authException);</span>
|
||||
<span class="fc" id="L51"> }</span>
|
||||
|
||||
@Override
|
||||
public void handle(
|
||||
HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
AccessDeniedException accessDeniedException
|
||||
) {
|
||||
<span class="fc" id="L59"> recordAudit(request, AuthAuditEventType.ACCESS_DENIED, "Access denied.");</span>
|
||||
<span class="pc bpc" id="L60" title="1 of 2 branches missed."> if (response.isCommitted()) {</span>
|
||||
<span class="nc" id="L61"> log.warn("Response already committed; cannot render access-denied error body. requestPath={}",</span>
|
||||
<span class="nc" id="L62"> LogSanitizer.requestPath(request.getRequestURI()));</span>
|
||||
<span class="nc" id="L63"> return;</span>
|
||||
}
|
||||
<span class="fc" id="L65"> handlerExceptionResolver.resolveException(request, response, null, accessDeniedException);</span>
|
||||
<span class="fc" id="L66"> }</span>
|
||||
|
||||
private void recordAudit(HttpServletRequest request, AuthAuditEventType type, String description) {
|
||||
try {
|
||||
<span class="fc" id="L70"> securityAuditTrailWriter.record(request, type, description);</span>
|
||||
<span class="nc" id="L71"> } catch (RuntimeException auditFailure) {</span>
|
||||
<span class="nc" id="L72"> log.warn("Security audit write failed; continuing with response rendering. type={}",</span>
|
||||
type, auditFailure);
|
||||
<span class="fc" id="L74"> }</span>
|
||||
<span class="fc" id="L75"> }</span>
|
||||
}
|
||||
</pre><div class="footer"><span class="right">Created with <a href="http://www.jacoco.org/jacoco">JaCoCo</a> 0.8.13.202504020838</span></div></body></html>
|
||||
+1
File diff suppressed because one or more lines are too long
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user