내 응용 프로그램에서 스프링 보안을 사용하고 있습니다. 역할 (관리자, 사용자)을 기반으로 API를 인증합니다. 매개 변수로 전달 된 변수의 값을 사용하여 액세스를 제한하려는 API 끝점이 하나 있습니다.스프링 보안 클래스의 변수 값을 사용하여 인증하기
내가 가진
@Override
protected void configure(HttpSecurity httpSecurity) throws Exception {
httpSecurity.csrf().disable().exceptionHandling().authenticationEntryPoint(this.unauthorizedHandler).and()
.sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().authorizeRequests()
.antMatchers(HttpMethod.OPTIONS, "/**").permitAll()
.antMatchers("/api/**").authenticated()
.anyRequest().permitAll();
httpSecurity.addFilterBefore(authenticationTokenFilterBean(), UsernamePasswordAuthenticationFilter.class);
}
내가 가진 전화
@PostMapping("/something")
public ResponseEntity<BotResponse> handleRequest(@Valid @RequestBody SomeClass someClass) {
// if someClass.getSomeValue() is not present in the User permissions, then it should give an unauthorized response.
return value(someClass);
}
봄 보안의 사용자는 다음과 같습니다
public Class User {
String userId;
String userName;
String authorities;
List<String> someList;
//Getters and setters for variables
}
그리고 사용 SomeClass은 다음과 같습니다
public Class SomeClass {
String someValue;
String userName;
...
// Getters and Setters
}
someClass.getSomeValue의 값이 User의 someList에있는 경우 사용자 기반으로 허용하지 않으려면 어떻게해야합니까?