【发布时间】:2013-04-01 21:48:34
【问题描述】:
我想使用 Spring Security 将 Spring Social facebook 集成到我的应用程序中(我使用 xml 配置)。我所需要的只是将 facebook 帐户与我的应用程序帐户连接起来。在简单的例子中,我发现了这个:
<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>
所以,据我了解,这种方法开始发挥作用:
public ConnectionRepository createConnectionRepository(String userId) {
if (userId == null) {
throw new IllegalArgumentException("userId cannot be null");
}
return new JdbcConnectionRepository(userId, jdbcTemplate, connectionFactoryLocator, textEncryptor, tablePrefix);
}
它从#{request.userPrincipal.name} 中提取“userId”。所以,我的问题:我怎样才能通过“userId”
如果我想使用SecurityContextHolder.getContext().getAuthentication().getPrincipal() 获取此“userId”,请使用此方法。
我看到的唯一方法是创建JdbcUsersConnectionRepository 的实现并重新定义createConnectionRepository(String userId) 方法。但也许有更优雅的解决方案。
【问题讨论】:
标签: facebook spring spring-security spring-social