Как войти в систему с помощью Facebook и обычным способом входа с весенней загрузкой? - PullRequest
0 голосов
/ 01 мая 2020

Я создаю приложение, которое позволяет пользователям входить в систему через Facebook, если запрашиваемый путь равен http://localhost: 8080 / facebook , и входить обычным способом, если запрашиваемый путь равен http://localhost : 8080 / user

, поэтому я смог войти в систему с помощью facebook, если я заменил аннотацию @EnableWebSecurity на @ EnableOAuth2Sso в SecurityConfiguration. java class.

Я попытался создать другой Security класс конфигурации для Facebook, но все еще не работает.

SecurityConfigFacebook. java class

@EnableWebSecurity
@EnableOAuth2Sso
@EnableGlobalMethodSecurity(prePostEnabled = true)
@Order(2)
@Configuration
public class SecurityConfigFacebook extends WebSecurityConfigurerAdapter {

    @Autowired
    UserDetailsService userDetailsService;

    // gives authentication
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService);
    }

    // give and prevent permissions for users
    @Override
    protected void configure(HttpSecurity http) throws Exception {
          http
            .csrf().disable()
            .authorizeRequests()
            .antMatchers("/signin/**","/signup/**", "/facebook").hasRole("USER")
            .anyRequest().authenticated()
            .and()
            .formLogin()
            .and()
            .logout();
    }
}

SecurityConfiguration. java class


@EnableWebSecurity
@Order(1)
@Configuration
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Autowired
    UserDetailsService userDetailsService;

    // gives authentication
    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.userDetailsService(userDetailsService);
    }

    // give and prevent permissions for users

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests().antMatchers("/admin").hasRole("ADMIN").antMatchers("/user").hasAnyRole("ADMIN", "USER")
                .antMatchers("/").permitAll().antMatchers(HttpMethod.POST, "/registration").permitAll()
                .antMatchers(HttpMethod.POST, "/**").hasRole("USER").antMatchers(HttpMethod.PUT, "/**").hasRole("USER")
                .antMatchers(HttpMethod.DELETE, "/**").hasRole("USER")

                .and().cors().and().csrf().disable().formLogin();
    }

    // encode password to not store it as a plain text (more secure)
    @Bean
    public PasswordEncoder getPasswordEncoder() {
        return new BCryptPasswordEncoder();
    }

}
...