java - Spring 社交 NoSuchMethodError SocialAuthenticationFilter.getFilterProcessesUrl()

标签 java spring-mvc spring-security spring-social spring-social-facebook

我使用 spring 安全登录。现在我正在尝试添加 spring social facebook 登录,但是我得到很多错误信息。

首先,当我尝试使用与 spring social guide 相同的方法时, 我不能 @Autowired private Facebook facebook

我找到了解决方案

@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;
}

接下来,我收到错误“找不到 bean”。我必须添加:

 @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());
}

在那之后,我有其他问题 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;
 }

但总是一样的。

这是我的http配置

        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());

和 Controller

@RequestMapping(value = "/login", method = RequestMethod.GET)
 public String loginPage() {
 return "redirect:/login/authenticate/connect/facebook";

 }

我做了一个整体tutorial .接下来,我删除了 SocialConfigurer 实现并创建了相同的实现(不是 @Override,只有 @Bean)social documentation .

“正常登录”(spring security)工作正常,但我无法使用 spring security 配置 spring social。我使用 JSF.XHTML 文件。

也许有人知道我在哪里犯了错误?

感谢您的帮助。

最佳答案

看起来 Spring Security 在 Spring Security 4.0.0.RC1 中删除了 getFilterProcessesUrl() (它被标记为已弃用)。

其他项目过滤器好像没有更新?

尝试回滚到 4.0.0.M2 或使用 3.2 序列。

关于java - Spring 社交 NoSuchMethodError SocialAuthenticationFilter.getFilterProcessesUrl(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28070088/

相关文章:

java - SimpleXML 构造函数异常 - 无法创建内部类

java - 如何使用Spring Security同时保护2条路径?

java - org.springframework.beans.factory.BeanCreationException : Injection of autowired dependencies failed;

java - 发布后 Spring Security Access 被拒绝 403

java 创建我的应用程序可以识别的自定义文件扩展名

java - 如何删除 Wicket 网页中的后缀

java - 如何让 Spring Security 将 HTTP session 存储在数据库中以在多个服务器上使用 Web 应用程序?

java - wicket-auth-roles 和 spring-security-cas-client 之间的身份验证集成问题

java - 向 Spring 应用程序添加另一个上下文

java - 在应用程序中验证 Aadhar 卡号