Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc spring security oauth2禁用基于jsessionid的会话_Spring Mvc_Spring Security_Spring Security Oauth2 - Fatal编程技术网

Spring mvc spring security oauth2禁用基于jsessionid的会话

Spring mvc spring security oauth2禁用基于jsessionid的会话,spring-mvc,spring-security,spring-security-oauth2,Spring Mvc,Spring Security,Spring Security Oauth2,我没有评论的名声,否则这描述了完全相同的问题 我已经在Spring4应用程序中成功地实现了SpringSecurityOAuth2.0.5。所有的工作都很好,我可以生成令牌,并且api请求经过正确的身份验证。但问题是,一旦在基于浏览器的应用程序中使用访问令牌对api进行了身份验证,后续调用就不需要访问令牌,因为 -spring安全性似乎依赖sessionid来识别和验证用户。 -即使在访问令牌过期之后,调用也似乎有效 因此,spring似乎只在第一次调用中依赖访问令牌,然后依赖cookie/js

我没有评论的名声,否则这描述了完全相同的问题

我已经在Spring4应用程序中成功地实现了SpringSecurityOAuth2.0.5。所有的工作都很好,我可以生成令牌,并且api请求经过正确的身份验证。但问题是,一旦在基于浏览器的应用程序中使用访问令牌对api进行了身份验证,后续调用就不需要访问令牌,因为 -spring安全性似乎依赖sessionid来识别和验证用户。 -即使在访问令牌过期之后,调用也似乎有效

因此,spring似乎只在第一次调用中依赖访问令牌,然后依赖cookie/jsessionid。我试图通过以下方式禁用该行为(从Sparkr2学习)-

但这没有帮助。在日志中我可以看到-

正在尝试使用Ant[pattern='/oauth/token']进行匹配检查 请求:'/v1.0/printconfig/';针对试图匹配的“/oauth/token” 使用Ant[pattern='/oauth/token_key']检查请求的匹配: “/v1.0/printconfig/”;针对“/oauth/token\u key”尝试使用 Ant[pattern='/oauth/check_token']检查请求的匹配: “/v1.0/printconfig/”;对“/oauth/check_token”未找到匹配项 正在尝试使用Ant[pattern='/v1.0/']进行匹配检查 请求:'/v1.0/printconfig/';与“/v1.0/”匹配 /v1.0/printconfig/位于附加过滤器链中10个位置中的第1个位置; 正在启动筛选器:“WebAsyncManagerIntegrationFilter”/v1.0/printconfig/ 在附加过滤器链的位置2/10处触发过滤器: “SecurityContextPersistenceFilter”获取了有效的SecurityContext 从SPRING_SECURITY_上下文: 'org.springframework.security.core.context。SecurityContextImpl@bd392350: 身份验证: org.springframework.security.oauth2.provider。OAuth2Authentication@bd392350: 负责人:org.springframework.security.core.userdetails。User@6d: 用户名:m;密码:[受保护];启用:真;AccountNoExpired: 是的;无需证明的凭证:真实;AccountNonLocked:true;授予 权限:角色\用户;凭据:[受保护];认证:正确; 详细信息:remoteAddress=0:0:0:0:0:0:1,tokenValue=;授予 权限:角色_USER'/v1.0/printconfig/位于 附加过滤链;正在启动筛选器:“HeaderWriterFilter”未启动 注入HSTS标头,因为它与请求匹配程序不匹配 org.springframework.security.web.header.writers.HstsHeaderWriter$SecureRequestMatcher@6044b89b /v1.0/printconfig/位于附加过滤器链中10个位置中的第4个位置; 正在启动筛选器:“LogoutFilter”检查请求的匹配: “/v1.0/printconfig/”;针对“/logout”/v1.0/printconfig/at位置 附加过滤器链中的10个过滤器中的5个;点火过滤器: >在标头中未找到“OAuth2AuthenticationProcessingFilter”标记。 正在尝试请求参数。在请求参数中找不到令牌。不 OAuth2请求。请求中没有令牌,将继续链。 /v1.0/printconfig/位于附加过滤器链中10个位置中的第6个位置; 正在启动筛选器:“RequestCacheAwarRefilter”/v1.0/printconfig/at 附加过滤器链中的位置7/10;点火过滤器: “SecurityContextHolderAwareRequestFilter”/v1.0/printconfig/at 附加过滤器链中的位置8/10;点火过滤器: “SessionManagementFilter”/v1.0/printconfig/位于 附加过滤链;正在启动筛选器:“ExceptionTranslationFilter” /v1.0/printconfig/位于附加过滤器链中10个位置中的第10个位置; 正在启动筛选器:“FilterSecurityInterceptor”检查请求的匹配: “/v1.0/printconfig/”;针对“/v1.0/**”安全对象: 过滤器职业:URL:/v1.0/printconfig/;属性: [#oauth2.throwOnError(hasRole('ROLE_USER'))]以前经过身份验证: org.springframework.security.oauth2.provider。OAuth2Authentication@bd392350: 负责人:org.springframework.security.core.userdetails。User@6d: 用户名:m;密码:[受保护];启用:真;AccountNoExpired: 是的;无需证明的凭证:真实;AccountNonLocked:true;授予 权限:角色\用户;凭据:[受保护];认证:正确; 详细信息:remoteAddress=0:0:0:0:0:0:1,tokenValue=;授予 权限:角色\用户投票人: org.springframework.security.web.access.expression。WebExpressionVoter@5f574bdc, 返回:1授权成功运行管理器未更改 身份验证对象/v1.0/printconfig/已到达附加 过滤链;正常处理原链条 请求处理完成后,SecurityContextHolder现在已清除


正如您所看到的,oauth令牌头不存在,但仍然有一个不同的筛选器标识了会话。我很想禁用sessionId本身,但是只禁用spring对用户本身的身份验证就可以了。我希望访问令牌是传入请求的唯一标识符。

在我看来,
/v1.0/printconfig/
OAuth2AuthenticationProcessingFilter
后面的受OAuth2保护的资源,您的客户端发送了cookie而不是令牌?如果这是正确的,那么2.0.5中的默认行为如您所见(接受cookie,并允许您在自己的配置中控制访问规则)。默认值在2.0.6中更改(除非明确配置了资源服务器,否则cookie将无法工作:)。

Dave,根据您的项目,我正在使用facebook登录oauth2。为什么facebook登录设置cookie,我可以通过任何方式更改它以提供访问令牌。仅供参考,我有自己的spring oauth服务器。我不太明白这个问题。当你通过Facebook认证时,你会得到一个cookie。相当标准的东西,而不是你有任何影响力的东西。上面的教程链接中有一个auth server示例。也许这就是你所说的“提供访问令牌”的意思?我正在创建rest服务,我的整个系统
Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.anonymous().disable();
        //oauth2 recommends that oauth token url should be only available to authorized clients
        http.requestMatchers().antMatchers("/oauth/token").and().authorizeRequests().anyRequest().fullyAuthenticated();
        http.httpBasic().authenticationEntryPoint(oAuth2AuthenticationEntryPoint()).and()
                .addFilterBefore(clientCredentialsTokenEndpointFilter(), BasicAuthenticationFilter.class)
                .sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS).and().exceptionHandling()
                .accessDeniedHandler(oAuth2AccessDeniedHandler);

    }