Quantcast
Channel: Spring Community Forums - Social
Viewing all articles
Browse latest Browse all 145

Spring social with spring security annotation config No authentication provider found

$
0
0
Hi,
I have a multi module maven project. I am using java annotation config on this application. I have integrated the spring security annotation config spring-social example into my application. Unfortunately, I couldn't get it to work properly. Here is the error I'm getting when I try to login with my Facebook login.

Quote:

Authentication Failed: No AuthenticationProvider found for org.springframework.social.security.SocialAuthenti cationToken
Everything seems in place, normal spring security filters work.

Code:

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .authorizeUrls()
                .antMatchers("/resources/**","/auth/**","/signup/**","/disconnect/facebook").permitAll()
                .anyRequest().authenticated()
                .and()
            .addFilterBefore(socialAuthenticationFilter, AbstractPreAuthenticatedProcessingFilter.class)
            .logout()
                .deleteCookies("JSESSIONID")
                .logoutUrl("/signout")
                .permitAll()
                .and()
            .formLogin()
                .loginPage("/signin")
                .loginProcessingUrl("/signin/authenticate")
                .failureUrl("/signin?param.error=bad_credentials")
                .permitAll();
    }

SocialSecurityConfig is same from Spring-security annotation configuration examples
Code:

@Configuration
public class SocialSecurityConfig {

    @Inject
    private Environment environment;

    @Inject
    private UsersConnectionRepository usersConnectionRepository;

    @Bean
    public SocialAuthenticationFilter socialAuthenticationFilter(AuthenticationManager authenticationManager, SocialAuthenticationServiceLocator authenticationServiceLocator) {
        SocialAuthenticationFilter socialAuthenticationFilter = new SocialAuthenticationFilter(authenticationManager, userIdSource(), usersConnectionRepository, authenticationServiceLocator);
        socialAuthenticationFilter.setSignupUrl("/redrum-web/signup"); // TODO: Fix filter to handle in-app paths
// FIXME add remember me        socialAuthenticationFilter.setRememberMeServices(rememberMeServices);
        return socialAuthenticationFilter;
    }

    @Bean
    public SocialAuthenticationProvider socialAuthenticationProvider(UserDetailsService userDetailsService) {
        return new SocialAuthenticationProvider(usersConnectionRepository, socialUsersDetailsService(userDetailsService));
    }

    @Bean
    public SocialUserDetailsService socialUsersDetailsService(UserDetailsService userDetailsService) {
        return new SimpleSocialUsersDetailService(userDetailsService);
    }

    @Bean
    public UserIdSource userIdSource() {
        return new AuthenticationUserIdExtractor();
    }
       
}

And SocialConfig class... I'm using my own consumer keys and secrets...
Code:

@Configuration
//@Profile("simple")
@EnableJdbcConnectionRepository
@EnableTwitter(appId="${twitter.consumerKey}", appSecret="${twitter.consumerSecret}")
@EnableFacebook(appId="${facebook.clientId}", appSecret="${facebook.clientSecret}")
//@EnableLinkedIn(appId="${linkedin.consumerKey}", appSecret="${linkedin.consumerSecret}")
public class SocialConfig {

        @Inject
        private Environment environment;
       
        @Inject
        private ConnectionFactoryLocator connectionFactoryLocator;
       
        @Inject
        private ConnectionRepository connectionRepository;

        @Inject
        private UsersConnectionRepository usersConnectionRepository;

        @Bean
        public ConnectController connectController() {
                ConnectController connectController = new ConnectController(connectionFactoryLocator, connectionRepository);
//                connectController.addInterceptor(new PostToWallAfterConnectInterceptor());
//                connectController.addInterceptor(new TweetAfterConnectInterceptor());
                return connectController;
        }
       
        @Bean
        public DisconnectController disconnectController() {
                return new DisconnectController(usersConnectionRepository, environment.getProperty("facebook.clientSecret"));
        }
       
        @Bean
        public UserIdSource userIdSource() {
                return new AuthenticationNameUserIdSource();
        }

}

I see below log entry, but I have the failure URL set in the security config

Quote:

21:47:23.550 [http-bio-8080-exec-9] DEBUG o.s.s.s.SocialAuthenticationFilter - Authentication request failed: org.springframework.security.authentication.Provid erNotFoundException: No AuthenticationProvider found for org.springframework.social.security.SocialAuthenti cationToken
21:47:23.550 [http-bio-8080-exec-9] DEBUG o.s.s.s.SocialAuthenticationFilter - Updated SecurityContextHolder to contain null Authentication
21:47:23.550 [http-bio-8080-exec-9] DEBUG o.s.s.s.SocialAuthenticationFilter - Delegating to authentication failure handler org.springframework.social.security.SocialAuthenti cationFailureHandler@49aa5056
21:47:23.550 [http-bio-8080-exec-9] DEBUG o.s.s.w.a.SimpleUrlAuthenticationFailureHandler - No failure URL set, sending 401 Unauthorized error
21:47:23.550 [http-bio-8080-exec-9] DEBUG o.s.s.w.c.HttpSessionSecurityContextRepository - SecurityContext is empty or contents are anonymous - context will not be stored in HttpSession.
21:47:23.550 [http-bio-8080-exec-9] DEBUG o.s.s.w.c.SecurityContextPersistenceFilter - SecurityContextHolder now cleared, as request processing completed

Viewing all articles
Browse latest Browse all 145

Trending Articles