Announcement Announcement Module
Collapse
No announcement yet.
Understanding Spring Social framework Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Understanding Spring Social framework

    Hello guys i try to integrate social in my application. I read reference manual but i do not understand some things there. So i try to signin via Facebook using implementing of SignInAdapter and with signInController. SignInController redirect me to facebook and there i authorize than it go to my redirect URL with error = provider. It is not possible to debug this and to see where is problem. When in conncetionRepository i change constructor arguments to #{request.getParametr('username')} it hangs and for many times connect to facebook and it happense nothing. if i use static parametr there something like "qwerty" it will show me error=provider. here is my config and can you tell what is #{request.getPrincipal.username}. What sould be there in request params?
    Why my signInController do not redirect me to signUp page?>

    Here is my configs:
    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    
    <beans xmlns="http://www.springframework.org/schema/beans"
    	xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    	xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
    	xsi:schemaLocation="
            http://www.springframework.org/schema/beans
            http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
            http://www.springframework.org/schema/aop 
            http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"
    	default-lazy-init="true">
    
    	<bean id="connectionFactoryLocator"
    		class="org.springframework.social.connect.support.ConnectionFactoryRegistry">
    		<property name="connectionFactories">
    			<list>
    				<bean
    					class="org.springframework.social.facebook.connect.FacebookConnectionFactory">
    					<constructor-arg value="${facebook.appId}" />
    					<constructor-arg value="${facebook.appSecret}" />
    				</bean>
    			</list>
    		</property>
    	</bean>
    
    	<bean id="usersConnectionRepository"
    		class="org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository">
    		<constructor-arg ref="dataSource" />
    		<constructor-arg ref="connectionFactoryLocator" />
    		<constructor-arg ref="textEncryptor" />
    	</bean>
    
    	<bean id="dataSource"
    		class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    		<property name="driverClassName" value="com.mysql.jdbc.Driver" />
    		<property name="url" value="jdbc:mysql://localhost:3306/shop" />
    		<property name="username" value="root" />
    		<property name="password" value="root" />
    	</bean>
    
    	<bean id="connectionRepository" factory-method="createConnectionRepository"
    		factory-bean="usersConnectionRepository" scope="request">
    		<constructor-arg value="#{request.getParameter('username')}" />
    <!-- 		<constructor-arg value="igor" /> -->
    		<aop:scoped-proxy proxy-target-class="false" />
    	</bean>
    
    	<bean class="org.springframework.social.connect.web.ProviderSignInController">
    		<constructor-arg ref="connectionFactoryLocator"/>
    		<constructor-arg ref="connectionRepository" />
    		<constructor-arg ref="simpleSignInAdapter" />
    		<property name="applicationUrl" value="${application.url}" />
    		<property name="signUpUrl" value="/signup" />
    	</bean>
    	<bean id="simpleSignInAdapter" class="com.social.SimpleSignInAdapter" />
    
    
    	<bean class="org.springframework.social.connect.web.ConnectController">
    		<constructor-arg ref="connectionFactoryLocator" />
    		<constructor-arg ref="connectionRepository" />
    		<property name="applicationUrl" value="${application.url}" />
    	</bean>
    
    	<bean id="textEncryptor" class="org.springframework.security.crypto.encrypt.Encryptors"
    		factory-method="noOpText" />
    </beans>

    p.s. I want to build my application like spring social showcase to (merge) to combine my server user account with facebook userAcc.
    p.p.s Sorry for my English....
    Last edited by DanteAlighieri; Jun 25th, 2012, 06:37 AM. Reason: Forget to paste code

  • #2
    I don't see anything obvious that's out of place, so I have to ask about the non-obvious:
    - I'm assuming that you've registered your app with Facebook and have received an app ID and secret...and that those are in a properties file and being plugged in via the placeholders in the FacebookConnectionFactory bean?
    - The value given in the constructor-arg for the connection factory should be a value that uniquely identifies the current user. If it's #{request.getParameter('username')}, then it is a Spring Expression Language (SpEL) expression that will evaluate to the "username" query parameter on the request; which is odd...probably not what you want it to do because there's probably *not* a username parameter on the callback. You can plug in anything you want here, but it should identify the user. "#{request.userPrincipal.name}" is probably a better choice, but it still depends on the user principal being set...are you using Spring Security for general security of your application in the same was as the showcase?
    - You say "for many times connect to facebook and it happense nothing". I'm not sure what you mean here, but perhaps what you're saying is that it redirects to FB for authorization, but then immediately comes back without presenting the authorization page. If that's what is happening, then it's probably because the authorization from once before is still good and so FB immediately redirects back. That's expected. To force it to show an authorization page, you should go into the user's FB account and revoke authorization for your app.
    - Are there any stack traces giving any clues as to what/where things go wrong?

    Comment


    • #3
      Sorry for such question, i do not create table connections in my DB . Now it work properly. And I start to integrate it in my existing login system... As i see here Spring Forum. When i register user with facebook account i should use postSignUtil to create userconnection in DB table, then when user press signIn_button he/she will be redirected to signInAdapter which takes some parametrs from userconnection table. Then what should i place in security context? Should I compare params that were passed to signUpAdapter and to search user with such params in my user table and then put to Security context this user.

      Yeah i understand this. SignInController check access_Token? And when token's are equ it goes to signIn else it goes tosignUp?
      Last edited by DanteAlighieri; Jun 26th, 2012, 12:36 PM. Reason: Grammar

      Comment


      • #4
        can u share the total code for spring with facebook integration

        can u share the total code for spring with facebook integration







        Originally posted by DanteAlighieri View Post
        Sorry for such question, i do not create table connections in my DB . Now it work properly. And I start to integrate it in my existing login system... As i see here Spring Forum. When i register user with facebook account i should use postSignUtil to create userconnection in DB table, then when user press signIn_button he/she will be redirected to signInAdapter which takes some parametrs from userconnection table. Then what should i place in security context? Should I compare params that were passed to signUpAdapter and to search user with such params in my user table and then put to Security context this user.

        Yeah i understand this. SignInController check access_Token? And when token's are equ it goes to signIn else it goes tosignUp?

        Comment

        Working...
        X