Search in sources :

Example 1 with ConnectionData

use of org.springframework.social.connect.ConnectionData in project nixmash-blog by mintster.

the class SocialSignInAdapter method signIn.

@Override
public String signIn(String localUserId, Connection<?> connection, NativeWebRequest request) {
    User user = userRepository.findByUsername(localUserId);
    ConnectionData connectionData = connection.createData();
    SignInUtils.authorizeUser(user);
    SignInUtils.setUserConnection(request, connectionData);
    return null;
}
Also used : User(com.nixmash.blog.jpa.model.User) ConnectionData(org.springframework.social.connect.ConnectionData)

Example 2 with ConnectionData

use of org.springframework.social.connect.ConnectionData in project paascloud-master by paascloud.

the class AppSingUpUtils method doPostSignUp.

/**
 * 将缓存的社交网站用户信息与系统注册用户信息绑定
 *
 * @param request the request
 * @param userId  the user id
 */
public void doPostSignUp(WebRequest request, String userId) {
    String key = getKey(request);
    if (!redisTemplate.hasKey(key)) {
        throw new AppSecretException("无法找到缓存的用户社交账号信息");
    }
    ConnectionData connectionData = (ConnectionData) redisTemplate.opsForValue().get(key);
    Connection<?> connection = connectionFactoryLocator.getConnectionFactory(connectionData.getProviderId()).createConnection(connectionData);
    usersConnectionRepository.createConnectionRepository(userId).addConnection(connection);
    redisTemplate.delete(key);
}
Also used : AppSecretException(com.paascloud.security.app.AppSecretException) ConnectionData(org.springframework.social.connect.ConnectionData)

Example 3 with ConnectionData

use of org.springframework.social.connect.ConnectionData in project theskeleton by codenergic.

the class SocialConnectionService method addConnection.

@Override
@Transactional
public void addConnection(Connection<?> connection) {
    ConnectionData data = connection.createData();
    int rank = connectionRepository.getRank(userId, data.getProviderId());
    SocialConnectionEntity userConnection = new SocialConnectionEntity().setUser(new UserEntity().setId(userId)).setProvider(data.getProviderId()).setProviderUserId(data.getProviderUserId()).setRank(rank).setDisplayName(data.getDisplayName()).setProfileUrl(data.getProfileUrl()).setImageUrl(data.getImageUrl()).setAccessToken(encrypt(data.getAccessToken())).setSecret(encrypt(data.getSecret())).setRefreshToken(encrypt(data.getRefreshToken())).setExpireTime(data.getExpireTime());
    connectionRepository.save(userConnection);
}
Also used : ConnectionData(org.springframework.social.connect.ConnectionData) UserEntity(org.codenergic.theskeleton.user.UserEntity) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with ConnectionData

use of org.springframework.social.connect.ConnectionData in project theskeleton by codenergic.

the class SocialConnectionService method updateConnection.

@Override
@Transactional
public void updateConnection(Connection<?> connection) {
    ConnectionData data = connection.createData();
    SocialConnectionEntity userConnection = connectionRepository.findByUserIdAndProviderAndProviderUserId(userId, data.getProviderId(), data.getProviderUserId()).orElseThrow(() -> new NoSuchConnectionException(connection.getKey())).setDisplayName(data.getDisplayName()).setProfileUrl(data.getProfileUrl()).setImageUrl(data.getImageUrl()).setAccessToken(encrypt(data.getAccessToken())).setSecret(encrypt(data.getSecret())).setRefreshToken(encrypt(data.getRefreshToken())).setExpireTime(data.getExpireTime());
    connectionRepository.save(userConnection);
}
Also used : NoSuchConnectionException(org.springframework.social.connect.NoSuchConnectionException) ConnectionData(org.springframework.social.connect.ConnectionData) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

ConnectionData (org.springframework.social.connect.ConnectionData)4 Transactional (org.springframework.transaction.annotation.Transactional)2 User (com.nixmash.blog.jpa.model.User)1 AppSecretException (com.paascloud.security.app.AppSecretException)1 UserEntity (org.codenergic.theskeleton.user.UserEntity)1 NoSuchConnectionException (org.springframework.social.connect.NoSuchConnectionException)1