RestController에 인증을 추가하려고하는데 Java Configuration으로 좋은 설명서 나 샘플을 찾을 수 없습니다. Java 구성 + REST 인증을 사용하는 스프링 보안 방법 수준 보안?
나는이 시도하지만내 컨트롤러가 @PreAuthorize
@RestController
@RequestMapping("/api/hello")
public class HelloController {
@RequestMapping(value = "/say", method = RequestMethod.GET)
public String sayHello() {
return "hello";
}
@PreAuthorize("hasRole('ROLE_USER')")
@RequestMapping(value = "/say/user", method = RequestMethod.GET)
public String sayHelloWithUserProtection(){
return "Hello USER";
}
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/say/admin", method = RequestMethod.GET)
public String sayHelloWithAdminrProtection(){
return "Hello ADMIN";
}
}
의 SecurityConfig
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
@ComponentScan(basePackages = {"com.test.server.security"})
public class SecurityConfig {
@Autowired
public void configureAuthentification(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER").and()
.withUser("admin").password("admin").roles("USER","ADMIN");
}
@Configuration
public static class ApiWebConfigurerAdapter extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/api/**")
.formLogin();
}
}
}
SecurityWebApplicationInitializer의 주석을 붙일 수 있고 (내가 로그인없이 모든 요청에 액세스 할 수 있습니다) 작동하지 않습니다
public class SecurityWebApplicationInitializer extends AbstractSecurityWebApplicationInitializer {
}
어떻게 작동시킬 수 있습니까?
Java 구성으로 REST 토큰 기반 (세션 키 및 다른 사용자 정의 값 저장 토큰) 인증을 JPA (또는 JDBC?) 데이터베이스에 저장하는 좋은 지침이 있습니까?
나는 그것을 얻지 못한다. 더 자세히 설명해 주겠다.?, web.xml에서 Spring config를 시작한다. – pazfernando