-1
스프링 부트 앱에 두 가지 다른 로그인 흐름이 있습니다. 스프링 보안 다중 로그인 필터
- 일반 양식 로그인 나는 다음을 시도했지만 항상 2 하나 개의 필터에오고. 상태 비 저장 인증을 위해서는
/api/**
을, 그리고 일반 세션 로그인에는 다른 것을 어떻게 제한합니까?@Configuration public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Autowired DataSource dataSource; @Autowired public void configAuthentication(AuthenticationManagerBuilder auth) throws Exception { auth .jdbcAuthentication() .dataSource(dataSource) .usersByUsernameQuery("select username,password, enabled from users where username=?") .authoritiesByUsernameQuery("select username, authority from authorities where username=?"); } private final UserService userService; private final TokenAuthenticationService tokenAuthenticationService; public WebSecurityConfig() { super(true); this.userService = new UserService(); tokenAuthenticationService = new TokenAuthenticationService("tooManySecrets", userService); } @Override protected void configure(HttpSecurity http) throws Exception { http .csrf().disable(); // Normal form login using jdbc http .authorizeRequests() .antMatchers("/", "/home").access("hasRole('ROLE_ADMIN')") .and() .formLogin() .loginPage("/login") .usernameParameter("username") .passwordParameter("password") .permitAll() .and() .logout().permitAll(); //Stateless authentication using tokens - Custome authentication from token implemented in the filter http .authorizeRequests() .antMatchers("/api").authenticated() .and() .addFilterBefore(new StatelessAuthenticationFilter(tokenAuthenticationService), UsernamePasswordAuthenticationFilter.class); } }