1
我試圖執行本教程https://spring.io/guides/tutorials/spring-boot-oauth2/#_social_login_logout 這是我的應用程序配置(春季啓動)如何將Facebook認證的用戶存儲在數據庫中?
@Configuration
@ComponentScan(basePackages = {"org.fiodorov.controller","org.fiodorov.service", "org.fiodorov.config"})
@EntityScan(basePackages = "org.fiodorov.model")
@EnableJpaRepositories(basePackages = "org.fiodorov.repository")
@EnableOAuth2Client
@EnableAutoConfiguration
public class Application extends WebSecurityConfigurerAdapter{
@Autowired
OAuth2ClientContext oauth2ClientContext;
@Override
protected void configure(HttpSecurity http) throws Exception {
http.antMatcher("/**")
.addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
}
public static void main(String[] args) {
SpringApplication.run(
Application.class, args);
}
private Filter ssoFilter() {
OAuth2ClientAuthenticationProcessingFilter facebookFilter = new OAuth2ClientAuthenticationProcessingFilter("/login/facebook");
OAuth2RestTemplate facebookTemplate = new OAuth2RestTemplate(facebook(), oauth2ClientContext);
facebookFilter.setRestTemplate(facebookTemplate);
facebookFilter.setTokenServices(new UserInfoTokenServices(facebookResource().getUserInfoUri(), facebook().getClientId()));
return facebookFilter;
}
@Bean
@ConfigurationProperties("facebook.client")
OAuth2ProtectedResourceDetails facebook() {
return new AuthorizationCodeResourceDetails();
}
@Bean
@ConfigurationProperties("facebook.resource")
ResourceServerProperties facebookResource() {
return new ResourceServerProperties();
}
@Bean
public FilterRegistrationBean oauth2ClientFilterRegistration(
OAuth2ClientContextFilter filter) {
FilterRegistrationBean registration = new FilterRegistrationBean();
registration.setFilter(filter);
registration.setOrder(-100);
return registration;
}
}
和它的作品。我可以登錄並獲取用戶信息,如教程中所述。但我不知道如何才能在登錄之後以及在重定向到主頁面之前找到那一刻,以便在用戶不存在的情況下將用戶詳細信息存儲在數據庫中,並在存在的情況下驗證其角色。
我該怎麼做?