我希望将Spring Social Facebook整合到我的应用程序中,并使用Spring Security(我使用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
”。因此,我的问题是:如果我想使用SecurityContextHolder.getContext().getAuthentication().getPrincipal()
获取这个“userId
”,那么我该如何将“userId
”传递给这个方法呢?我唯一能想到的方法是创建我的
JdbcUsersConnectionRepository
实现,并重新定义createConnectionRepository(String userId)
方法。但可能还有更优雅的解决方案。
SecurityContextImpl.setAuthentication(...)
方法中设置一个断点,并在调试模式下查找原因。 - Maksym Demidas