Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/346.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/13.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
Java Spring security Oauth 2在/Oauth/token上的重定向行为_Java_Spring_Spring Mvc_Oauth - Fatal编程技术网

Java Spring security Oauth 2在/Oauth/token上的重定向行为

Java Spring security Oauth 2在/Oauth/token上的重定向行为,java,spring,spring-mvc,oauth,Java,Spring,Spring Mvc,Oauth,我正在开发一个Spring Boot应用程序,我遇到的问题如下: 默认情况下,对我的控制器的每个请求都被重定向到/login,因此我不能这样使用它 我可以通过设置禁用/登录 security.oauth2.resource.filter-order = 3 在application.properties中 但我想知道如何仅对非浏览器禁用它,因此我仍然可以使用登录 编辑: 这就是我的方法: http.antMatcher("/api/**") .author

我正在开发一个Spring Boot应用程序,我遇到的问题如下:

默认情况下,对我的控制器的每个请求都被重定向到/login,因此我不能这样使用它

我可以通过设置禁用/登录

security.oauth2.resource.filter-order = 3
在application.properties中

但我想知道如何仅对非浏览器禁用它,因此我仍然可以使用登录

编辑:

这就是我的方法:

   http.antMatcher("/api/**")
                .authorizeRequests().anyRequest().authenticated();

        http.antMatcher("/**")
                .formLogin();
从/api/运行的所有内容都是REST,应该仅由Oauth处理。 其余的应该通过登录来处理

但它仍然不工作,我仍然得到重定向

没关系,修好了。谢谢你的长号码

在我的例子中,我的Web安全性被错误配置了。 现在可以这样做了:

@Override
protected void configure(HttpSecurity http) throws Exception {
    http.
            formLogin().permitAll()
            .and()
            .authorizeRequests().anyRequest().authenticated();
}
我的RessourceServerConfig如下所示:

@Override
public void configure(HttpSecurity http) throws Exception {

        http
                .exceptionHandling()
                .authenticationEntryPoint(customAuthenticationEntryPoint)
                .and()
                .logout()
                .logoutUrl("/oauth/logout")
                .logoutSuccessHandler(customLogoutSuccessHandler)
                .and()
                .headers()
                .frameOptions().disable()
                .and()
                .sessionManagement()
                .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
                .and()
                .authorizeRequests()
                .antMatchers("/api/**").authenticated();

    }

}

您需要降低主应用程序安全筛选器的优先级

如Spring引导教程中所述

@EnableResourceServer注释创建了一个安全过滤器,默认情况下,过滤器的顺序为@OrderSecurityProperties.ACCESS\u OVERRIDE\u-ORDER-1,因此通过将主应用程序安全性移动到@OrderSecurityProperties.ACCESS\u OVERRIDE\u-ORDER,我们可以确保OAuth资源的规则优先

背景

security.oauth2.resource.filter-order=3

不禁用主安全筛选器。它只是将优先级更改为较低的值。负值具有最高优先级-3的优先级高于3

据我所知,您的问题是没有在ResourceServerConfiguration中正确设置matcher。具体如下

http.antMatcher("/helloOAuth")
            .authorizeRequests().anyRequest().authenticated();
有一个示例实现。可能会有帮助