gpt4 book ai didi

java - AuthenticationSuccessEvent 从未触发

转载 作者:行者123 更新时间:2023-12-02 03:38:45 24 4
gpt4 key购买 nike

我编写用户使用 Facebook 登录的应用程序。

我的安全配置/应用程序类:

@SpringBootApplication
@EnableOAuth2Sso
@ComponentScan(basePackages = { "app" })
public class Application extends WebSecurityConfigurerAdapter {

@SuppressWarnings("SpringJavaAutowiringInspection")
@Autowired
private OAuth2ClientContext oauth2ClientContext;

@Override
protected void configure(HttpSecurity http) throws Exception {
http
.antMatcher("/**")
.authorizeRequests()
.antMatchers("/",
"/login**",
"/webjars/**",
"/bower_components/**",
"/assets/**",
"/app/**",
"/api/auth/isAuthenticated")
.permitAll()
.anyRequest()
.authenticated()
.and().formLogin().defaultSuccessUrl("/", true).loginPage("/login").permitAll()
.and().logout().logoutSuccessUrl("/").permitAll()
.and().addFilterBefore(ssoFilter(), BasicAuthenticationFilter.class);
}

@Bean
@ConfigurationProperties("facebook")
ClientResources facebook() {
return new ClientResources();
}

private Filter ssoFilter() {
CompositeFilter filter = new CompositeFilter();
List<Filter> filters = new ArrayList<>();
filters.add(ssoFilter(facebook(), "/login/facebook"));
filter.setFilters(filters);
return filter;
}

private Filter ssoFilter(ClientResources client, String path) {
OAuth2ClientAuthenticationProcessingFilter filter = new OAuth2ClientAuthenticationProcessingFilter(path);
OAuth2RestTemplate facebookTemplate = new OAuth2RestTemplate(client.getClient(), oauth2ClientContext);
filter.setRestTemplate(facebookTemplate);
filter.setTokenServices(new UserInfoTokenServices(client.getResource().getUserInfoUri(), client.getClient().getClientId()));
return filter;
}

class ClientResources {
private OAuth2ProtectedResourceDetails client = new AuthorizationCodeResourceDetails();
private ResourceServerProperties resource = new ResourceServerProperties();

public OAuth2ProtectedResourceDetails getClient() {
return client;
}

public ResourceServerProperties getResource() {
return resource;
}
}

我的问题是,即使我配置了监听器:

package app;
@Component
public class AuthenticationListener implements ApplicationListener<AuthenticationSuccessEvent> {

@Override
public void onApplicationEvent(AuthenticationSuccessEvent event) {
System.out.println("Event fired");
}
}

它永远不会被解雇。我尝试了这里提供的解决方案:Spring boot OAuth successful login listener not triggering但这也无济于事。 SecurityContextHolder.getContext().getAuthentication().isAuthenticated() 登录后返回 true。

最佳答案

OAuth SSO 支持不触发 AuthenticationSuccessEvent的确。这也是我最近面临的事情。这个is implemented now但尚未发布。

关于java - AuthenticationSuccessEvent 从未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37105555/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com