Package org.multibit.mbm.client.interfaces.rest.api.user

Examples of org.multibit.mbm.client.interfaces.rest.api.user.UserDto


        Optional<UserDto> anonymousUserOptional = PublicMerchantClient
          .newInstance(Locale.getDefault())
          .user()
          .registerAnonymously();
        if (anonymousUserOptional.isPresent()) {
          UserDto anonymousUser = anonymousUserOptional.get();
          anonymousUser.setSessionToken(UUID.randomUUID());
          // Keep a copy in the session cache
          InMemorySessionTokenCache
            .INSTANCE
            .put(anonymousUser.getSessionToken(), anonymousUser);
        }
        return anonymousUserOptional;

      }
View Full Code Here


      // User has been authenticated by the upstream server

      // Create a session token to allow ongoing cookie authentication
      UUID sessionToken = UUID.randomUUID();

      UserDto clientUser = clientUserOptional.get();
      clientUser.setSessionToken(sessionToken);

      // Cache this user to allow cookie authentication
      InMemorySessionTokenCache
        .INSTANCE
        .put(sessionToken, clientUserOptional.get());
View Full Code Here

    // Arrange
    final CartDto expectedCart = new CartDto();
    expectedCart.setItemTotal("2");

    final UserDto clientUser = new UserDto();
    clientUser.setApiKey("apiKey");
    clientUser.setSecretKey("secretKey");

    URI expectedUri = URI.create("http://localhost:8080/mbm/cart");

    // Test-specific JerseyClient behaviour
    when(client.resource(expectedUri))
View Full Code Here

    // Arrange
    final CartDto expectedCart = new CartDto();
    expectedCart.setItemTotal("2");

    final UserDto clientUser = new UserDto();
    clientUser.setApiKey("apiKey");
    clientUser.setSecretKey("secretKey");

    URI expectedUri = URI.create("http://localhost:8080/mbm/cart");

    // Test-specific JerseyClient behaviour
    when(client.resource(expectedUri))
View Full Code Here

    // Arrange
    final CartDto expectedCart = new CartDto();
    expectedCart.setItemTotal("2");

    final UserDto clientUser = new UserDto();
    clientUser.setApiKey("apiKey");
    clientUser.setSecretKey("secretKey");

    URI expectedUri = URI.create("http://localhost:8080/mbm/cart");

    // Test-specific JerseyClient behaviour
    when(client.resource(expectedUri))
View Full Code Here

public class InMemorySessionTokenCacheTest {

  @Test
  public void testGetBySessionToken() throws Exception {

    UserDto expectedClientUser = createClientUser();

    InMemorySessionTokenCache
      .INSTANCE
      .put(
        expectedClientUser.getSessionToken(),
        expectedClientUser);

    Optional<UserDto> clientUserOptional = InMemorySessionTokenCache
      .INSTANCE
      .getBySessionToken(Optional.of(expectedClientUser.getSessionToken()));

    assertTrue(clientUserOptional.isPresent());

    assertEquals(expectedClientUser, clientUserOptional.get());
View Full Code Here

  }

  @Test
  public void testPut_WithExpiry() throws Exception {

    UserDto expectedClientUser = createClientUser();

    InMemorySessionTokenCache
      .INSTANCE
      .reset(100, TimeUnit.MILLISECONDS)
      .put(
        expectedClientUser.getSessionToken(),
        expectedClientUser);

    // Allow time for expiry
    Thread.sleep(200);

    Optional<UserDto> clientUserOptional = InMemorySessionTokenCache
      .INSTANCE
      .getBySessionToken(Optional.of(expectedClientUser.getSessionToken()));

    assertFalse(clientUserOptional.isPresent());

  }
View Full Code Here

  @Test
  public void testPut_WithActivityPreventingExpiry() throws Exception {

    int duration = 200;

    UserDto expectedClientUser = createClientUser();

    InMemorySessionTokenCache
      .INSTANCE
      .reset(duration, TimeUnit.MILLISECONDS)
      .put(
        expectedClientUser.getSessionToken(),
        expectedClientUser);

    // Wait for a duration within the expiry time
    Thread.sleep(duration / 2);

    // This should reset the cache expiry giving the entry longer life
    Optional<UserDto> clientUserOptional = InMemorySessionTokenCache
      .INSTANCE
      .getBySessionToken(Optional.of(expectedClientUser.getSessionToken()));

    assertTrue("Unexpected expiry of client user (early expiration)", clientUserOptional.isPresent());

    // Wait for a duration that now extends beyond the original expiry time
    Thread.sleep(duration * 3 / 4);

    // This should again reset the cache expiry giving the entry longer life
    clientUserOptional = InMemorySessionTokenCache
      .INSTANCE
      .getBySessionToken(Optional.of(expectedClientUser.getSessionToken()));

    assertTrue("Unexpected expiry of client user (refresh failed)", clientUserOptional.isPresent());

    // Wait for a duration that now extends beyond the refreshed expiry time
    Thread.sleep(duration * 2);

    // This should again reset the cache expiry giving the entry longer life
    clientUserOptional = InMemorySessionTokenCache
      .INSTANCE
      .getBySessionToken(Optional.of(expectedClientUser.getSessionToken()));

    assertFalse("Unexpected presence of client user (late expiration)",clientUserOptional.isPresent());

  }
View Full Code Here

  }

  private UserDto createClientUser() {

    UserDto clientUser = new UserDto();

    clientUser.setApiKey("apiKey");
    clientUser.setUsername("username");
    clientUser.setCachedAuthorities(new Authority[]{Authority.ROLE_CUSTOMER});
    clientUser.setPasswordDigest("passwordDigest");
    clientUser.setSecretKey("secretKey");
    clientUser.setSessionToken(UUID.randomUUID());

    return clientUser;
  }
View Full Code Here

    // Read the HAL
    ReadableRepresentation rr = unmarshalHal(hal);

    Map<String, Object> properties = rr.getProperties();

    UserDto clientUser = new UserDto();
    String apiKey = (String) properties.get("api_key");
    String secretKey = (String) properties.get("secret_key");

    if ("".equals(apiKey) || "".equals(secretKey)) {
      return Optional.absent();
    }

    // Must assume that the registration was successful
    // Using the credentials later would mean failed authentication anyway
    clientUser.setApiKey(apiKey);
    clientUser.setSecretKey(secretKey);
    clientUser.setCachedAuthorities(new Authority[] {Authority.ROLE_CUSTOMER});

    return Optional.of(clientUser);
  }
View Full Code Here

TOP

Related Classes of org.multibit.mbm.client.interfaces.rest.api.user.UserDto

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.