Spring Social После успешной проблемы с перенаправлением входа в систему - PullRequest
1 голос
/ 07 апреля 2020

Я настроил свое весеннее загрузочное приложение для входа в социальную сеть с помощью этой документации. Приложение запущено, и я вошел в свою учетную запись gmail. Пока проблем нет. Но когда я захожу с учетной записью Gmail, мое приложение не получает пользовательскую информацию. Вот моя социальная конфигурация.

autoSignup 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);
}

Также моя конфигурация безопасности здесь;

@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)

publi c Класс BlogSiteSecurityConfig расширяет 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();
}

Почему приложение не получает информацию о пользователе после входа в систему с социальной учетной записью?

...