Skip to content

Commit

Permalink
Fixed SonarLint smells
Browse files Browse the repository at this point in the history
  • Loading branch information
massenz committed Oct 26, 2023
1 parent a590da4 commit 4b3d82f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,11 @@
@Service @Slf4j
public class ApiTokenAuthenticationFactory {

@Autowired
JwtTokenProvider provider;
private final JwtTokenProvider provider;

public ApiTokenAuthenticationFactory(JwtTokenProvider provider) {
this.provider = provider;
}

/**
* Creates an implementation of the {@link Authentication} interface which implements the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@

package com.alertavert.opademo.api;

import com.alertavert.opademo.DbInit;
import com.alertavert.opademo.data.ReactiveUsersRepository;
import com.alertavert.opa.jwt.JwtTokenProvider;
import com.alertavert.opademo.data.ReactiveUsersRepository;
import com.alertavert.opademo.data.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.Base64Utils;
import org.springframework.util.MimeTypeUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
Expand All @@ -38,6 +34,7 @@
import reactor.core.publisher.Mono;

import java.nio.charset.StandardCharsets;
import java.util.Base64;
import java.util.UUID;

import static com.alertavert.opa.Constants.BASIC_AUTH;
Expand All @@ -56,14 +53,13 @@
consumes = MimeTypeUtils.ALL_VALUE)
public class LoginController {

@Autowired
JwtTokenProvider provider;
private final JwtTokenProvider provider;
private final ReactiveUsersRepository repository;

@Autowired
ReactiveUsersRepository repository;

@Autowired
PasswordEncoder encoder;
public LoginController(JwtTokenProvider provider, ReactiveUsersRepository repository) {
this.provider = provider;
this.repository = repository;
}


@GetMapping
Expand Down Expand Up @@ -114,7 +110,7 @@ public static Mono<String> usernameFromHeader(String credentials) {
log.debug("Extracting username from Authorization header");
if (credentials.startsWith(BASIC_AUTH)) {
return Mono.just(credentials.substring(BASIC_AUTH.length() + 1))
.map(enc -> Base64Utils.decode(enc.getBytes(StandardCharsets.UTF_8)))
.map(enc -> Base64.getDecoder().decode(enc.getBytes(StandardCharsets.UTF_8)))
.map(String::new)
.map(creds -> {
String[] userPass = creds.split(":");
Expand All @@ -126,7 +122,7 @@ public static Mono<String> usernameFromHeader(String credentials) {
}

public static Mono<String> credentialsToHeader(String credentials) {
String encoded = Base64Utils.encodeToString(credentials.getBytes(StandardCharsets.UTF_8));
String encoded = Base64.getEncoder().encodeToString(credentials.getBytes(StandardCharsets.UTF_8));
return Mono.just(String.format("%s %s", BASIC_AUTH, encoded));
}
}

0 comments on commit 4b3d82f

Please sign in to comment.