本文整理汇总了Java中org.springframework.social.connect.ConnectionData类的典型用法代码示例。如果您正苦于以下问题:Java ConnectionData类的具体用法?Java ConnectionData怎么用?Java ConnectionData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ConnectionData类属于org.springframework.social.connect包,在下文中一共展示了ConnectionData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectionToUserSocialConnection
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
private SocialUserConnection connectionToUserSocialConnection(final Connection<?> connection,
final Long rank) {
final ConnectionData connectionData = connection.createData();
return SocialUserConnection.builder()
.userId(userId)
.providerId(connection.getKey().getProviderId())
.providerUserId(connection.getKey().getProviderUserId())
.rank(rank)
.displayName(connection.getDisplayName())
.profileURL(connection.getProfileUrl())
.imageURL(connection.getImageUrl())
.accessToken(connectionData.getAccessToken())
.secret(connectionData.getSecret())
.refreshToken(connectionData.getRefreshToken())
.expireTime(connectionData.getExpireTime())
.build();
}
示例2: socialUserConnectionToConnection
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
private Connection<?> socialUserConnectionToConnection(final SocialUserConnection socialUserConnection) {
final ConnectionData connectionData = new ConnectionData(socialUserConnection.getProviderId(),
socialUserConnection.getProviderUserId(),
socialUserConnection.getDisplayName(),
socialUserConnection.getProfileURL(),
socialUserConnection.getImageURL(),
socialUserConnection.getAccessToken(),
socialUserConnection.getSecret(),
socialUserConnection.getRefreshToken(),
socialUserConnection.getExpireTime());
final ConnectionFactory<?> connectionFactory
= connectionFactoryLocator.getConnectionFactory(connectionData.getProviderId());
return connectionFactory.createConnection(connectionData);
}
示例3: testGetConnection
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
@Test
public void testGetConnection() throws Exception {
Connection connection = mock(Connection.class);
ArgumentCaptor<ConnectionData> connectionDataCaptor =
ArgumentCaptor.forClass(ConnectionData.class);
when(connectionFactoryOne.createConnection(connectionDataCaptor.capture()))
.thenReturn(connection);
when(userRepository.findOneByAuthProviderUserId(PROVIDER_ONE, providerUserId()))
.thenReturn(user());
Connection<?> foundConnection = connectionRepository.getConnection(
new ConnectionKey(PROVIDER_ONE, providerUserId()));
assertNotNull(foundConnection);
assertEquals(connection, foundConnection);
ConnectionData connectionData = connectionDataCaptor.getValue();
assertConnectionData(user(), connectionData);
}
示例4: testCreateConnectionRepository
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
@Test
public void testCreateConnectionRepository() throws Exception {
User user = new User(SocialTestUtils.USER_ONE);
user.setId(idProvider.getAndIncrement());
when(userRepository.findOneByPrimaryEmail(SocialTestUtils.USER_EMAIL_ONE))
.thenReturn(user);
Connection connection = mock(Connection.class);
ArgumentCaptor<ConnectionData> connectionDataCaptor =
ArgumentCaptor.forClass(ConnectionData.class);
ConnectionFactory connectionFactoryOne = mock(ConnectionFactory.class);
when(connectionFactoryLocator.getConnectionFactory(user.getAuthProviderId()))
.thenReturn(connectionFactoryOne);
when(connectionFactoryOne.createConnection(connectionDataCaptor.capture()))
.thenReturn(connection);
ConnectionRepository connectionRepository = usersConnectionRepository
.createConnectionRepository(SocialTestUtils.USER_EMAIL_ONE);
assertTrue(connectionRepository instanceof AwesomeAgileConnectionRepository);
}
示例5: updateConnection
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
public void updateConnection(Connection<?> connection) {
ConnectionData data = connection.createData();
SQLiteDatabase db = repositoryHelper.getWritableDatabase();
ContentValues values = new ContentValues();
values.put("displayName", data.getDisplayName());
values.put("profileUrl", data.getProfileUrl());
values.put("imageUrl", data.getImageUrl());
values.put("accessToken", encrypt(data.getAccessToken()));
values.put("secret", encrypt(data.getSecret()));
values.put("refreshToken", encrypt(data.getRefreshToken()));
values.put("expireTime", data.getExpireTime());
final String whereClause = "userId = ? and providerId = ? and providerUserId = ?";
final String[] whereArgs = { userId, data.getProviderId(), data.getProviderUserId() };
db.update("UserConnection", values, whereClause, whereArgs);
db.close();
}
示例6: getConnectionData
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
/**
* Returns the list of {@link ConnectionData} associated to the provider ID of
* the specified profile
*
* @param profile the profile that contains the connection data in its attributes
* @param providerId the provider ID of the connection
* @param encryptor the encryptor used to decrypt the accessToken, secret and refreshToken
*
* @return the list of connection data for the provider, or empty if no connection data was found
*/
public static List<ConnectionData> getConnectionData(Profile profile, String providerId,
TextEncryptor encryptor) throws CryptoException {
Map<String, List<Map<String, Object>>> allConnections = profile.getAttribute(CONNECTIONS_ATTRIBUTE_NAME);
if (MapUtils.isNotEmpty(allConnections)) {
List<Map<String, Object>> connectionsForProvider = allConnections.get(providerId);
if (CollectionUtils.isNotEmpty(connectionsForProvider)) {
List<ConnectionData> connectionDataList = new ArrayList<>(connectionsForProvider.size());
for (Map<String, Object> connectionDataMap : connectionsForProvider) {
connectionDataList.add(mapToConnectionData(providerId, connectionDataMap, encryptor));
}
return connectionDataList;
}
}
return Collections.emptyList();
}
示例7: getConnection
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
@Override
@Transactional(readOnly = true)
public Connection<?> getConnection(final ConnectionKey connectionKey) {
final String providerId = connectionKey.getProviderId();
final String providerUserId = connectionKey.getProviderUserId();
final UserConnection userConnection = userConnectionRepository.findOne(user, providerId, providerUserId);
if (userConnection == null) {
throw new NoSuchConnectionException(connectionKey);
}
final ConnectionData connectionData = Functions.toConnectionData(textEncryptor)
.apply(userConnection);
return connectionFactoryLocator.getConnectionFactory(userConnection.getProviderId())
.createConnection(connectionData);
}
示例8: findPrimaryConnection
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
public <A> Connection<A> findPrimaryConnection(final Class<A> apiType) {
final UserConnection userConnection = userConnectionRepository.findPrimaryConnection(user, getProviderId(apiType));
final ConnectionData connectionData = Functions.toConnectionData(textEncryptor)
.apply(userConnection);
if (connectionData == null) {
return null;
}
return (Connection<A>) connectionFactoryLocator.getConnectionFactory(userConnection.getProviderId())
.createConnection(connectionData);
}
示例9: addConnection
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
@Override
@Transactional
public void addConnection(final Connection<?> connection) {
final ConnectionData connectionData = connection.createData();
final String providerId = connectionData.getProviderId();
final String providerUserId = connectionData.getProviderUserId();
final int rank = userConnectionRepository.findRank(user, providerId);
final UserConnection userConnection = Functions.toUserConnection(textEncryptor, rank, user)
.apply(connectionData);
if (userConnectionRepository.findOne(user, providerId, providerUserId) != null) {
throw new DuplicateConnectionException(connection.getKey());
}
userConnectionRepository.save(userConnection);
}
示例10: testSignIn
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
@Test
public void testSignIn() throws Exception {
final ConnectionStub<Object> connection = new ConnectionStub<>(new ConnectionData("provider id",
"provider user id",
"display name",
"profile url",
"image url",
"access token",
"secret",
"refresh token",
1234L));
final MockHttpServletResponse response = new MockHttpServletResponse();
subject.signIn("userId", connection, new ServletWebRequest(new MockHttpServletRequest(), response));
final Object principal = SecurityContextHolder.getContext()
.getAuthentication()
.getPrincipal();
assertThat(principal).isEqualTo("userId");
assertThat(response.getCookie(LAST_LOGIN_SOURCE.getName()).getValue()).isEqualTo("provider id");
}
示例11: testAddConnection
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
@Test
public void testAddConnection() throws Exception {
final ConnectionData connectionData = new ConnectionData("twitter",
"provider user id 3",
"display name",
"profile url",
"image url",
"access token",
"secret",
"refresh token",
1234L);
final Connection<?> connection = new ConnectionStub<>(connectionData);
subject.addConnection(connection);
assertThat(userConnectionRepository.findAll(user, "twitter")).hasSize(3);
}
示例12: testAddConnectionWithDuplicate
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
@Test(expected = DuplicateConnectionException.class)
public void testAddConnectionWithDuplicate() throws Exception {
final ConnectionData connectionData = new ConnectionData("twitter",
"provider user id 3",
"display name",
"profile url",
"image url",
"access token",
"secret",
"refresh token",
1234L);
final Connection<?> connection = new ConnectionStub<>(connectionData);
subject.addConnection(connection);
subject.addConnection(connection);
}
示例13: testFindUserIdsWithConnection
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
@Test
public void testFindUserIdsWithConnection() throws Exception {
final ConnectionData connectionData = new ConnectionData("twitter",
"twitter_1",
null,
null,
null,
null,
null,
null,
null);
final Connection<?> connection = new ConnectionStub(connectionData);
final List<String> result = subject.findUserIdsWithConnection(connection);
assertThat(result).containsExactly(user.getId().toString());
}
示例14: testPostConnect
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
@Test
public void testPostConnect() throws Exception {
SecurityContextHolder.getContext()
.setAuthentication(new UsernamePasswordAuthenticationToken(user.getUuid(), null));
subject.postConnect(new ConnectionStub<>(new ConnectionData("provider id",
"provider user id",
"display name",
"profile url",
"image url",
"access token",
"secret",
"refresh token",
1234L)), null);
assertThat(analytics.trackings.size()).isEqualTo(1);
assertThat(analytics.trackings.containsKey(user.getUuid())).isTrue();
assertThat(analytics.trackings.getFirst(user.getUuid()).getLeft()).isEqualTo(CONNECT);
assertThat(analytics.trackings.getFirst(user.getUuid()).getRight()).contains(PROPERTY_DISPLAY_NAME, "display name",
PROPERTY_PROVIDER_ID, "provider id",
PROPERTY_PROVIDER_USER_ID, "provider user id");
}
示例15: createUserAccount
import org.springframework.social.connect.ConnectionData; //导入依赖的package包/类
@Override
public UserAccount createUserAccount(ConnectionData data, UserProfile profile) {
long userIdSequence = this.counterService.getNextUserIdSequence();
UserRoleType[] roles = (userIdSequence == 1l) ?
new UserRoleType[] { UserRoleType.ROLE_USER, UserRoleType.ROLE_AUTHOR, UserRoleType.ROLE_ADMIN } :
new UserRoleType[] { UserRoleType.ROLE_USER };
UserAccount account = new UserAccount(USER_ID_PREFIX + userIdSequence, roles);
account.setEmail(profile.getEmail());
account.setDisplayName(data.getDisplayName());
account.setImageUrl(data.getImageUrl());
if (userIdSequence == 1l) {
account.setTrustedAccount(true);
}
LOGGER.info(String.format("A new user is created (userId='%s') for '%s' with email '%s'.", account.getUserId(),
account.getDisplayName(), account.getEmail()));
return this.accountRepository.save(account);
}