Spring security Spring安全性-检查web url是否安全/受保护

Spring security Spring安全性-检查web url是否安全/受保护,spring-security,Spring Security,如果当前请求是安全的,有没有办法“询问”spring安全性?因为即使我通过了身份验证,我也希望检测我是在一个受安全保护的URL中还是在一个匿名/公共页面中 提前谢谢 我认为您可以使用自己的实现来实现AccessDecisionVoter,然后只需覆盖方法,并使用filtering.getRequestUrl()比较拦截url方法 @Override public int vote(Authentication authentication, FilterInvocation filterInvo

如果当前请求是安全的,有没有办法“询问”spring安全性?因为即使我通过了身份验证,我也希望检测我是在一个受安全保护的URL中还是在一个匿名/公共页面中


提前谢谢

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

@Override
public int vote(Authentication authentication, FilterInvocation filterInvocation,
    Collection<ConfigAttribute> attributes) {
  String requestUrl = filterInvocation.getRequestUrl();
  ....
}
@覆盖
公共整数投票(身份验证、筛选职业筛选职业、,
集合属性){
字符串requestUrl=filterInvocation.getRequestUrl();
....
}

我们可以将其标记为安全通道,以便转换为https://url

    <intercept-url pattern="/**" access="IS_AUTHENTICATED_FULLY" requires-channel="https" />

然后我们可以使用request.getScheme()来识别它。 我使用了org.springframework.security.version 3.1.4.RELEASE

Spring security为此提供了支持。例如:

<sec:authorize url="/admin">

This content will only be visible to users who are authorized to access the "/admin" URL.

</sec:authorize>
<div sec:authorize-url="/admin">
    This will only be displayed if authenticated user can call the "/admin" URL.
</div>

您是指包含拦截url模式的请求还是经过ssl身份验证的请求?我是指拦截url模式和安全批注。我想测试我所处的当前请求是否匿名,或者是否已使用配置或使用@secured annotation将其标记为安全的,您可以在何处解决此问题?我也想知道请求URL是否应该受到保护。这是正确的,但它只适用于spring-security.xml中定义的URL模式(不适用于@PreAuthorize注释的控制器方法),正如我不久前注意到的那样。您可以检查一下,当我不使用Spring上下文时,如何获得此WebInvocationPrivilegeEvaluator?
@Autowired
WebInvocationPrivilegeEvaluator webPrivs;

public void useIt() {
    Authentication authentication = SecurityContextHolder.getContext().getAuthentication();

    boolean hasAdminAccess = webPrivs.isAllowed("/admin", authentication);

    boolean hasAdminPostAccess = webPrivs.isAllowed(null, "/admin", "POST", authentication);
}