我希望能更好地控制spring安全的OAuth2中使用的“状态”参数。
DefaultStateKeyGenerator只返回一个随机的6个字符的字符串。
AuthorizationCodeAccessTokenProvider有一个setStateKeyGenerator,但我不确定如何让实例调用setter。
我觉得StateKeyGenerator接受OAuth2ProtectedResourceDetails很奇怪,但是默认的实现会忽略它,并且没有详细说明如何配置您自己的an
~/repos/jtor > mvn dependency:tree | grep security
[INFO] +- org.springframework.security.oauth:spring-security-oauth2:jar:2.0.14.RELEASE:compile
[INFO] | +- org.springframework.security:spring-security-core:jar:4.2.3.RELEASE:compile
[INFO] | +- org.springframework.security:spring-security-config:jar:4.2.3.RELEASE:compile
[INFO] | +- org.springframework.security:spring-security-web:jar:4.2.3.RELEASE:compile
[INFO] +- org.springframework.security:spring-security-jwt:jar:1.0.8.RELEASE:compile
[INFO] \- org.springframework.security:spring-security-test:jar:4.2.3.RELEASE:test发布于 2018-03-12 23:36:19
根据您的使用情况,您可以实现自己的StateKeyGenerator,然后配置bean以使用它。如果resource与您的用例相关,那么您可以自由使用它,但是可以忽略它!
以下是一种可能的配置:
@Bean
public StateKeyGenerator stateKeyGenerator() {
return new CustomStateKeyGenerator();
}
@Bean
public AccessTokenProvider accessTokenProvider() {
AuthorizationCodeAccessTokenProvider accessTokenProvider = new AuthorizationCodeAccessTokenProvider();
accessTokenProvider.setStateKeyGenerator(stateKeyGenerator());
return accessTokenProvider;
}
@Bean
@Scope(value = "session", proxyMode = ScopedProxyMode.INTERFACES)
public OAuth2RestTemplate restTemplate() {
OAuth2RestTemplate restTemplate = new OAuth2RestTemplate(myResource(), new DefaultOAuth2ClientContext(accessTokenRequest));
restTemplate.setAccessTokenProvider(accessTokenProvider());
return restTemplate;
}https://stackoverflow.com/questions/46062208
复制相似问题