}
return false;
}
protected Connection<?> addConnection(SocialAuthenticationService<?> authService, String userId, Connection<?> connection) {
ConnectionKey connectionKey = connection.getKey();
HashSet<String> userIdSet = new HashSet<String>();
userIdSet.add(connectionKey.getProviderUserId());
Set<String> connectedUserIds = usersConnectionRepository.findUserIdsConnectedTo(connectionKey.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(connectionKey.getProviderId());
if (!connections.isEmpty()) {
// TODO maybe throw an exception to allow UI feedback?
return null;
}
}