Spring Social After succesfull login redirect problem

60 views Asked by At

I configured my spring boot application for social login with this documentation. Application started and I have logined with my gmail account. There is no problem thus far. But when I login with a gmail account my app is not getting user infos. Here is my social config.

autoSignup is true

@Configuration
@EnableSocial
@PropertySource("classpath:social-config.properties")
public class BlogSiteSocialConfig implements SocialConfigurer{

@Autowired
private DataSource dataSource;

@Autowired
private Environment env;

@Autowired
private IKullaniciDao kullaniciDao;

private boolean autoSignUp = false;

@Override
public void addConnectionFactories(ConnectionFactoryConfigurer connectionFactoryConfigurer,
        Environment environment) {
     try {
        this.autoSignUp = Boolean.parseBoolean(env.getProperty("social.auto-signup"));
    } catch (Exception e) {
        this.autoSignUp = false;
    }

     GoogleConnectionFactory googleFactory = new GoogleConnectionFactory(
                env.getProperty("google.client.id"), 
                env.getProperty("google.client.secret"));
     googleFactory.setScope(env.getProperty("google.scope"));

     connectionFactoryConfigurer.addConnectionFactory(googleFactory);

}

@Override
public UserIdSource getUserIdSource() {
     return new AuthenticationNameUserIdSource();
}

@Override
public UsersConnectionRepository getUsersConnectionRepository(ConnectionFactoryLocator connectionFactoryLocator) {
    JdbcUsersConnectionRepository usersConnectionRepository = new JdbcUsersConnectionRepository(dataSource,
            connectionFactoryLocator,Encryptors.noOpText());

    if (autoSignUp) {
        // After logging in to social networking.
        // Automatically creates corresponding APP_USER if it does not exist.
        ConnectionSignUp connectionSignUp = new ConnectionSignUpImpl(kullaniciDao);
        usersConnectionRepository.setConnectionSignUp(connectionSignUp);
    } else {
        // After logging in to social networking.
        // If the corresponding APP_USER record is not found.
        // Navigate to registration page.
        usersConnectionRepository.setConnectionSignUp(null);
    }
    return usersConnectionRepository;
}

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

Also my security config is here;

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)

public class BlogSiteSecurityConfig extends WebSecurityConfigurerAdapter{

@Autowired
private UserDetailsService userDetailsService;

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userDetailsService);
}

@Override
protected void configure(HttpSecurity http) throws Exception {

    http.csrf().disable();

    // Pages do not require login
    http.authorizeRequests().antMatchers(
            "/css/**","/js/**","/fonts/**","/images/**", 
            "/anasayfa","/yazidetay","/index","/","/hakkimda","/api/kullanici/kaydet",
            "/500","/404","/exceptions/**","/yazilar/getir","/signup"
            ).permitAll();



    // For ADMIN only.
    http.authorizeRequests().antMatchers("/admin/**").access("hasRole('ADMIN')");

    // When the user has logged in as XX.
    // But access a page that requires role YY,
    // AccessDeniedException will be thrown.
    http.authorizeRequests().and().exceptionHandling().accessDeniedPage("/403");

    // Form Login config
    http.authorizeRequests().and().formLogin()//
            // Submit URL of login page.
            .loginProcessingUrl("/j_spring_security_check") // Submit URL
            .loginPage("/login")//
            .defaultSuccessUrl("/anasayfa")//
            .failureUrl("/login?error=true")//
            .usernameParameter("username")//
            .passwordParameter("password");

    // Logout Config
    http.authorizeRequests().and().logout().logoutUrl("/logout").logoutSuccessUrl("/anasayfa");

    // Spring Social Config.
    http.apply(new SpringSocialConfigurer())
            .signupUrl("/signup");

}

// This bean is load the user specific data when form login is used.
@Override
public UserDetailsService userDetailsService() {
    return userDetailsService;
}

@Bean
public PasswordEncoder passwordEncoder() {
    return new BCryptPasswordEncoder();
}

Why app is not getting user info after login with social account?

0

There are 0 answers