在我的应用程序中,我实现了spring-security-oauth2。除了一种情况外,一切都运行得很好。
场景是,我登录到系统,我会看到oauth2 access_token。我通过提供令牌来请求我的受保护资源,我就会得到结果。我再一次做了同样的请求,没有任何头(没有access_token),这一次我也得到了受保护的资源。
我的受保护资源相关代码:
<http pattern="/**" create-session="never"
entry-point-ref="oauthAuthenticationEntryPoint"
xmlns="http://www.springframework.org/schema/security">
<anonymous enabled="true" />
<intercept-url pattern="/users" access="IS_AUTHENTICATED_ANONYMOUSLY"/>
<intercept-url pattern="/**" access="IS_AUTHENTICATED_FULLY" />
<custom-filter ref="customFilter" position="FORM_LOGIN_FILTER"/>
<custom-filter ref="resourceServerFilter" before="PRE_AUTH_FILTER" />
<access-denied-handler ref="oauthAccessDeniedHandler" />
</http>此外,我还使用了客户过滤器。我使用如下身份验证对象在我的过滤器中打印client_id -
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
System.out.println("----------->>>" + ((OAuth2Authentication) authentication).getAuthorizationRequest().getClientId());使用access_token,我得到客户端id-“test1”,在第一次请求之后,如果我在没有access_token的情况下做同样的请求,我会再次得到相同的client_id="test1“
并且资源也被访问。
我很努力地尝试了,但没有在代码中找到任何漏洞。任何帮助都将不胜感激。
发布于 2015-07-30 00:40:56
这对我很有效:
将create-session = "never"更改为create-session = "stateless"
希望这能有所帮助。
https://stackoverflow.com/questions/30889450
复制相似问题