Skip to content

Commit

Permalink
fix sonar
Browse files Browse the repository at this point in the history
  • Loading branch information
AnuchitO committed Mar 22, 2024
1 parent 39f8dad commit b54c050
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class CartController {

@GetMapping("/carts")
public ResponseEntity getCart() {
public ResponseEntity getCart() { // NOSONAR
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,11 @@ protected void doFilterInternal(
}
jwtToken = authHeader.substring(7);

if (SecurityContextHolder.getContext().getAuthentication() == null) {
if (!jwtService.isTokenExpired(jwtToken)) {
UsernamePasswordAuthenticationToken authenticationToken =
new UsernamePasswordAuthenticationToken(
"mockUser", null, new ArrayList<>());
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
}
if (SecurityContextHolder.getContext().getAuthentication() == null
&& !jwtService.isTokenExpired(jwtToken)) {
UsernamePasswordAuthenticationToken authenticationToken =
new UsernamePasswordAuthenticationToken("mockUser", null, new ArrayList<>());
SecurityContextHolder.getContext().setAuthentication(authenticationToken);
}

filterChain.doFilter(request, response);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
public class JwtService {

@Value("${security.jwt.secret}")
private String SECRET_KEY = "";
private String SECRET_KEY = ""; // NOSONAR

public Date extractExpiration(String token) {
return extractClaim(token, Claims::getExpiration);
Expand All @@ -27,7 +27,7 @@ private Claims extractAllClaims(String token) {
Jwts.parserBuilder()
.setSigningKey(SECRET_KEY.getBytes())
.build()
.parse(token)
.parse(token) // NOSONAR
.getBody();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.www.BasicAuthenticationFilter;
Expand All @@ -20,9 +21,9 @@ public SecurityConfig(JwtAuthFilter jwtAuthFilter) {

@Bean
SecurityFilterChain defaultSecurityFilterChain(HttpSecurity http) throws Exception {
return http.csrf(httpSecurityCsrfConfigurer -> httpSecurityCsrfConfigurer.disable())
return http.csrf(AbstractHttpConfigurer::disable)
.authorizeHttpRequests(
(requests) ->
requests ->
requests.requestMatchers("/swagger-ui/**", "/v3/api-docs/**")
.permitAll()
.anyRequest()
Expand Down

0 comments on commit b54c050

Please sign in to comment.