Files
project-auth-server/build/reports/jacoco/aggregate/html/com.project.auth.config.auth.security/KeycloakAuthenticatedUserFactory.java.html
T

40 lines
3.1 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>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">project-auth-server</a> &gt; <a href="index.source.html" class="el_package">com.project.auth.config.auth.security</a> &gt; <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 = &quot;email&quot;;
private static final String CLAIM_NAME = &quot;name&quot;;
private static final String CLAIM_PREFERRED_USERNAME = &quot;preferred_username&quot;;
public AuthenticatedUser create(Jwt jwt, Collection&lt;? extends GrantedAuthority&gt; 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 &amp;&amp; !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&lt;String&gt; authorityNames(Collection&lt;? extends GrantedAuthority&gt; 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.14.202510111229</span></div></body></html>