Java Code Examples for org.springframework.social.connect.Connection#getKey()

The following examples show how to use org.springframework.social.connect.Connection#getKey() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MongoUsersConnectionRepositoryImpl.java    From JiwhizBlogWeb with Apache License 2.0 6 votes vote down vote up
public List<String> findUserIdsWithConnection(Connection<?> connection) {
    ConnectionKey key = connection.getKey();
    List<UserSocialConnection> userSocialConnectionList = 
            this.userSocialConnectionRepository.findByProviderIdAndProviderUserId(key.getProviderId(), key.getProviderUserId());
    List<String> localUserIds = new ArrayList<String>();
    for (UserSocialConnection userSocialConnection : userSocialConnectionList){
        localUserIds.add(userSocialConnection.getUserId());
    }
    
    if (localUserIds.size() == 0 && connectionSignUp != null) {
        String newUserId = connectionSignUp.execute(connection);
        if (newUserId != null)
        {
            createConnectionRepository(newUserId).addConnection(connection);
            return Arrays.asList(newUserId);
        }
    }
    return localUserIds;
}
 
Example 2
Source File: WechatSignInAdapter.java    From spring-social-wechat-sample with Apache License 2.0 5 votes vote down vote up
@Override
public String signIn(String openId, Connection<?> connection, NativeWebRequest request) {
	ConnectionKey key = connection.getKey();
	if ("wechat".equalsIgnoreCase(key.getProviderId()) || "wechatmp".equalsIgnoreCase(key.getProviderId())) { // 这里的if判断可对微信开放平台和微信公众平台帐号登录做不同的逻辑处理,此例子代码处理逻辑相同
		User user = ((Wechat) connection.getApi()).userOperations().getUserProfile(openId); // 默认语言为英文,如果想切换为中文可改为:getUserProfile(openId,WechatLangEnum.ZH_CN);
		System.out.println(user); // 打印微信用户详细信息
	}
	return "/login.htm"; // 返回跳转的url
}
 
Example 3
Source File: MongoConnectionRepositoryImpl.java    From JiwhizBlogWeb with Apache License 2.0 5 votes vote down vote up
public void addConnection(Connection<?> connection) {
    //check cardinality
    SocialAuthenticationService<?> socialAuthenticationService = 
            this.socialAuthenticationServiceLocator.getAuthenticationService(connection.getKey().getProviderId());
    if (socialAuthenticationService.getConnectionCardinality() == ConnectionCardinality.ONE_TO_ONE ||
            socialAuthenticationService.getConnectionCardinality() == ConnectionCardinality.ONE_TO_MANY){
        List<UserSocialConnection> storedConnections = 
                this.userSocialConnectionRepository.findByProviderIdAndProviderUserId(
                        connection.getKey().getProviderId(), connection.getKey().getProviderUserId());
        if (storedConnections.size() > 0){
            //not allow one providerId/providerUserId connect to multiple userId
            throw new DuplicateConnectionException(connection.getKey());
        }
    }
    
    UserSocialConnection userSocialConnection = this.userSocialConnectionRepository
            .findByUserIdAndProviderIdAndProviderUserId(userId, connection.getKey().getProviderId(), 
                    connection.getKey().getProviderUserId());
    if (userSocialConnection == null) {
        ConnectionData data = connection.createData();
        userSocialConnection = new UserSocialConnection(userId, data.getProviderId(), data.getProviderUserId(), 0,
                data.getDisplayName(), data.getProfileUrl(), data.getImageUrl(), encrypt(data.getAccessToken()),
                encrypt(data.getSecret()), encrypt(data.getRefreshToken()), data.getExpireTime());
        this.userSocialConnectionRepository.save(userSocialConnection);
    } else {
        throw new DuplicateConnectionException(connection.getKey());
    }
}
 
Example 4
Source File: SocialUserServiceImpl.java    From cloudstreetmarket.com with GNU General Public License v3.0 4 votes vote down vote up
public List<String> findUserIdsWithConnection(Connection<?> connection) {
    ConnectionKey key = connection.getKey();
    return socialUserRepository.findUserIdsByProviderIdAndProviderUserId(key.getProviderId(), key.getProviderUserId());
}