Spring Security - 检查Web URL是否安全/受保护

use*_*877 7 spring-security

如果当前请求是安全的,有没有办法"询问"弹簧安全性?因为即使我经过身份验证,我也想检测我是在安全的受保护URL中还是在匿名/公共页面中

提前致谢!

HRg*_*ger 0

我认为您可以使用自己的实现,AccessDecisionVoter 然后只需覆盖Vote方法并使用方法比较拦截 url 即可filterInvocation.getRequestUrl();

@Override
public int vote(Authentication authentication, FilterInvocation filterInvocation,
    Collection<ConfigAttribute> attributes) {
  String requestUrl = filterInvocation.getRequestUrl();
  ....
}
Run Code Online (Sandbox Code Playgroud)