Skip to content

Commit

Permalink
oppdatert med sikring av metodene
Browse files Browse the repository at this point in the history
  • Loading branch information
tofiksa committed Jul 23, 2024
1 parent 9ede0ed commit 22498f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.http.SessionCreationPolicy;
Expand All @@ -16,6 +17,7 @@

@Configuration
@EnableWebSecurity
@EnableMethodSecurity
public class SecurityConfiguration {
private final AuthenticationProvider authenticationProvider;
private final JwtAuthenticationFilter jwtAuthenticationFilter;
Expand All @@ -33,10 +35,9 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
http.csrf()
.disable()
.authorizeHttpRequests()
.requestMatchers("/auth/**")
.permitAll()
.requestMatchers("/swagger-ui.html", "/swagger-ui/**", "/swagger-resources/**", "/swagger-resources", "/v3/api-docs/*", "/v3/api-docs").hasRole("ANONYMOUS")
.requestMatchers("/register/**").hasRole("ANONYMOUS")
.requestMatchers("/auth/**").permitAll()
.requestMatchers("/swagger-ui.html", "/swagger-ui/**", "/swagger-resources/**", "/swagger-resources", "/v3/api-docs/*", "/v3/api-docs").permitAll()
.requestMatchers("/register/**").permitAll()
.anyRequest()
.authenticated()
.and()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import no.josefushighscore.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
Expand All @@ -19,7 +19,7 @@ public class UserInfoController {
private UserService userService;


@Secured("ROLE_USER")
@PreAuthorize("hasRole('ROLE_USER')")
@GetMapping("/me")
public ResponseEntity currentUser(@AuthenticationPrincipal UserDetails userDetails) throws InvalidJwtAuthenticationException {
return ok(userService.getUserDetails(userDetails.getUsername()));
Expand Down

0 comments on commit 22498f6

Please sign in to comment.