Мне нужно убедиться, что пользователь 123 из арендатора 1 может только разрушить свои собственные настройки. Ни настройки других пользователей одного и того же арендатора, ни настройки пользователей других арендаторов.
Код: Выделить всё
@Configuration
@EnableWebSecurity
public class DirectlyConfiguredJwkSetUri {
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(authorize -> authorize
.requestMatchers("/contacts/**").access(hasScope("contacts"))
.requestMatchers("/messages/**").access(hasScope("messages"))
.anyRequest().authenticated()
)
.oauth2ResourceServer(oauth2 -> oauth2
.jwt(Customizer.withDefaults())
);
return http.build();
}
}
< /code>
или на уровне метода: < /p>
@PreAuthorize("hasAuthority('SCOPE_messages')")
public List getMessages(...) {}
Подробнее здесь: https://stackoverflow.com/questions/795 ... issued-jwt