【发布时间】:2020-01-19 19:02:02
【问题描述】:
tl;dr:为什么我的OidcUserService虽然注册了却不是?
我正在尝试使用我自己的OAuth2UserService,方法是按照Spring Security documentation 中的说明进行注册。
但是,当我在 OidcUserService.loadUser(OidcUserRequest)](https://docs.spring.io/spring-security/site/docs/current/api/org/springframework/security/oauth2/client/oidc/userinfo/OidcUserService.html#loadUser-org.springframework.security.oauth2.client.oidc.userinfo.OidcUserRequest-) 方法上设置断点时,它会一直命中 com.okta.spring.boot.oauth.OktaOidcUserService!我是使用com.okta.spring:okta-spring-boot-parent:1.2.2-SNAPSHOT这可能是问题吗?
我注册了我的OidcUserServicelike documented:
@SpringBootApplication
@EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class RedirectCodeFlowApplication {
public static void main(String[] args) {
SpringApplication.run(RedirectCodeFlowApplication.class, args);
}
@Configuration
static class WebConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
final OidcUserService delegate = new OidcUserService();
http.authorizeRequests().anyRequest().authenticated()
.and()
.oauth2Login()
.userInfoEndpoint()
.oidcUserService( (userRequest) -> {
System.out.println( "!!xXx!! never gets here" );
OidcUser oidcUser = delegate.loadUser(userRequest);
OAuth2AccessToken accessToken = userRequest.getAccessToken();
Set<GrantedAuthority> mappedAuthorities = new HashSet<>();
oidcUser = new DefaultOidcUser(mappedAuthorities, oidcUser.getIdToken(), oidcUser.getUserInfo());
return oidcUser;
})
;
}
而且我调用的方法很简单:
@RestController
public class WelcomeController {
@GetMapping("/")
public Welcome getMessageOfTheDay(Principal principal) {
return "The message of the day is boring.";
}
}
【问题讨论】:
标签: spring spring-security okta spring-oauth2