Spring security spring引导受限url

Spring security spring引导受限url,spring-security,spring-boot,Spring Security,Spring Boot,你好, 我有一个spring boot 1.1.4.RELEASE应用程序,它使用spring security作为依赖项,例如: compile("org.springframework.boot:spring-boot-starter-security") compile("org.springframework.security:spring-security-web:4.0.0.M1") compile("org.springframework.security:spring-s

你好, 我有一个spring boot 1.1.4.RELEASE应用程序,它使用spring security作为依赖项,例如:

compile("org.springframework.boot:spring-boot-starter-security")    
compile("org.springframework.security:spring-security-web:4.0.0.M1")
compile("org.springframework.security:spring-security-config:4.0.0.M1")
compile('org.thymeleaf.extras:thymeleaf-extras-springsecurity3:2.1.1.RELEASE')
我有两种角色:“用户”和“管理员”。后者拥有前者的一切,但也可以访问管理屏幕。在my Thymeleaf页面中,我仅通过显示指向具有管理员角色的用户的链接,这很好:

<li sec:authorize="hasRole('ADMIN')">
    <i class="fa fa-link"></i><a th:href="@{/admin}">
            Administer User</a>
</li>
}

我的配置中是否缺少或不正确

更新: 根据Dave的回答,我使用的解决方案是使用以下三行:

.antMatchers( "/admin**" ).hasAuthority("ADMIN" )
.antMatchers( "/admin/" ).hasAuthority( "ADMIN" )
.antMatchers( "/admin/**" ).hasAuthority( "ADMIN" )

这将在浏览器上显示403错误。最后,我会尝试让它重定向到错误页面或“/”。

您只显式地保护了“/admin/”(带尾随斜杠)。我想如果您访问“/admin”(不带尾随斜杠),您需要比这更精确.

谢谢你,Dave。实际上我不得不添加以下两行,这样页面就不会呈现:.antMatchers(“/admin**”).hasRole(“admin”)和&.antMatchers(“/admin/**”).hasRole(“admin”)否则,/admin/url将呈现
.antMatchers( "/admin**" ).hasAuthority("ADMIN" )
.antMatchers( "/admin/" ).hasAuthority( "ADMIN" )
.antMatchers( "/admin/**" ).hasAuthority( "ADMIN" )