Package org.springframework.social.connect

Examples of org.springframework.social.connect.ConnectionKey


  @Test
  public void removeConnection() {
    insertFacebookConnection();
    assertTrue(dataAccessor.queryForObject("select exists (select 1 from " + getTablePrefix() + "UserConnection where providerId = 'facebook')", Boolean.class));
    connectionRepository.removeConnection(new ConnectionKey("facebook", "9"));
    assertFalse(dataAccessor.queryForObject("select exists (select 1 from " + getTablePrefix() + "UserConnection where providerId = 'facebook')", Boolean.class));   
  }
View Full Code Here


    assertFalse(dataAccessor.queryForObject("select exists (select 1 from " + getTablePrefix() + "UserConnection where providerId = 'facebook')", Boolean.class));   
  }

  @Test
  public void removeConnectionNoOp() {
    connectionRepository.removeConnection(new ConnectionKey("facebook", "1"));
  }
View Full Code Here

  @Test
  public void findPrimaryConnection_afterRemove() {
    insertFacebookConnection();
    insertFacebookConnection2();   
    // 9 is the providerUserId of the first Facebook connection
    connectionRepository.removeConnection(new ConnectionKey("facebook", "9"));
    assertEquals(1, connectionRepository.findConnections(TestFacebookApi.class).size());
    assertNotNull(connectionRepository.findPrimaryConnection(TestFacebookApi.class));
  }
View Full Code Here

    assertEquals("123456789", connection.createData().getAccessToken());
    assertEquals("987654321", connection.createData().getRefreshToken());
  }

  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());   
View Full Code Here

    twitter.sync();
    assertEquals("http://twitter.com/kdonald/a_new_picture", twitter.getImageUrl());
  }

  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());
View Full Code Here

    Set<ConnectionKey> connectionKeys = new HashSet<ConnectionKey>();
    for (Connection<?> connection : connections) {
      if (includeExpiredConnections || !connection.hasExpired()) {

        ConnectionData connectionData = connection.createData();
        connectionKeys.add(new ConnectionKey(connectionData
            .getProviderId(), connectionData.getProviderUserId()));
      }
    }
    return connectionKeys;
  }
View Full Code Here

    }
    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;
      }
    }
View Full Code Here

      providerUserIds.add(userId);
      Set<String> localUserIds = usersConnectionRepository.findUserIdsConnectedTo("facebook", providerUserIds);
      for (String localUserId : localUserIds) {
        ConnectionRepository connectionRepository = usersConnectionRepository.createConnectionRepository(localUserId);
        logger.info("  Removing Facebook connection for local user '" + localUserId + "'");
        connectionRepository.removeConnection(new ConnectionKey("facebook", userId));
      }   
      return new ResponseEntity<String>(HttpStatus.NO_CONTENT);
    } catch (SignedRequestException e) {
      return new ResponseEntity<String>(HttpStatus.BAD_REQUEST);
    }
View Full Code Here

TOP

Related Classes of org.springframework.social.connect.ConnectionKey

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.