Spring security จะไม่เปลี่ยนเส้นทางไปยังหน้าเข้าสู่ระบบอีกต่อไปหลังจากอัปเกรดเป็นจาก Spring Boot 1.5-2, Spring Security 4-5

ฉันมีแอป OAUTH2 ที่จุดสิ้นสุด oauth2 ได้รับการรักษาความปลอดภัยโดย Spring Security ดังนั้นบางหน้าจึงได้รับการปกป้องโดยการเข้าสู่ระบบตามแบบฟอร์ม

ก่อนหน้านี้หากฉันคลิก URL เหล่านี้ ฉันจะถูกเปลี่ยนเส้นทางไปยังหน้าเข้าสู่ระบบอย่างถูกต้อง

ฉันเพิ่งอัพเกรดจาก Spring Boot 1.5.16 เป็น Spring Boot 2.0.6 ส่งผลให้มีการอัพเกรดผ่านการพึ่งพา Spring Security จาก 4.2.8 เป็น 5.0.9

ตอนนี้ถ้าฉันกด URL ที่ฉันไม่ได้เข้าสู่ระบบ ฉันเพิ่งได้รับหน้าเว็บแบบนี้:

<oauth>
  <error_description>
    Full authentication is required to access this resource
  </error_description>
  <error>unauthorized</error>
</oauth>

มีอะไรมากกว่านั้นหากฉันพยายามกดหน้าเข้าสู่ระบบโดยไม่ได้รับอนุญาต มีใครทราบบ้างไหมว่าสาเหตุของสิ่งนี้คืออะไร ลำดับการกรองเป็นไปได้ ?

นี่คือลักษณะการกำหนดค่าความปลอดภัยของฉัน:

@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {

    private final AuthenticationManager authenticationManager;

    private final Environment environment;

    @Autowired
    public SecurityConfig(AuthenticationManager authenticationManager, Environment environment) {
        this.authenticationManager = authenticationManager;
        this.environment = environment;
    }


    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.csrf().disable().
                headers().frameOptions().disable().and()
                .formLogin().loginPage("/login").permitAll()
                .and()
                .requestMatchers().antMatchers("/login", "/logout", "/oauth/authorize", "/oauth/confirm_access")
                .and()
                .authorizeRequests().anyRequest().authenticated();
    }
}

และนี่คือสายโซ่ตัวกรองที่ถูกสร้างขึ้น:

2018-10-19 15:22:10.865  INFO 19012 --- [  restartedMain] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/oauth/token'], Ant [pattern='/oauth/token_key'], Ant [pattern='/oauth/check_token']]], [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@737f44b6, org.springframework.security.web.context.SecurityContextPersistenceFilter@61f7a8e9, org.springframework.security.web.header.HeaderWriterFilter@139be706, org.springframework.security.web.authentication.logout.LogoutFilter@60b40eca, org.springframework.security.web.authentication.www.BasicAuthenticationFilter@7467a12, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@4fd13263, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@1d003890, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@6e762f08, org.springframework.security.web.session.SessionManagementFilter@13f07542, org.springframework.security.web.access.ExceptionTranslationFilter@2e2ecd3a, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@65db717c]
2018-10-19 15:22:10.880  INFO 19012 --- [  restartedMain] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: org.springframework.security.oauth2.config.annotation.web.configuration.ResourceServerConfiguration$NotOAuthRequestMatcher@4432df93, [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@c48f5fc, org.springframework.security.web.context.SecurityContextPersistenceFilter@731455ec, org.springframework.security.web.header.HeaderWriterFilter@67e583c6, org.springframework.security.web.authentication.logout.LogoutFilter@7bc67409, org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter@4c112545, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@16762cc2, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@5dc67679, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@5473e34c, org.springframework.security.web.session.SessionManagementFilter@4e9d0777, org.springframework.security.web.access.ExceptionTranslationFilter@750210bc, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@d7ab665]
2018-10-19 15:22:10.895  INFO 19012 --- [  restartedMain] o.s.s.web.DefaultSecurityFilterChain     : Creating filter chain: OrRequestMatcher [requestMatchers=[Ant [pattern='/login'], Ant [pattern='/logout'], Ant [pattern='/oauth/authorize'], Ant [pattern='/oauth/confirm_access']]], [org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@22671580, org.springframework.security.web.context.SecurityContextPersistenceFilter@412e0841, org.springframework.security.web.header.HeaderWriterFilter@60f6611f, org.springframework.security.web.authentication.logout.LogoutFilter@24ec00c6, org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter@1531681a, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@242e419a, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@77833299, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@2ea3b229, org.springframework.security.web.session.SessionManagementFilter@38fd683f, org.springframework.security.web.access.ExceptionTranslationFilter@7e4364ca, org.springframework.security.web.access.intercept.FilterSecurityInterceptor@63dad600]
201

person PaulNUK    schedule 19.10.2018    source แหล่งที่มา
comment
คุณได้อ่านคู่มือการโยกย้ายแล้วหรือยัง? (บูตสปริง)[github.com/ spring-projects/spring-boot/wiki/ & (ความปลอดภัยของสปริง) [github.com/spring-projects/spring-boot/wiki/   -  person Randy Casburn    schedule 19.10.2018
comment
ใช่ ไม่มีอะไรโดดเด่น   -  person PaulNUK    schedule 19.10.2018
comment
ฉันจะตรวจสอบ github .com/spring-projects/spring-boot/wiki/ โดยพื้นฐานแล้วความปลอดภัยใด ๆ ที่คุณเชื่อถือโดย Boot จะไม่สามารถใช้งานได้อีกต่อไปใน 2.x   -  person Rob Winch    schedule 19.10.2018
comment
กลายเป็นลำดับการกรอง   -  person PaulNUK    schedule 30.01.2019
comment
@PaulNUK สวัสดี ขออภัย ฉันไม่สามารถหาวิธีแก้ปัญหาสำหรับปัญหาที่กล่าวมาข้างต้นได้ คุณช่วยอธิบายอย่างละเอียดได้ไหมในขณะที่ฉันกำลังประสบปัญหาเดียวกัน ขอบคุณล่วงหน้า.   -  person Vibhav Chaddha    schedule 26.04.2019


คำตอบ (1)


สิ่งนี้ใช้ได้กับฉัน

    import org.springframework.context.annotation.Configuration;
    import org.springframework.security.config.annotation.web.builders.HttpSecurity;
    import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
    import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

    @Configuration
    @EnableWebSecurity
    public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

        @Override
        protected void configure(HttpSecurity http) throws Exception {
            http.csrf().disable();
            http.authorizeRequests().
            antMatchers("/db*/**").fullyAuthenticated().
            antMatchers("/rest/**").permitAll().
            and().formLogin().  //login configuration
            loginPage("/index.jsf?faces-redirect=true");
        }
    }

และที่ url คุณต้องให้ localhost:8080/db/ และมันจะเปลี่ยนเส้นทางไปยังหน้าดัชนีของคุณโดยอัตโนมัติ

person Aneesh Mathai    schedule 30.01.2019