Multiple antMatchers in Spring security

前端 未结 1 1534
说谎
说谎 2020-12-12 22:04

I work on content management system, that has five antMatchers like the following:

http.authorizeRequests()
        .antMatchers(\"/\", \"/*.html\")         


        
1条回答
  •  暖寄归人
    2020-12-12 22:34

    I believe that the problem is in the order of your rules:

    .antMatchers("/admin/**").hasRole("ADMIN")
    .antMatchers("/admin/login").permitAll()
    

    The order of the rules matters and the more specific rules should go first. Now everything that starts with /admin will require authenticated user with ADMIN role, even the /admin/login path (because /admin/login is already matched by the /admin/** rule and therefore the second rule is ignored).

    The rule for the login page should therefore go before the /admin/** rule. E.G.

    .antMatchers("/admin/login").permitAll()
    .antMatchers("/admin/**").hasRole("ADMIN")
    

    0 讨论(0)
提交回复
热议问题