本文整理了Java中org.springframework.social.connect.Connection.sync()
方法的一些代码示例,展示了Connection.sync()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Connection.sync()
方法的具体详情如下:
包路径:org.springframework.social.connect.Connection
类名称:Connection
方法名:sync
[英]Sync's this connection object with the current state of the external user's profile. Triggers locally cached profile fields to update if they have changed on the provider's system.
[中]将此连接对象与外部用户配置文件的当前状态同步。如果本地缓存的配置文件字段在提供程序的系统上发生更改,则触发这些字段进行更新。
代码示例来源:origin: org.springframework.social/spring-social-security
protected Connection<?> addConnection(SocialAuthenticationService<?> authService, String userId, ConnectionData data) {
HashSet<String> userIdSet = new HashSet<String>();
userIdSet.add(data.getProviderUserId());
Set<String> connectedUserIds = usersConnectionRepository.findUserIdsConnectedTo(data.getProviderId(), userIdSet);
if (connectedUserIds.contains(userId)) {
// already connected
return null;
} else if (!authService.getConnectionCardinality().isMultiUserId() && !connectedUserIds.isEmpty()) {
return null;
}
ConnectionRepository repo = usersConnectionRepository.createConnectionRepository(userId);
if (!authService.getConnectionCardinality().isMultiProviderUserId()) {
List<Connection<?>> connections = repo.findConnections(data.getProviderId());
if (!connections.isEmpty()) {
// TODO maybe throw an exception to allow UI feedback?
return null;
}
}
// add new connection
Connection<?> connection = authService.getConnectionFactory().createConnection(data);
connection.sync();
repo.addConnection(connection);
return connection;
}
代码示例来源:origin: com.jtbdevelopment.core-games/games-web
protected Connection<?> addConnection(SocialAuthenticationService<?> authService, String userId, ConnectionData data) {
Set<String> userIdSet = new HashSet<>();
userIdSet.add(data.getProviderUserId());
Set<String> connectedUserIds = usersConnectionRepository.findUserIdsConnectedTo(data.getProviderId(), userIdSet);
if (connectedUserIds.contains(userId)) {
// already connected
return null;
} else if (!authService.getConnectionCardinality().isMultiUserId() && !connectedUserIds.isEmpty()) {
return null;
}
ConnectionRepository repo = usersConnectionRepository.createConnectionRepository(userId);
if (!authService.getConnectionCardinality().isMultiProviderUserId()) {
List<Connection<?>> connections = repo.findConnections(data.getProviderId());
if (!connections.isEmpty()) {
// JTB - removed to do marker here to not show on scans as this is c-n-p
// maybe throw an exception to allow UI feedback?
return null;
}
}
// add new connection
Connection<?> connection = authService.getConnectionFactory().createConnection(data);
connection.sync();
repo.addConnection(connection);
return connection;
}
代码示例来源:origin: at.molindo.social/spring-social-security
protected Connection<?> addConnection(SocialAuthenticationService<?> authService, String userId, ConnectionData data) {
HashSet<String> userIdSet = new HashSet<String>();
userIdSet.add(data.getProviderUserId());
Set<String> connectedUserIds = usersConnectionRepository.findUserIdsConnectedTo(data.getProviderId(), userIdSet);
if (connectedUserIds.contains(userId)) {
// providerUserId already connected to userId
return null;
} else if (!authService.getConnectionCardinality().isMultiUserId() && !connectedUserIds.isEmpty()) {
// providerUserId already connected to different userId and no multi user allowed
return null;
}
ConnectionRepository repo = usersConnectionRepository.createConnectionRepository(userId);
if (!authService.getConnectionCardinality().isMultiProviderUserId()) {
List<Connection<?>> connections = repo.findConnections(data.getProviderId());
if (!connections.isEmpty()) {
// TODO maybe throw an exception to allow UI feedback?
return null;
}
}
// add new connection
Connection<?> connection = authService.getConnectionFactory().createConnection(data);
connection.sync();
repo.addConnection(connection);
return connection;
}
代码示例来源:origin: io.loli.social/custom-social-core-extension
@Test
public void updateConnectionProfileFields() {
connectionFactoryRegistry
.addConnectionFactory(new TestTwitterConnectionFactory());
insertTwitterConnection();
Connection<TestTwitterApi> twitter = connectionRepository
.getPrimaryConnection(TestTwitterApi.class);
assertEquals("http://twitter.com/kdonald/picture",
twitter.getImageUrl());
twitter.sync();
assertEquals("http://twitter.com/kdonald/a_new_picture",
twitter.getImageUrl());
connectionRepository.updateConnection(twitter);
Connection<TestTwitterApi> twitter2 = connectionRepository
.getPrimaryConnection(TestTwitterApi.class);
assertEquals("http://twitter.com/kdonald/a_new_picture",
twitter2.getImageUrl());
}
代码示例来源:origin: io.loli.social/custom-social-core-extension
private void assertTwitterConnection(Connection<TestTwitterApi> twitter) {
assertEquals(new ConnectionKey("twitter", "1"), twitter.getKey());
assertEquals("@kdonald", twitter.getDisplayName());
assertEquals("http://twitter.com/kdonald", twitter.getProfileUrl());
assertEquals("http://twitter.com/kdonald/picture",
twitter.getImageUrl());
TestTwitterApi twitterApi = twitter.getApi();
assertEquals("123456789", twitterApi.getAccessToken());
assertEquals("987654321", twitterApi.getSecret());
twitter.sync();
assertEquals("http://twitter.com/kdonald/a_new_picture",
twitter.getImageUrl());
}
代码示例来源:origin: io.loli.social/custom-social-core-extension
private void assertFacebookConnection(Connection<TestFacebookApi> facebook) {
assertEquals(new ConnectionKey("facebook", "9"), facebook.getKey());
assertEquals(null, facebook.getDisplayName());
assertEquals(null, facebook.getProfileUrl());
assertEquals(null, facebook.getImageUrl());
TestFacebookApi facebookApi = facebook.getApi();
assertEquals("234567890", facebookApi.getAccessToken());
facebook.sync();
assertEquals("Keith Donald", facebook.getDisplayName());
assertEquals("http://facebook.com/keith.donald",
facebook.getProfileUrl());
assertEquals("http://facebook.com/keith.donald/picture",
facebook.getImageUrl());
}
内容来源于网络,如有侵权,请联系作者删除!