Page 1 of 3 123 LastLast
Results 1 to 10 of 23

Thread: twitter has already been registered error.

  1. #1
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default twitter has already been registered error.

    Failed properties: Property 'authenticationServices' threw exception; nested exception is java.lang.IllegalArgumentException: A ConnectionFactory for provider 'twitter' has already been registered

    Not sure why i am getting this. Twitter and Facebook are configured via annotations. This whole configuration is loaded via the ContextLoaderListener, just like the samples project.

    But for some reason it looks like the App context loaded by the DispatcherServlet might be trying to make them too.

    Here is my Java Config class

    Code:
    @Configuration
    @EnableJdbcConnectionRepository
    @EnableTwitter(appId="${twitter.consumerKey}", appSecret = "${twitter.consumerSecret}")
    @EnableFacebook(appId = "${facebook.clientId}", appSecret = "${facebook.clientSecret}")
    public class SocialWebConfig {
    
      @Autowired
      ConnectionFactoryLocator connectionFactoryLocator;
    
      @Autowired
      ConnectionRepository connectionRepository;
    
      @Autowired
      UsersConnectionRepository usersConnectionRepository;
    
      @Autowired
      private UserIdSource userIdSource;
    
      @Bean
      public ConnectController connectController() {
        ConnectController connectController = new ConnectController(connectionFactoryLocator, connectionRepository);
        return connectController;
      }
    
      @Bean
      public ProviderSignInController providerSignInController(RequestCache requestCache) {
        ProviderSignInController controller = new ProviderSignInController(connectionFactoryLocator, usersConnectionRepository, new SpringSecuritySignInAdapter(requestCache));
        controller.setSignUpUrl("/account/signup");
        return controller;
      }
    
      @Bean
      public SocialAuthenticationFilter socialAuthenticationFilter(AuthenticationManager authenticationManager, RememberMeServices rememberMeServices, SocialAuthenticationServiceLocator authenticationServiceLocator) {
        SocialAuthenticationFilter socialAuthenticationFilter = new SocialAuthenticationFilter(authenticationManager, userIdSource, usersConnectionRepository, authenticationServiceLocator);
        socialAuthenticationFilter.setFilterProcessesUrl("/auth");
        socialAuthenticationFilter.setSignupUrl("/account/signup"); // TODO: Fix filter to handle in-app paths
        socialAuthenticationFilter.setRememberMeServices(rememberMeServices);
        return socialAuthenticationFilter;
      }
    
      @Bean
      public AuthenticationProvider socialAuthenticationProvider(UserDetailsService userDetailsService, UsersConnectionRepository usersConnectionRepository) {
        return new SocialAuthenticationProvider(usersConnectionRepository, socialUsersDetailsService(userDetailsService));
      }
    
      @Bean
      public SocialUserDetailsService socialUsersDetailsService(UserDetailsService userDetailsService) {
        return new SimpleSocialUserDetailsService(userDetailsService);
      }
    
      @Bean
      public PasswordEncoder passwordEncoder() {
          return NoOpPasswordEncoder.getInstance();
      }
    
      @Bean
      public TextEncryptor textEncryptor() {
        return Encryptors.noOpText();
      }
    
      @Bean
      public UserIdSource userIdSource() {
        return new AuthenticationNameUserIdSource();
      }
    
    }
    Here is what I have in the applicationContext.xml

    Code:
        <context:property-placeholder location="classpath:META-INF/spring/social.properties"/>
        <context:component-scan base-package="com.hdpoker.social.config"/>
        <import resource="classpath*:META-INF/spring/applicationContext*.xml"/>
        <import resource="applicationContext-security-account.xml"/>
    Here is my spring-security xml file config

    Code:
        <security:global-method-security secured-annotations="enabled"/>
    
    	<!-- HTTP security configurations -->
        <security:http auto-config="true" use-expressions="true">
            <security:form-login login-page="/" authentication-failure-url="/?login_error=1" default-target-url="/index"/>
            <security:intercept-url pattern="/index/**" access="hasRole('Player')"/>
            <security:intercept-url pattern="/account/**" method="POST" access="permitAll"/>
    
            <!-- Configure these elements to secure URIs in your application -->
            <security:intercept-url pattern="/resources/**" access="permitAll"/>
            <security:intercept-url pattern="/auth/**" access="permitAll" />
            <security:intercept-url pattern="/signin/**" access="permitAll" />
            <security:intercept-url pattern="/signup/**" access="permitAll" />
            <security:intercept-url pattern="/" access="permitAll" />
    
            <!--  Spring Social Security authentication filter -->
            <security:custom-filter ref="socialAuthenticationFilter" before="PRE_AUTH_FILTER" />
        </security:http>
    
        <!--Make sure somewhere there is a component-scan to bring in the accountUserDetailsService-->
        <security:authentication-manager alias="authenticationManager">
            <security:authentication-provider user-service-ref="accountUserDetailsService">
                <!--security:password-encoder hash="md5">
                        <security:salt-source system-wide="wysiwyg"/>
                </security:password-encoder-->
            </security:authentication-provider>
            <security:authentication-provider ref="socialAuthenticationProvider"/>
        </security:authentication-manager>
    Any ideas what I am doing wrong.

    Thanks

    Mark

  2. #2
    Join Date
    Aug 2004
    Posts
    1,070

    Default

    Can you confirm which version of Spring Social you are working with? I had this exact same problem at one time (about a week ago), but it turned out to be a copy-n-paste error that has since been fixed.

    For grins, try removing the Facebook provider and see if the error goes away.
    Craig Walls
    Spring Social Project Lead

  3. #3
    Join Date
    Aug 2004
    Posts
    1,070

    Default

    Another thing that might be going on is that you have a @Configuration-annotated class and then you're (probably...I can't tell for sure here) component-scanning the same package that the class is in from your XML. My guess is that SocialWebConfig is being used twice...once because it is annotated with @Configuration and again due to component-scanning.

    If this is the problem (and I can't be certain for lack of visibility into the rest of your code), the fix is to add an exclusion to the <context:component-scan> to not scan for any classes that are annotated with @Configuration. I hope you've also taken care to not have applicationContext.xml anywhere in a page that the import would pick it up again.

    Again...this is just a guess because I can't see enough of your project to give a real diagnosis (and again, it'd be handy if this stuff or a smaller facsimile of it were in GitHub so that I can help with the diagnosis).
    Craig Walls
    Spring Social Project Lead

  4. #4
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    I really wish I could share the code. But we are building a Poker app that will be for actual gambling. I am working for a casino/gaming company in Las Vegas and there are so much legal stuff. So much that I don't know if I was even allowed to tell you what I am working on.

    I do have a component-scan for loading in the @Configuration. So are you saying that a component scan is already occurring automatically without any config to do so?

    I am using the yet to be announced M2 in the SpringSource Milestone repo that you deployed yesterday.

    Mark

  5. #5
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    If I remove the component-scan then it doesn't pick up the Configuration class. So I get noBeanDefined error.

    And here is the component-scan in the xxx-servlet.xml file

    Code:
    <context:component-scan base-package="com.blah.controller" use-default-filters="false">
    	<context:include-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
    </context:component-scan>
    All the other xml files that are brought into via the <import> are for infrastructure database and services/repos stuff. One for Spring Data Neo4j. One for Spring Data JPA.

    Also have
    Code:
        <context:spring-configured/>
    
        <context:component-scan base-package="com.hdpoker" use-default-filters="false">
            <context:include-filter type="annotation" expression="com.blah.annotations.AccountServerApp"/>
            <context:exclude-filter expression="org.springframework.stereotype.Controller" type="annotation"/>
        </context:component-scan>
    Mark
    Last edited by bytor99999; Feb 13th, 2013 at 10:44 AM. Reason: more info

  6. #6
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    I am now going to try using xml instead. I had posted a new thread on that topic, but can't find it. Maybe the same issue I had before with a post where it didn't show up for a day. No biggie.

    Thanks

    Mark

  7. #7
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    OK, now I am back to just configuring Spring Social from @Configuration class. I have two component-scans. One for the middle tier, one for the web tier. Both exclude @Configuration. I have only one @Configuration class and I make it a bean by itself in xml with <bean>

    I even thought maybe Spring Data Neo4j was doing an internal scan that might have picked it up. But I set a base-package in that config too that would not go into the @Configuration classes package.

    I am still getting that duplicate twitter et al.

    Now in trying xml, there was a class in Spring Social Security that got me wondering if two locators were being created. The base one with @EnableTwitter and another in Social Security for SocialAuthenticationServiceLocator. When I was doing xml I would get that as a bean not found. But with @Configuration there isn't any place in the samples that define an @Bean for it, but it seems like that is then created automatically, because I would have a different failure if it wasn't.

    Thanks

    Mark

  8. #8
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    OK. I am now back to being able to deploy my application. I still have some errors, but I got past the already registered provider error.

    And my last post was correct. If you are going to use the Spring Social Security Filter, you cannot also use the @EnableTwitter like annotations because you will end up with two locators. One that @EnableTwitter creates and a SocialAuthenticationServiceLocator which by the way extends ConnectionFactoryRegistry.

    So I removed the @Enable annotations, then for my FactoryRegistry I created an @Bean that returns a SocialAuthenticationServiceLocator. But that caused another error because some beans are looking for a bean named connectionFactoryRegistry. So I just made that the name of my @Bean method ConnectionFactoryRegistry() and now I am deploying.

    Now my current error is now very much in the realm of something that I can resolve because it is a NPE in my UserDetailsService.

    Of course a big contributor to the Spring Social Security, Yuan was where I found the answer on his post

    http://www.jiwhiz.com/post/2013/1/Cu..._For_Mong oDB

    Looking at his @Configuration class

    Thanks

    Mark
    Last edited by bytor99999; Feb 13th, 2013 at 05:41 PM. Reason: more info

  9. #9
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    Interesting. While what I said above is true, in that I couldn't use the @Enable because it created two ServiceLocators. I just noticed in ProviderConfigurationSupport class that it does check first to see if Spring Social Security is there and if so instantiate a SocialAuthenticationServiceLocator instead of ConnectionFactory.

    So maybe there is a way to configure it to make it work, it is just that it is cleaner than it was before, and I think the samples don't reflect the new changes.

    Just a hunch/guess.

    Mark

  10. #10
    Join Date
    Jan 2009
    Location
    Huntington Beach, CA
    Posts
    718

    Default

    Nope. Setting break points in ProviderConfigurationSupport shows that it does see that Spring Social Security is there and returns true. But it is still trying to register Twitter or Facebook twice.

    Well, I can put it back to what I had. I am just not getting redirected to my signup page when there is a UserNotFoundException thrown from my UserDetailsService. Instead it gets a 401.

    Thanks

    Mark

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •