I use Spring Social 1.0.3 to add "Sign In with Facebook" and "Sign In with Twitter" on my login page. Here my login view page :
login view :
<form action="<c:url value="/connect/twitter" />" method="POST">
<p><button type="submit"><img src="<c:url value="/resources/images/social/twitter/sign-in-with-twitter-d.png" />"/>
</button></p>
</form>
<form action="<c:url value="/connect/facebook" />" method="POST">
<p><button type="submit"><img src="<c:url value="/resources/images/social/facebook/sign-in-with-facebook.png" />"/>
</button></p>
</form>
Spring social xml configuration:
<context:property-placeholder location="classpath:application.properties" />
<bean id="connectionFactoryLocator"
class="org.springframework.social.connect.support.ConnectionFactoryRegistry">
<property name="connectionFactories">
<list>
<bean class="org.springframework.social.twitter.connect.TwitterConnectionFactory">
<constructor-arg value="${twitter.consumerKey}" />
<constructor-arg value="${twitter.consumerSecret}" />
</bean>
<bean class="org.springframework.social.facebook.connect.FacebookConnectionFactory">
<constructor-arg value="${facebook.clientId}" />
<constructor-arg value="${facebook.clientSecret}" />
</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="connectionRepository" factory-method="createConnectionRepository"
factory-bean="usersConnectionRepository" scope="request">
<constructor-arg value="#{request.userPrincipal.name}" />
<aop:scoped-proxy proxy-target-class="false" />
</bean>
<bean id="textEncryptor" class="org.springframework.security.crypto.encrypt.Encryptors"
factory-method="noOpText">
</bean>
<bean class="org.springframework.social.connect.web.ConnectController">
<!-- relies on by-type autowiring for the constructor-args -->
<property name="applicationUrl" value="${application.url}" />
</bean>
</beans>
application properties file:
#Facebook
facebook.clientId=ideletetherealvalue
facebook.clientSecret=ideletetherealvalue
#Twitter
twitter.consumerKey=ideletetherealvalue
twitter.consumerSecret=ideletetherealvalue
application.url=http://localhost:8080/myapp
The url application http://localhost:8080/myapp
is authorized in facebook application.
When i click on "Sign In with Twitter" or "Sign In with Facebook", i am redirect to Twitter or Facebook to submit my login and password.
1.Twitter when i submit my credentials then another page ask me to allow the application
I allow the application and then i get the following error :
DEBUG [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] [] http-bio-8080-exec-10 Resolving exception from handler [public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(java.lang.String,org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model)]: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'name' cannot be found on null
DEBUG [org.springframework.web.servlet.DispatcherServlet] [] http-bio-8080-exec-10 Could not complete request
org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'name' cannot be found on null
The complete error is here http://pastebin.com/hyRicyFu
2.Facebook when i submit my credentials then i get the following error:
org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'name' cannot be found on null
DEBUG [org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] [] http-bio-8080-exec-2 Resolving exception from handler [public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(java.lang.String,org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model)]: org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'name' cannot be found on null
DEBUG [org.springframework.web.servlet.DispatcherServlet] [] http-bio-8080-exec-2 Could not complete request
org.springframework.beans.factory.BeanExpressionException: Expression parsing failed; nested exception is org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Field or property 'name' cannot be found on null
The complete error is here http://pastebin.com/hyRicyFu
Questions:
According to what i understand this error comes from
<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>
error message : Field or property 'name' cannot be found on null
I need some confirmation :
a- Have i to create in database a user when the user submit ? Which controller i have to extend ? If someone has an example it will help
b- If i am wrong, what's happening , why i am getting the error ?