Announcement Announcement Module
Collapse
No announcement yet.
Unable to set connectionSignup with social:jdbc-connection-repository Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to set connectionSignup with social:jdbc-connection-repository

    Hello,
    I'm trying to use Implicit sign up as defined on the manual at page:
    http://static.springsource.org/sprin...ml/signin.html

    but I'm unable to do it using the examples provided in the showcase where the jdbc connection repository is defined as:
    <social:jdbc-connection-repository/>

    I could define it not using the social namespace, this way:
    <bean id="connectionRepository" class="org.springframework.social.connect.jdbc.Jdb cUsersConnectionRepository"
    p:connectionSignUp-ref="signInAdapter">
    <aop:scoped-proxy proxy-target-class="false"/>
    <constructor-arg ref="dataSource"/>
    <constructor-arg ref="connectionFactoryLocator"/>
    <constructor-arg ref="textEncryptor"/>
    </bean>

    but in this case the configuration does not work any more because Spring tells me that the connectController is unable to find a bean of class org.springframework.social.connect.ConnectionRepos itory.

    So I'm stuck if I don't want to use JavaConfig (and I don't want to).

    Any help would be very, very appreciated!

  • #2
    Which version of Spring Social are you using?

    The samples are updated to reflect the latest 1.1.0.M2 releases, but the manual has not yet been updated (primarily because I want to shake out any issues before I document them).

    The way you configured the JdbcUsersConnectionRepository looks *mostly* correct, but it's not enough. There are two kinds of connection repositories: The UsersConnectionRepository and the ConnectionRepository. You've configured the first kind, but ConnectController wants the 2nd kind. Actually, you need to configure both:

    Code:
    <bean id="usersConnectionRepository" class="org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository">
    	<constructor-arg ref="dataSource" />
    	<constructor-arg ref="connectionFactoryLocator" />
    	<constructor-arg ref="textEncryptor" />
    	<aop:scoped-proxy proxy-target-class="false" />
    </bean>
    
    <bean id="connectionRepository" factory-method="createConnectionRepository" factory-bean="usersConnectionRepository" scope="request">
    	<constructor-arg value="#{request.userPrincipal.name}" />
    	<aop:scoped-proxy proxy-target-class="false" />
    </bean>
    (Note: Depending on your security mechanism, you might need to tweak the SpEL expression that fetches the username.)

    If it helps, think of the UsersConnectionRepository as a "ConnectionRepository factory". It's a bit more than that, but that's one of its primary jobs--to create a connection repository for the current user. It's that 2nd bean that ConnectController wants, but you need the first one to create it for you.

    I acknowledge that this can be confusing. From a design standpoint it makes sense. But from a configuration standpoint it's a bit awkward. That's why Spring Social 1.1.0.M1 introduced the new configuration namespace (and JavaConfig annotations) to free you from having to deal with those beans directly. But if you're still on 1.0.x, then you must do it the hard way.

    I also should warn you that if you are doing it the hard way on 1.0.x, that the XML configuration is a bit trickier. The JavaConfig is easier for 1.0.2. I wonder why you are hesitant to use JavaConfig...even if just for those two beans and use XML for the rest of your app?

    Comment


    • #3
      Hello Craig for your response, much appreciated.
      I somewhat understood I had to create both beans but I had no clue to how create the one named connectionRepository and I certainly would not be able to deduce the runtime expression for his constructor.

      The main question still holds, though: wouldn't be better to provide some parameter to the social:jdbc-connection-repository element to avoid to create by hand those two beans?

      I'm using spring-social 1.1.0.M2.

      Thanks!

      Comment


      • #4
        Yes, I agree that a connection-signup-ref attribute on social:jdbc-connection-repository would be very handy. In fact, barring any surprises, you should see that in a snapshot build later today.

        Comment

        Working...
        X