【问题标题】:Spring social NoSuchMethodError SocialAuthenticationFilter.getFilterProcessesUrl()Spring social NoSuchMethodError SocialAuthenticationFilter.getFilterProcessesUrl()
【发布时间】:2015-03-20 03:24:17
【问题描述】:

我使用弹簧安全登录。现在我正在尝试添加 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());

和控制器

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

 }

我做了一个完整的tutorial。接下来,我删除了SocialConfigurer 实现并创建了相同的(不是@Override,只有@Beansocial documentation

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

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

感谢您的帮助。

【问题讨论】:

  • 可能是版本冲突。您使用的是哪个版本?
  • facebook 社交我使用&lt;version&gt;1.1.1.RELEASE&lt;/version&gt; 但在应用中我使用@EnableAutoConfiguration 也许这是一个问题

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


【解决方案1】:

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

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

尝试回滚到 4.0.0.M2 或使用 3.2 火车。

【讨论】:

    【解决方案2】:

    请注意,spring security 4 将不接受 spring social 1.1.0。请将所有 Spring 社交依赖项(配置、核心、安全和 Web)升级到 1.1.2.RELEASE。您可以将您的春季社交 Facebook 保留到 1.1.0

    【讨论】:

      【解决方案3】:

      正如我在评论中所暗示的,您的某些库版本错误。我的聪明猜测是 Spring Security 的版本是错误的。据我所知,您应该使用 Spring Security 的 3.2.x 系列(例如 3.2.5)中的版本。

      【讨论】:

      • @luprogrammer Spring Security 的错误版本,你看到了吗?将4.0.0.CI-SNAPSHOT 更改为3.2.5
      • 当我更改为 4.0.0.RC1 时,我遇到了同样的问题,但现在我使用 @EnableSocial 之后我可以重定向到 facebook 登录,但现在我有其他问题 [anonymusUser] (@987654321 @)
      • @luprogrammer 除非您有特殊原因,否则您不应使用除RELEASE 版本之外的任何内容。
      • 当我更改为4.0.0.M2 => NoClassDefFoundError: org/springframework/core/annotation/OrderProvider 但我有spring-security-corespring-core
      • @luprogrammer Mx = 里程碑,RC = 候选发布,这些是开发版本,不打算包含在常规项目中!
      【解决方案4】:

      考虑使用 1.1.4 版本。

      这在 spring-social-security 1.1.4.RELEASE(或者之前的某个版本)中得到了解决。

      https://github.com/spring-projects/spring-social

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-04-01
        • 1970-01-01
        • 2015-11-03
        • 2011-12-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多