3

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.

Mario Cervera
  • 671
  • 1
  • 8
  • 19
luprogrammer
  • 155
  • 1
  • 3
  • 12

4 Answers4

1

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.

Jaymes Bearden
  • 2,009
  • 2
  • 21
  • 24
1

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

bogdan.rusu
  • 901
  • 4
  • 21
  • 41
0

As hinted in my comment, you have the wrong version of some library. My intelligent guess is that version of Spring Security is wrong. From what I can find, you should use a version in the 3.2.x series (for example 3.2.5) of Spring Security.

holmis83
  • 15,922
  • 5
  • 82
  • 83
  • @luprogrammer Wrong version of Spring Security, you see? Change `4.0.0.CI-SNAPSHOT` to `3.2.5`. – holmis83 Jan 24 '15 at 19:40
  • When I change to `4.0.0.RC1` I have the same issue, but now I'm using `@EnableSocial` after that I can redirect to facebook login but now I have other problem [anonymusUser] (http://stackoverflow.com/questions/28236063/spring-social-facebook-login-inserts-anonymoususer-in-database/28245733#28245733) – luprogrammer Jan 31 '15 at 18:19
  • @luprogrammer Unless you have a special reason, you should not use anything but `RELEASE` versions. – holmis83 Jan 31 '15 at 19:35
  • When I change to `4.0.0.M2` => `NoClassDefFoundError: org/springframework/core/annotation/OrderProvider` but I Have `spring-security-core` and `spring-core` – luprogrammer Jan 31 '15 at 20:20
  • @luprogrammer `Mx` = milestone, `RC` = release candidate, these are development versions and not intended to be included in regular projects! – holmis83 Jan 31 '15 at 20:41
  • I heard about I musn't combain Spring framework 4 with spring security 3.x – luprogrammer Jan 31 '15 at 21:33
  • I change to spring security 3.2.5 I have to add more another dependencys but after change I can,t compile project `IllegalStateException: SpringSocialConfigurer depends on org.springframework.social.security.SocialUserDetailsService. No single bean of that type found in application context`I implements this service only [once] (http://paste.ofcode.org/9HGDZN3FBuqchSEQsff8V4) this problem is when I use `httpConfigure... .and().apply(new SpringSocialConfigurer())` [pom.xml] (http://paste.ofcode.org/LAUjhVmkXgNkDr2Cz7ZzE) – luprogrammer Jan 31 '15 at 23:27
0

Consider using version 1.1.4.

this is solved in spring-social-security 1.1.4.RELEASE (or perhaps some version before).

https://github.com/spring-projects/spring-social