How can I change my code according to Sonar lint rules?
My code is below:
public interface TokenParser {
public Optional<String> getUserName();
}
public class JWTTokenParser implements TokenParser {
private Optional<Jwt> getJwt() {
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
if (!authentication.isAuthenticated() || authentication instanceof AnonymousAuthenticationToken) {
return Optional.empty();
}
return Optional.ofNullable((Jwt) authentication.getPrincipal());
}
@Override
public Optional<String> getUserName() {
return Optional.ofNullable(getJwt().get().getClaimAsString("preferred_username"));
}
}
I could not pass the Sonar rules. How can I change my code?