Код: Выделить всё
@RestController
@RequestMapping(path = "/")
public class HomeController {
@GetMapping
public String home() {
return "Hello, %s".formatted(SecurityContextHolder.getContext().getAuthentication().getName());
}
}
Код: Выделить всё
Hello, anonymousUser
Код: Выделить всё
@Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http, Converter converter) throws Exception {
http
.authorizeHttpRequests(authorize ->
authorize
.anyRequest()
.permitAll()
)
.csrf(AbstractHttpConfigurer::disable)
.cors(AbstractHttpConfigurer::disable)
.httpBasic(AbstractHttpConfigurer::disable)
.oauth2Login(withDefaults())
.oauth2ResourceServer(configurer ->
configurer
.jwt((jwt) -> jwt.jwtAuthenticationConverter(converter))
)
.sessionManagement(configurer ->
configurer
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
)
.exceptionHandling(configurer ->
configurer
.authenticationEntryPoint(new BearerTokenAuthenticationEntryPoint())
.accessDeniedHandler(new BearerTokenAccessDeniedHandler())
);
return http.build();
}
Код: Выделить всё
spring:
security:
oauth2:
client:
registration:
github:
clientId:
clientSecret:
redirect-uri: '{baseUrl}/login/oauth2/code/{registrationId}'
Я так понял, что это происходит из-за настроек:
Код: Выделить всё
.sessionManagement(configurer ->
configurer
.sessionCreationPolicy(SessionCreationPolicy.STATELESS)
)
Подробнее здесь: https://stackoverflow.com/questions/785 ... pring-boot
Мобильная версия