Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.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 security 如何覆盖Spring引导默认OAuthTokenEndpoint_Spring Security_Spring Boot_Spring Security Oauth2 - Fatal编程技术网

Spring security 如何覆盖Spring引导默认OAuthTokenEndpoint

Spring security 如何覆盖Spring引导默认OAuthTokenEndpoint,spring-security,spring-boot,spring-security-oauth2,Spring Security,Spring Boot,Spring Security Oauth2,我一直在使用SpringSecurityOAuth保护Restful服务。我一直在绞尽脑汁试图使用SSL保护/oauth/token端点,并且只允许POST调用 我正在使用@EnableAuthorizationServer,它声明 用于启用授权服务器(即 当前应用程序中的AuthorizationEndpoint和TokenEndpoint) 上下文,它必须是DispatcherServlet上下文。的许多特点 可以使用类型为的@Beans自定义服务器 授权服务器配置器(例如,通过扩展 授权服

我一直在使用SpringSecurityOAuth保护Restful服务。我一直在绞尽脑汁试图使用SSL保护/oauth/token端点,并且只允许POST调用

我正在使用@EnableAuthorizationServer,它声明

用于启用授权服务器(即 当前应用程序中的AuthorizationEndpoint和TokenEndpoint) 上下文,它必须是DispatcherServlet上下文。的许多特点 可以使用类型为的@Beans自定义服务器 授权服务器配置器(例如,通过扩展 授权服务器配置RADAPTER)。用户负责 使用普通方法保护授权端点(/oauth/authorize) Spring安全功能(@EnableWebSecurity等),但令牌 端点(/oauth/token)将使用HTTP Basic自动保护 对客户端凭据进行身份验证。客户必须注册 通过一个或多个客户端提供ClientDetails服务 授权服务器配置程序

这很好,但我似乎无法覆盖令牌端点部分或强制POST-only调用,就像使用intercept url xml语法一样

@配置
@EnableAuthorizationServer
受保护的静态类AuthorizationServerConfiguration扩展AuthorizationServerConfigurerAdapter{
@豆子
公共令牌库令牌库(){
返回新的InMemoryTokenStore()
}
@自动连线
AuthenticationManager AuthenticationManager
@凌驾
公共无效配置(授权服务器端点配置器端点){
端点
.tokenStore(tokenStore())
.authenticationManager(authenticationManager);
}
@凌驾
公共无效配置(ClientDetailsServiceConfigurer客户端)引发异常{
客户
.inMemory()
.withClient(“testApp”)
.作用域(“读”、“写”)
.当局(“角色\客户”)
.authorizedGrantTypes(“密码”、“刷新令牌”)
.secret(“secret”)
.accessTokenValiditySeconds(7200)
}
}
我用安全软件保护了我的资源服务器

@配置
@EnableResourceServer
受保护的静态类ResourceServerConfiguration扩展了ResourceServerConfigurerAdapter{
@自动连线
私有重新身份验证入口点身份验证入口点;
@凌驾
public void configure(HttpSecurity http)引发异常{
http
.例外处理()
.authenticationEntryPoint(authenticationEntryPoint)
.及()
.requiresChannel().anyRequest().RequiresCure())
.及()
.csrf()
.requireCsrfProtectionMatcher(新的AntPathRequestMatcher(“/oauth/authorize”))
.disable()
.headers()
.frameOptions().disable()
.会议管理()
.sessionCreationPolicy(sessionCreationPolicy.STATELESS)
.及()
.授权请求()
.antMatchers(“/api/**”).authenticated()
}
}

对于使用RequireChannel的授权服务器令牌端点安全性,是否有类似的生成器语法?

我最终使用
org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerSecurityConfiguration

因为我使用的是Spring boot,所以我只是自动连接了SecurityProperty,并为Oauth端点上的SSL添加了这一行

if(this.security.isRequireSsl()){
http.requireChannel().anyRequest().requirescure();
}
以及职位要求

http .授权请求() .antMatchers(HttpMethod.POST,tokenEndpointPath).fullyaAuthenticated() .antMatchers(HttpMethod.GET,tokenEndpointPath).denyAll()

之后删除了@EnableAuthorizationServer,以便使用我的配置。

POST only是默认设置(从2.0.7开始)。我打开了另一个关于安全通道的问题: