Package org.surfnet.oaaas.model

Examples of org.surfnet.oaaas.model.Client


    assertThat(validationErrorResponse.getViolations().get(0), containsString("Client should only contain scopes that its resource server defines"));
  }

  @Test
  public void post() {
    Client originalClient = putSomeClient();


    final String newDescription = "new description";
    originalClient.setDescription(newDescription);
    Client postResult = webResource
        .path(String.valueOf(originalClient.getId()))
        .header("Authorization", authorizationBearer(ACCESS_TOKEN))
        .post(Client.class, originalClient);
    assertEquals(newDescription, postResult.getDescription());
  }
View Full Code Here


    assertEquals(newDescription, postResult.getDescription());
  }

  @Test
  public void delete() {
    Client c = putSomeClient();
    String id = String.valueOf(c.getId());
    ClientResponse deleteResponse = webResource
        .path(id)
        .header("Authorization", authorizationBearer(ACCESS_TOKEN))
        .delete(ClientResponse.class);
    assertEquals(204, deleteResponse.getStatus());
View Full Code Here

        .get(ClientResponse.class);
    assertEquals(404, getResponse.getStatus());
  }

  private Client buildClient() {
    Client c = new Client();
    String r = UUID.randomUUID().toString();
    c.setClientId(r);
    c.setContactEmail("contact@example.com");
    c.setContactName("contact name");
    c.setName(r);
    c.setScopes(Arrays.asList("read"));
    c.setSecret(r);
    c.setDescription("Some description");
    final HashMap<String, String> attributes = new HashMap<String, String>();
    attributes.put("myKey", "myValue");
    attributes.put("myKey2", "myValue2");
    attributes.put("myKey3", "myValue3");
    c.setAttributes(attributes);
    return c;
  }
View Full Code Here

    c.setAttributes(attributes);
    return c;
  }

  private Client putSomeClient() {
    Client c = buildClient();
    return webResource
        .header("Authorization", authorizationBearer(ACCESS_TOKEN))
        .put(Client.class, c);
  }
View Full Code Here

public class ClientRepositoryTest extends AbstractTestRepository {

  @Test
  public void test() {
    ClientRepository repo = getRepository(ClientRepository.class);
    Client client = repo.findByClientId("cool_app_id");
    Map<String, String> attr = client.getAttributes();
    assertEquals("foo-university", attr.get("university"));
  }
View Full Code Here

    r.setSecret("secret");

    r = resourceServerRepository.save(r);

    // Create and save a client
    Client client = new Client();
    client.setName("name");
    client.setClientId("clientid");

    // Let them meet each other
    r.setClients(new HashSet(Arrays.asList(client)));
    client.setResourceServer(r);

    client = repo.save(client);


    // Create an access token
    AccessToken at = new AccessToken("mytoken", new AuthenticatedPrincipal("username"), client, 0, null);
    at = accessTokenRepository.save(at);
    assertEquals(at, accessTokenRepository.findOne(at.getId()));

    // Create an authorization request
    AuthorizationRequest ar = new AuthorizationRequest("foo", "faa", "boo", null, "boo", "boo");
    ar.setClient(client);
    ar = authorizationRequestRepository.save(ar);
    assertEquals(ar, authorizationRequestRepository.findOne(ar.getId()));

    // Make sure things are saved; the relation between clients and access tokens is unidirectional; therefore a
    // delete would not work with attached entities.
    entityManager.clear();

    final long clientId = client.getId();
    repo.delete(client);
    assertNull(repo.findOne(clientId));

    assertNull(accessTokenRepository.findOne(at.getId()));
    assertNull(authorizationRequestRepository.findOne(ar.getId()));
View Full Code Here

  }


  private AuthorizationRequest createAuthRequest(String implicitGrantResponseType) {
    AuthorizationRequest authRequest = new AuthorizationRequest();
    Client client = new Client();
    authRequest.setClient(client);
    authRequest.setResponseType(implicitGrantResponseType);
    authRequest.setPrincipal(new AuthenticatedPrincipal("sammy sammy"));
    authRequest.setRedirectUri("http://localhost:8080");
    authRequest.setState("important");
View Full Code Here

    String authState = UUID.randomUUID().toString();
    AuthorizationRequest authReq = new AuthorizationRequest("code", "cool_app_id", "http://whatever",
        Arrays.asList("read","update"),
        "state", authState);
    ClientRepository clientRepo = getRepository(ClientRepository.class);
    Client client = clientRepo.findByClientId(authReq.getClientId());
    client.getAttributes();
    authReq.setClient(client);
    save(authReq, repo);
    authReq.setPrincipal(getPrincipal());
    repo.save(authReq);
View Full Code Here

    resourceServerResource = new ResourceServerResource();
  }

  @Test
  public void pruneScopes() {
    Client client1 = new Client();
    client1.setScopes(Arrays.asList("scope1"));
    Client client2 = new Client();
    client2.setScopes(Arrays.asList("scope1", "scope2"));

    Set<Client> clients = new HashSet(Arrays.asList(client1, client2));

    List<String> oldScopes = Arrays.asList("scope1");
    List<String> newScopes = Arrays.asList("scope2");

    resourceServerResource.pruneClientScopes(newScopes, oldScopes, clients);

    assertEquals(0, client1.getScopes().size());
    assertEquals(1, client2.getScopes().size());
    assertEquals("scope2", client2.getScopes().get(0));
  }
View Full Code Here

    assertEquals("some-nice-client-name-", sanitized);
  }

  @Test
  public void uniqueClientId() {
    final Client existingClient = new Client();
    when(clientRepository.findByClientId(anyString())).thenReturn(
        existingClient,
        existingClient,
        existingClient,
        existingClient,
        existingClient,
        null);
    Client newClient = new Client();
    newClient.setName("myname");
    String clientId = clientResource.generateClientId(newClient);
    LOG.debug("client id generated: " + clientId);
    // 5 existing clients, this one should be number 6.
    assertEquals("myname6", clientId);
  }
View Full Code Here

TOP

Related Classes of org.surfnet.oaaas.model.Client

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.