我使用Spring Social LinkedIn通过自定义ConnectController检索用户配置文件,因为我希望用户一步登录并检索配置文件。问题是有时会返回系统中的第一个用户而不是当前登录的用户。
这是我的CustomConnectController
@Controller
@RequestMapping("/connect")
public class CustomConnectController extends ConnectController {
@Inject
public CustomConnectController(ConnectionFactoryLocator connectionFactoryLocator,
ConnectionRepository connectionRepository) {
super(connectionFactoryLocator, connectionRepository);
}
@Override
protected String connectView(String providerId) {
return "redirect:/hey/" + providerId + "Connect";
}
@Override
protected String connectedView(String providerId) {
return "redirect:/hey/" + providerId + "Connected";
}
}
和我的webcontroller
@Controller
public class WebController {
@Autowired
private LinkedIn linkedin;
@Autowired
private ConnectionRepository repository;
@RequestMapping(value = "/hey/linkedinConnected", method = RequestMethod.GET)
public String linkedinConnected(HttpServletRequest request, Model model, Locale locale) {
if (repository.findConnections("linkedin").isEmpty()
|| !linkedin.isAuthorized()) {
return "redirect:/connect/linkedin";
}
LinkedInProfile userProfile = linkedin.profileOperations().getUserProfile();
return "loggedinpage";
}
@RequestMapping(value = "/hey/linkedinConnect", method = RequestMethod.GET)
public String linkedinConnect(HttpServletRequest request, Model model, Locale locale) {
if (repository.findConnections("linkedin").isEmpty()
|| !linkedin.isAuthorized()) {
return "redirect:/connect/linkedin";
}
LinkedInProfile userProfile = linkedin.profileOperations().getUserProfile();
return "loggedinpage";
}
}
关于我做错了什么的想法?