Announcement Announcement Module
Collapse
No announcement yet.
twitter has already been registered error. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    OK. First. It is not a component-scan problem.

    It works when I comment out the @EnableTwitter like annotations.

    The problem that was happening is that @EnableTwitter causes a ConnectionFactoryLocator to be automatically created for you. But since I am using the Security filter I don't want that ConnectionFactoryLocator, I need the SocialAuthenticationServiceLocator instead (It also implements ConnectionFactoryLocator too).

    So what happens when you have @EnableTwitter and the SecurityFilter is that two ConnectFactoryLocators then get created, each with Twitter services added, and that is the problem.

    Mark

    Comment


    • #17
      No, that's not accurate. The configuration code behind @EnableTwitter and @EnableFacebook will detect that Spring Security stuff is being used and create a SocialAuthenticationServiceLocator instead of a plain ConnectionFactoryLocator.

      Here's the snippet that makes that decision in https://github.com/SpringSource/spri...nSupport.java:

      Code:
      protected BeanDefinition registerBeanDefinitions(BeanDefinitionRegistry registry, Map<String, Object> allAttributes) {
      	if (isSocialSecurityAvailable() && authenticationServiceClass != null) {
      		registerAuthenticationServiceBeanDefinitions(registry, allAttributes);						
      	} else {
      		registerConnectionFactoryBeanDefinitions(registry, allAttributes);			
      	}
      
      	return registerApiBindingBean(registry, apiHelperClass, apiBindingType);
      }
      See https://github.com/SpringSource/spri...l-showcase-sec for an example of how this works. (Actually, there's not much to see there, because most of the interesting work happens under the hood of the @Enable[Provider] annotations.)

      I'm honestly puzzled as to how you would get it to try to register two ConnectionFactory or SocialAuthenticationService beans just because you used @Enable[Provider] annotations. I'm doing exactly that in the aforementioned sample and it works perfectly.
      Last edited by habuma; Feb 14th, 2013, 11:06 AM.

      Comment


      • #18
        Yep, exactly, in my previous post I said.

        "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."

        So that code is working as advertised. Let me put some code in there to get the BeanDefinition names from the ApplicationContext and println them out and post them. That will tell us if we get both ConnectionFactoryLocators.

        Thanks

        Mark

        Originally posted by habuma View Post
        No, that's not accurate. The configuration code behind @EnableTwitter and @EnableFacebook will detect that Spring Security stuff is being used and create a SocialAuthenticationServiceLocator instead of a plain ConnectionFactoryLocator.

        Here's the snippet that makes that decision in https://github.com/SpringSource/spri...nSupport.java:

        Code:
        protected BeanDefinition registerBeanDefinitions(BeanDefinitionRegistry registry, Map<String, Object> allAttributes) {
        	if (isSocialSecurityAvailable() && authenticationServiceClass != null) {
        		registerAuthenticationServiceBeanDefinitions(registry, allAttributes);						
        	} else {
        		registerConnectionFactoryBeanDefinitions(registry, allAttributes);			
        	}
        
        	return registerApiBindingBean(registry, apiHelperClass, apiBindingType);
        }
        See https://github.com/SpringSource/spri...l-showcase-sec for an example of how this works. (Actually, there's not much to see there, because most of the interesting work happens under the hood of the @Enable[Provider] annotations.)

        I'm honestly puzzled as to how you would get it to try to register two ConnectionFactory or SocialAuthenticationService beans just because you used @Enable[Provider] annotations. I'm doing exactly that in the aforementioned sample and it works perfectly.

        Comment


        • #19
          Could you also try it with the spring-social-showcase-sec example? Just to (1) prove that it works and (2) to give you some baseline example for how to configure things on your end.

          And yes, I completely understand that you don't want to share your poker site code on GitHub. I wouldn't expect you to do that. But one thing that often helps me with these kinds of problems is to extract them from the main project into a smaller, easier to digest "laboratory" project where I can work out the kinks and then use what I learn to make the real project work. If you were to do that it'd probably help you identify your problem faster and if not, then it'd give you something to share on GitHub that I could help you with.

          Comment


          • #20
            OK. first sorry this is so long.

            Second, I don't see two connectionFactoryLocators. But setting a break point at the line of registerAuthenticationServiceBeanDefinitions call. It stops there twice for each provider. Also, after the four times it got called, it was NOT when the exception would be thrown. That would happen later in the App Context lifecycle.

            I have no idea why this is happening. But I am very sure it isn't because of my <component-scans> All of them have exclude filters on @Configuration. I also have been using user-default-filters="false".

            Part of me thinks that maybe something in Spring Data projects they do a built in component-scan. We are using Spring Data Neo4j and Spring Data JPA. That would be something that is different than the samples.

            Thanks again for all your time.

            Mark

            list of bean definition names.

            [neo4jProperties,
            org.springframework.context.annotation.Configurati onClassPostProcessor#0,
            org.springframework.data.neo4j.config.Neo4jConfigu ration#0,
            graphDatabaseService,
            gameTableRepository,
            accountRepository,
            org.springframework.data.repository.core.support.R epositoryInterfaceAwareBeanPostProcessor#0,
            postgresProperties,
            org.springframework.orm.jpa.support.PersistenceAnn otationBeanPostProcessor#0,
            dataSource,
            entityManagerFactory,
            jpaTransactionManager,
            jpaAdapter,
            accountSecurityRepository,
            currencyRepository,
            org.springframework.data.repository.core.support.R epositoryInterfaceAwareBeanPostProcessor#1,
            org.springframework.dao.annotation.PersistenceExce ptionTranslationPostProcessor#0,
            org.springframework.aop.config.internalAutoProxyCr eator,
            org.springframework.transaction.annotation.Annotat ionTransactionAttributeSource#0,
            org.springframework.transaction.interceptor.Transa ctionInterceptor#0,
            org.springframework.transaction.config.internalTra nsactionAdvisor,
            accountUserDetailsService,
            accountServiceImpl,
            org.springframework.context.annotation.internalCon figurationAnnotationProcessor,
            org.springframework.context.annotation.internalAut owiredAnnotationProcessor,
            org.springframework.context.annotation.internalReq uiredAnnotationProcessor,
            org.springframework.context.annotation.internalCom monAnnotationProcessor,
            org.springframework.context.annotation.internalPer sistenceAnnotationProcessor,
            org.springframework.security.access.method.Delegat ingMethodSecurityMetadataSource#0,
            org.springframework.security.access.vote.Affirmati veBased#0,
            org.springframework.security.access.intercept.aopa lliance.MethodSecurityInterceptor#0,
            org.springframework.security.methodSecurityMetadat aSourceAdvisor,
            org.springframework.security.filterChains,
            org.springframework.security.filterChainProxy,
            org.springframework.security.web.PortMapperImpl#0,
            org.springframework.security.web.PortResolverImpl# 0,
            org.springframework.security.config.authentication .AuthenticationManagerFactoryBean#0,
            org.springframework.security.authentication.Provid erManager#0,
            org.springframework.security.web.context.HttpSessi onSecurityContextRepository#0,
            org.springframework.security.web.authentication.se ssion.SessionFixationProtectionStrategy#0,
            org.springframework.security.web.savedrequest.Http SessionRequestCache#0,
            org.springframework.security.web.access.expression .DefaultWebSecurityExpressionHandler#0,
            org.springframework.security.access.vote.Affirmati veBased#1,
            org.springframework.security.web.access.intercept. FilterSecurityInterceptor#0,
            org.springframework.security.web.access.DefaultWeb InvocationPrivilegeEvaluator#0,
            org.springframework.security.authentication.Anonym ousAuthenticationProvider#0,
            org.springframework.security.web.authentication.re memberme.TokenBasedRememberMeServices#0,
            org.springframework.security.authentication.Rememb erMeAuthenticationProvider#0,
            org.springframework.security.web.authentication.www.BasicAuthenticationEntryPoint#0,
            org.springframework.security.web.authentication.Us ernamePasswordAuthenticationFilter#0,
            org.springframework.security.userDetailsServiceFac tory,
            org.springframework.security.web.DefaultSecurityFi lterChain#0,
            org.springframework.security.authentication.dao.Da oAuthenticationProvider#0,
            org.springframework.security.authentication.Defaul tAuthenticationEventPublisher#0,
            org.springframework.security.authenticationManager ,
            socialProperties,
            com.blah.social.config.SocialConfig#0,
            org.springframework.context.annotation.Configurati onClassPostProcessor.importAwareProcessor,
            scopedTarget.usersConnectionRepository,
            usersConnectionRepository,
            __userIdString,
            scopedTarget.connectionRepository,
            connectionRepository,
            scopedTarget.connectionFactoryLocator,
            connectionFactoryLocator,
            __twitterApiHelper,
            scopedTarget.twitter,
            twitter,
            __facebookApiHelper,
            scopedTarget.facebook,
            facebook,
            neo4jTemplate,
            neo4jMappingContext,
            mappingInfrastructure,
            relationshipTypeRepresentationStrategy,
            nodeTypeRepresentationStrategy,
            typeRepresentationStrategyFactory,
            entityStateHandler,
            nodeTypeMapper,
            relationshipTypeMapper,
            entityFetchHandler,
            nodeStateTransmitter,
            neo4jConversionService,
            graphRelationshipInstantiator,
            graphEntityInstantiator,
            entityAlias,
            relationshipEntityStateFactory,
            nodeEntityStateFactory,
            nodeDelegatingFieldAccessorFactory,
            relationshipDelegatingFieldAccessorFactory,
            neo4jTransactionManager,
            indexCreationMappingEventListener,
            graphDatabase,
            configurationCheck,
            persistenceExceptionTranslator,
            indexProvider,
            providerSignInController,
            socialAuthenticationFilter,
            socialAuthenticationProvider,
            socialUsersDetailsService,
            socialAuthenticationEntryPoint,
            passwordEncoder,
            textEncryptor,
            userIdSource]
            Last edited by bytor99999; Feb 14th, 2013, 11:41 AM. Reason: list of names

            Comment


            • #21
              Well, I can explain quickly why it stops there 4 times and complains later: That's because the configuration code doesn't create the actual beans in the context...it creates bean definitions. Later the container uses those bean definitions to create the actual beans and that's when you get the exception.

              As for explaining why you get the complaint at all...I'm not there yet. I see nothing obvious out of sorts in your bean listing, though.

              Comment


              • #22
                So, therefore it would create BeanDefinitions twice for the same "bean" but it will have the same bean name, so therefore in the Map, one would overwrite the other in the Map. Then after the BeanFactoryPostProcessors, during Instantiation and BeanPostProcessors, they would only instantiate and create a single instance, not dups.

                Also, the samples do not run on my machine. Running mvn tomcat:run or even just mvn package I get lots of errors.

                Here is a sample of those errors

                Code:
                [ERROR] class ExplicitSocialConfig
                [ERROR] /Users/bytor99999/Java/GitHubRepos/spring-social-samples/spring-social-showcase-sec/src/main/java/org/springframework/social/showcase/config/SocialConfig.java:[82,13] error: cannot find symbol
                [ERROR] class SocialConfig
                [ERROR] /Users/bytor99999/Java/GitHubRepos/spring-social-samples/spring-social-showcase-sec/src/main/java/org/springframework/social/showcase/linkedin/LinkedInProfileController.java:[38,13] error: cannot find symbol
                [ERROR] class LinkedInProfileController
                [ERROR] /Users/bytor99999/Java/GitHubRepos/spring-social-samples/spring-social-showcase-sec/src/main/java/org/springframework/social/showcase/linkedin/LinkedInProfileController.java:[38,79] error: cannot find symbol
                I can run the quickstart sample.

                Actually, sorry I know why they won't run. It is because they are pointing to BUILD-SNAPSHOT, not M2. Which means we can't access them through our Nexus artifactory. I will edit the poms to point to M2 and try again.

                Thanks

                Mark

                Comment


                • #23
                  Hmm. the pom files are pointing to M2 and not SNAPSHOT. Strange, it should work.

                  Mark

                  Comment

                  Working...
                  X