Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring social NoSuchMethodError SocialAuthenticationFilter.getFilterProcessesUrl()

I use spring security login. Now I'm trying to add spring social facebook login, but I get many error information.

First, when I try to use the same method like spring social guide, I can't @Autowired private Facebook facebook

I found a solution

@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.INTERFACES)
public Facebook facebook(ConnectionRepository repository) {
    Connection<Facebook> connection = repository
            .findPrimaryConnection(Facebook.class);
    return connection != null ? connection.getApi() : null;
}

Next, I get the error "cannot find bean". I have to add:

 @Bean
 public ConnectionRepository connectionRepository() {
 Authentication authentication = SecurityContextHolder.getContext()
 .getAuthentication();
 if (authentication == null) {
 throw new IllegalStateException(
 "Unable to get a ConnectionRepository: no user signed in");
 }
 return usersConnectionRepository().createConnectionRepository(
 authentication.getName());
 }

@Bean
public ConnectionFactoryLocator connectionFactoryLocator() {
    ConnectionFactoryRegistry registry = new ConnectionFactoryRegistry();

     registry.addConnectionFactory(new FacebookConnectionFactory(facebookid,
                facebookSecure));

    return registry;
}

@Bean
public AuthenticationNameUserIdSource authenticationNameUserIdSource(){
    return new  AuthenticationNameUserIdSource();
}


@Bean
public ConnectController connectController(
        ConnectionFactoryLocator connectionFactoryLocator,
        ConnectionRepository connectionRepository) {
    return new ConnectController(connectionFactoryLocator,
            connectionRepository);
}

@Bean
public UsersConnectionRepository usersConnectionRepository() {
    return new JdbcUsersConnectionRepository(dataSource,
            connectionFactoryLocator(), Encryptors.noOpText());
}

After that, I have other issue java.lang.NoSuchMethodError: org.springframework.social.security.SocialAuthenticationFilter.getFilterProcessesUrl()Ljava/lang/String;

@Bean
  public SocialAuthenticationServiceLocator socialAuthenticationServiceLocator() {
    SocialAuthenticationServiceRegistry registry = new SocialAuthenticationServiceRegistry();
    registry.addConnectionFactory(new FacebookConnectionFactory(facebookid,
            facebookSecure));
    return registry;
}

     @Bean
 public SocialAuthenticationFilter socialAuthenticationFilter()
 throws Exception {
 SocialAuthenticationFilter filter = new SocialAuthenticationFilter(
 authenticationManager(), authenticationNameUserIdSource(),
 usersConnectionRepository(), socialAuthenticationServiceLocator());
 filter.setFilterProcessesUrl("/login");
 filter.setSignupUrl("/signup");
 filter.setConnectionAddedRedirectUrl("/home");
 filter.setPostLoginUrl("/home"); // always open account profile
 // page after login
 // filter.setRememberMeServices(rememberMeServices());
 return filter;
 }

but always is the same.

This is my http configuration

        http.csrf()
            .disable()
            .authorizeRequests()
            .antMatchers("/home", "/css/**", "/**/*.css*", "/", "/signup",
                    "/facebook", "/signup.xhtml").permitAll().anyRequest()
               .authenticated().and().formLogin().loginPage("/login").loginProcessingUrl("/login/authenticate")
            .defaultSuccessUrl("/home").failureUrl("/login")

            .permitAll().and().logout().logoutUrl("/logout")
            .invalidateHttpSession(true).logoutSuccessUrl("/").and()
            .apply(new SpringSocialConfigurer());

And controller

@RequestMapping(value = "/login", method = RequestMethod.GET)
 public String loginPage() {
 return "redirect:/login/authenticate/connect/facebook";

 }

I did a whole tutorial. Next, I removed SocialConfigurer implementation and created the same (not @Override, only @Bean) social documentation.

'Normal login '(spring security) works fine, but I can't configure spring social with spring security. I use JSF and .XHTML files.

Maybe someone knows where I make the mistakes?

Thanks for your help.

like image 575
luprogrammer Avatar asked May 08 '26 10:05

luprogrammer


2 Answers

It looks like Spring Security removed getFilterProcessesUrl() in Spring Security 4.0.0.RC1 (it was marked as deprecated anyways).

It seems that other project filters have not been updated?

Try rolling back to 4.0.0.M2 or use the 3.2 train.

like image 71
Jaymes Bearden Avatar answered May 09 '26 22:05

Jaymes Bearden


Please notice that spring security 4 will not accept spring social 1.1.0. Please upgrade all spring social dependencies(config, core, security and web) to 1.1.2.RELEASE. You can leave your spring social Facebook to 1.1.0

like image 26
bogdan.rusu Avatar answered May 09 '26 23:05

bogdan.rusu



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!