Java Spring Social/Twitter——ConnectController不';你没有回复/连接吗?
好吧,我已经花了好长时间(至少看起来是这样!)试图弄清楚我做错了什么:我有一个Java项目,我想让登录的用户(通过正常的Spring Security JDBC启用的存储库)向我的应用程序授予访问他们Twitter帐户的权限。我已经在Twitter等网站上注册了一个应用程序,并拥有密码和访问密钥以及测试所需的所有其他内容,然而,尽管docco的所有读取和所有配置都尝试过,即使我的spring配置创建了一个Java Spring Social/Twitter——ConnectController不';你没有回复/连接吗?,java,spring,spring-mvc,twitter,spring-social,Java,Spring,Spring Mvc,Twitter,Spring Social,好吧,我已经花了好长时间(至少看起来是这样!)试图弄清楚我做错了什么:我有一个Java项目,我想让登录的用户(通过正常的Spring Security JDBC启用的存储库)向我的应用程序授予访问他们Twitter帐户的权限。我已经在Twitter等网站上注册了一个应用程序,并拥有密码和访问密钥以及测试所需的所有其他内容,然而,尽管docco的所有读取和所有配置都尝试过,即使我的spring配置创建了一个连接控制器,只要我点击/connect/Twitter,我就会得到一个404(未找到)尽管在
连接控制器
,只要我点击/connect/Twitter
,我就会得到一个404(未找到)尽管在Tomcat中出现的上下文中绝对没有生成错误,其他一切都可以正常工作(即我的所有bean都被实例化,所有视图/控制器都可以工作等等)
据我所知——尽管我确实在与Spring Social docco抗争,但由于所示的一些示例仅适用于特定版本,因此情况更为严重简单地实例化这个控制器就可以解决其余的问题——但也许我错了
我的配置是这样的——是的,到处都是:
/WEB-INF/WEB.xml
传说
传说
org.springframework.web.servlet.DispatcherServlet
1.
传说
/
违约
*.txt
违约
*.ico
违约
/静止的/*
org.springframework.web.context.ContextLoaderListener
上下文配置位置
/WEB-INF/applicationContext.xml,
/WEB-INF/spring-security.xml
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
/WEB-INF/legototies servlet.xml
/WEB-INF/tiles.xml
/WEB-INF/applicationContext.xml
classpath*:config/*.properties
类路径:hibernate.cfg.xml
/WEB-INF/spring security.xml
这里不包括/WEB-INF/tiles.xml,因为我认为它不相关——它只定义了一些基本模板
最后,这是项目pom.xml——请注意,我使用的是最新的spring社交里程碑(M4):
4.0.0
利维乌图多尔
传说
战争
1.0.0-SNAPSHOT
传说
2013
这是“乐高玩具”
http://legototies.com
利维乌都铎
利维特
我在liviutudor.com
假的
中心的
Maven存储库交换机
http://repo1.maven.org/maven2
春季快照
春季快照
http://repo.spring.io/snapshot
真的
春季里程碑
春季里程碑
http://repo.spring.io/milestone
假的
1.6
UTF-8
3.6.10.最终版本
1.7.2
4.10
3.2.3.1发布
1.1.0.M4
3.1.4.1发布
2.2.2
javax.servlet
servlet api
2.5
假如
javax.servlet
jstl
1.2
org.springframework
弹簧芯
${spring.version}
org.springframework
春季aop
${spring.version}
公用记录
公用记录
org.springframework
SpringJDBC
${spring.version}
org.springframework
春季甲虫
${spring.version}
org.springframework
弹簧网
${spring.version}
org.springframework
SpringWebMVC
${spring.version}
公用记录
公用记录
org.springframework
spring上下文
${spring.version}
org.springframework.security
spring安全内核
${spring.security.version}
org.springframework.security
spring安全网
${spring.security.version}
org.springframework.security
spring安全配置
${spring.security.version}
org.springframework.security
spring安全标记库
${spring.security.version}
org.springframework.securi
5148 [main] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[POST],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.connect(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
5148 [main] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnections(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
5148 [main] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}/{providerUserId}],methods=[DELETE],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.removeConnection(java.lang.String,java.lang.String,org.springframework.web.context.request.NativeWebRequest)
5149 [main] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(java.lang.String,org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model)
5150 [main] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect],methods=[GET],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public java.lang.String org.springframework.social.connect.web.ConnectController.connectionStatus(org.springframework.web.context.request.NativeWebRequest,org.springframework.ui.Model)
5150 [main] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[oauth_token],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth1Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
5151 [main] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[code],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2Callback(java.lang.String,org.springframework.web.context.request.NativeWebRequest)
5152 [main] INFO org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/connect/{providerId}],methods=[GET],params=[error],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.oauth2ErrorCallback(java.lang.String,java.lang.String,java.lang.String,java.lang.String,org.springframework.web.context.request.NativeWebRequest)
<context:component-scan base-package="com.lt">
<context:exclude-filter type="annotation" value="org.springframework.stereotype.Controller" />
</context:component-scan>
<context:component-scan base-package="com.lt" use-default-filters="false">
<context:include-filter type="annotation" value="org.springframework.stereotype.Controller" />
</context:component-scan>
@Controller
public class CustomConnectController extends ConnectController {
@Inject
public CustomConnectController(
ConnectionFactoryLocator connectionFactoryLocator,
ConnectionRepository connectionRepository) {
super(connectionFactoryLocator, connectionRepository);
}
//This connectedView will be called after user authorize twitter app. So here you can redirect
//users to the page you need.
@Override
protected String connectedView(String providerId){
return "redirect:/user/profile";
}
//This connectView will be called if user disconnect from social media. Here you can redirect
//them once they got disconnected.
@Override
protected String connectView(String providerId) {
return "redirect:/connect";
}
}
<filter>
<filter-name>springSecurityFilterChain</filter-name>
<filter-class>
org.springframework.web.filter.DelegatingFilterProxy
</filter-class>
</filter>
<filter-mapping>
<filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.UrlBasedViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.tiles2.TilesView" />
</bean>
<servlet>
<servlet-name>appServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/appServlet-context.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<bean id="connectionFactoryLocator"
class="org.springframework.social.connect.support.ConnectionFactoryRegistry">
<property name="connectionFactories">
<list>
<ref bean="twitterConnectFactory" />
</list>
</property>
</bean>
<bean id="twitterConnectFactory" class="org.springframework.social.twitter.connect.TwitterConnectionFactory">
<constructor-arg value="${twitter.app.consumer.key}" />
<constructor-arg value="${twitter.app.consumer.secret}" />
</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="connectController"
class="org.springframework.social.connect.web.ConnectController">
<constructor-arg ref="connectionFactoryLocator" />
<constructor-arg ref="connectionRepository" />
<property name="connectInterceptors">
<list>
<bean class="com.lt.utils.TweetAfterConnectInterceptor">
<constructor-arg index="0" value="${twitter.app.connect.msg}" />
</bean>
</list>
</property>
</bean>
<beans:beans xmlns="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<global-method-security secured-annotations="enabled" />
<http auto-config="true" use-expressions="true">
<intercept-url pattern="/in/**" access="hasRole('ROLE_USER')" />
<intercept-url pattern="/connect" access="hasRole('ROLE_USER')" />
<intercept-url pattern="/connect/**" access="hasRole('ROLE_USER')" />
<intercept-url pattern="/*" access="permitAll" />
<intercept-url pattern="/static/**" access="permitAll" />
<intercept-url pattern="/login" access="permitAll" />
<intercept-url pattern="/loginfailed" access="permitAll" />
<form-login login-page="/login" default-target-url="/" authentication-failure-url="/loginfailed" />
<logout logout-success-url="/logout" />
</http>
<authentication-manager>
<authentication-provider>
<jdbc-user-service data-source-ref="dataSource"
users-by-username-query="select username,password, enabled from users where username=?"
authorities-by-username-query="select u.username, ur.authority from users u, user_roles ur
where u.id = ur.user_id and u.username =?" />
</authentication-provider>
</authentication-manager>
</beans:beans>