private void doInvoke(String actualBookName, String actualHeaderName) throws Exception {
      Response response = client.post(actualBookName);

      assertEquals(actualHeaderName, response.getMetadata().getFirst("CustomHeader").toString());
      String responseValue = IOUtils.readStringFromStream((InputStream) response.getEntity());
      assertEquals(actualBookName, responseValue);
    }
  public boolean removeUserCredentialsForPaaS(String userInstanceUriId, String paaSInstanceUriId)
      throws SOAException {
    String rsUri = getBASE_URI() + "removeUserCredentialsForPaaS";

    WebClient client = WebClient.create(rsUri);
    client.type("multipart/mixed").accept(MediaType.TEXT_PLAIN);

    registerJsonProvider();

    List<Attachment> atts = new LinkedList<Attachment>();

    atts.add(new Attachment("userInstanceUriId", MediaType.TEXT_PLAIN, userInstanceUriId));

    atts.add(new Attachment("paaSInstanceUriId", MediaType.TEXT_PLAIN, paaSInstanceUriId));

    Response response = client.post(new MultipartBody(atts));

    if (Response.Status.fromStatusCode(response.getStatus()) == Response.Status.ACCEPTED) {
      try {
        String responseString = IOUtils.readStringFromStream((InputStream) response.getEntity());
        logger.debug("Response Status ACCEPTED - " + responseString);
      } catch (IOException ex) {
        logger.error("Error reading the REST response: " + ex.getMessage());
      }
      return true;
    }
    return false;
  }
  public String storeTurtleUserProfile(String userProfile, String username, String password) {
    String rsUri = getBASE_URI() + "createNewUserAccount";

    WebClient client = WebClient.create(rsUri);
    client.type("multipart/mixed").accept(MediaType.TEXT_PLAIN);

    registerJsonProvider();

    List<Attachment> atts = new LinkedList<Attachment>();

    atts.add(new Attachment("userProfile", MediaType.TEXT_PLAIN, userProfile));

    atts.add(new Attachment("username", MediaType.TEXT_PLAIN, username));

    atts.add(new Attachment("password", MediaType.TEXT_PLAIN, password));

    Response response = client.post(new MultipartBody(atts));
    String userInstanceUriId = null;
    if (Response.Status.fromStatusCode(response.getStatus()) == Response.Status.CREATED) {
      try {
        userInstanceUriId = IOUtils.readStringFromStream((InputStream) response.getEntity());
        logger.debug("Response Status CREATED - userInstanceUriId: " + userInstanceUriId);
      } catch (IOException ex) {
        logger.error("Error reading the REST response: " + ex.getMessage());
      }
    }
    return userInstanceUriId;
  }
Exemple #4
0
  public static String getAuthorizationCode(WebClient client, String scope) {
    // Make initial authorization request
    client.type("application/json").accept("application/json");
    client.query("client_id", "consumer-id");
    client.query("redirect_uri", "http://www.blah.apache.org");
    client.query("response_type", "code");
    if (scope != null) {
      client.query("scope", scope);
    }
    client.path("authorize/");
    Response response = client.get();

    OAuthAuthorizationData authzData = response.readEntity(OAuthAuthorizationData.class);

    // Now call "decision" to get the authorization code grant
    client.path("decision");
    client.type("application/x-www-form-urlencoded");

    Form form = new Form();
    form.param("session_authenticity_token", authzData.getAuthenticityToken());
    form.param("client_id", authzData.getClientId());
    form.param("redirect_uri", authzData.getRedirectUri());
    if (authzData.getProposedScope() != null) {
      form.param("scope", authzData.getProposedScope());
    }
    form.param("oauthDecision", "allow");

    response = client.post(form);
    String location = response.getHeaderString("Location");
    return getSubstring(location, "code");
  }
  // TEIID-3914 - test the olingo-patch work
  public void testCompositeKeyTimestamp() throws Exception {

    String vdb =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"northwind\" version=\"1\">\n"
            + "    <model name=\"m\">\n"
            + "        <source name=\"x1\" translator-name=\"loopback\" />\n"
            + "         <metadata type=\"DDL\"><![CDATA[\n"
            + "                CREATE FOREIGN TABLE x (a string, b timestamp, c integer, primary key (a, b)) options (updatable true);\n"
            + "        ]]> </metadata>\n"
            + "    </model>\n"
            + "</vdb>";

    admin.deploy(
        "loopy-vdb.xml", new ReaderInputStream(new StringReader(vdb), Charset.forName("UTF-8")));
    assertTrue(AdminUtil.waitForVDBLoad(admin, "Loopy", 1, 3));

    WebClient client =
        WebClient.create("http://localhost:8080/odata4/m/x(a='a',b=2011-09-11T00:00:00Z)");
    client.header(
        "Authorization",
        "Basic " + Base64.encodeBytes(("user:user").getBytes())); // $NON-NLS-1$ //$NON-NLS-2$
    Response response = client.invoke("GET", null);
    assertEquals(200, response.getStatus());

    client = WebClient.create("http://localhost:8080/odata4/m/x");
    client.header(
        "Authorization",
        "Basic " + Base64.encodeBytes(("user:user").getBytes())); // $NON-NLS-1$ //$NON-NLS-2$
    response = client.post("{\"a\":\"b\", \"b\":\"2000-02-02T22:22:22Z\"}");
    assertEquals(204, response.getStatus());

    admin.undeploy("loopy-vdb.xml");
  }
  @Test
  public void testPostBookAdminRoleWithGoodSubjectName() throws Exception {
    String address = "https://*****:*****@mycompany.com");
    WebClient wc = createWebClient(address, props);
    wc.type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML);
    Book book = wc.post(new Book("CXF", 125L), Book.class);
    assertEquals(125L, book.getId());
  }
 @Test
 public void testPostBookAdminRole() throws Exception {
   String address = "https://localhost:" + PORT + "/saml-roles/bookstore/books";
   WebClient wc =
       createWebClient(
           address,
           Collections.<String, Object>singletonMap(
               "saml.roles", Collections.singletonList("admin")));
   wc.type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML);
   Book book = wc.post(new Book("CXF", 125L), Book.class);
   assertEquals(125L, book.getId());
 }
 @Test
 public void testPostBookUserRole() throws Exception {
   String address = "https://localhost:" + PORT + "/saml-roles/bookstore/books";
   WebClient wc = createWebClient(address, null);
   wc.type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML);
   try {
     wc.post(new Book("CXF", 125L), Book.class);
     fail("403 is expected");
   } catch (WebApplicationException ex) {
     assertEquals(403, ex.getResponse().getStatus());
   }
 }
  @Test
  public void testPostBookAdminWithClaims() throws Exception {
    String address = "https://localhost:" + PORT + "/saml-claims/bookstore/books";

    Map<String, Object> props = new HashMap<String, Object>();
    props.put("saml.roles", Collections.singletonList("admin"));
    props.put("saml.auth", Collections.singletonList("smartcard"));
    WebClient wc = createWebClient(address, props);
    wc.type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML);
    Book book = wc.post(new Book("CXF", 125L), Book.class);
    assertEquals(125L, book.getId());
  }
Exemple #10
0
  public static ClientAccessToken getAccessTokenWithAuthorizationCode(
      WebClient client, String code) {
    client.type("application/x-www-form-urlencoded").accept("application/json");
    client.path("token");

    Form form = new Form();
    form.param("grant_type", "authorization_code");
    form.param("code", code);
    form.param("client_id", "consumer-id");
    Response response = client.post(form);

    return response.readEntity(ClientAccessToken.class);
  }
 @Test
 @Ignore
 public void shit() throws Exception {
   WebClient client =
       WebClient.create("http://localhost:8080/forsendelse/service/rest/forsendelsesservice/send");
   client.type("multipart/form-data");
   List<Attachment> attacments = new ArrayList<Attachment>();
   attacments.add(
       createDocumentAttachment(new File("src/test/resources/Undervisningsfritak.pdf")));
   attacments.add(createForsendelsesAttachment(createForsendelse(1)));
   Response rs = client.post(new MultipartBody(attacments));
   System.out.println(rs.getStatus());
 }
  @Test
  public void testPostBookAdminWithWeakClaims() throws Exception {
    String address = "https://localhost:" + PORT + "/saml-claims/bookstore/books";

    Map<String, Object> props = new HashMap<String, Object>();
    WebClient wc = createWebClient(address, props);
    wc.type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML);
    try {
      wc.post(new Book("CXF", 125L), Book.class);
      fail("403 is expected");
    } catch (WebApplicationException ex) {
      assertEquals(403, ex.getResponse().getStatus());
    }
  }
 @Test
 public void testPostBookAdminRoleWithWrongSubjectNameFormat() throws Exception {
   String address = "https://localhost:" + PORT + "/saml-roles2/bookstore/books";
   WebClient wc =
       createWebClient(
           address,
           Collections.<String, Object>singletonMap(
               "saml.roles", Collections.singletonList("admin")));
   wc.type(MediaType.APPLICATION_XML).accept(MediaType.APPLICATION_XML);
   try {
     wc.post(new Book("CXF", 125L), Book.class);
     fail("403 is expected");
   } catch (WebApplicationException ex) {
     assertEquals(403, ex.getResponse().getStatus());
   }
 }
  public UserPaaSCredentials readUserCredentialsForPaaS(
      String userInstanceUriId, String paaSInstanceUriId) throws SOAException {
    String rsUri = getBASE_URI() + "readUserCredentialsForPaaS";

    WebClient client = WebClient.create(rsUri);
    client.type("multipart/mixed").accept(MediaType.APPLICATION_JSON);

    registerJsonProvider();

    List<Attachment> atts = new LinkedList<Attachment>();

    atts.add(new Attachment("userInstanceUriId", MediaType.TEXT_PLAIN, userInstanceUriId));

    atts.add(new Attachment("paaSInstanceUriId", MediaType.TEXT_PLAIN, paaSInstanceUriId));
    UserPaaSCredentials userPaaSCredentials;
    try {
      userPaaSCredentials = client.post(new MultipartBody(atts), UserPaaSCredentials.class);
    } catch (ServerWebApplicationException cwe) {
      throw new SOAException(Response.Status.fromStatusCode(cwe.getStatus()), cwe.getMessage());
    }

    return userPaaSCredentials;
  }
  public UserInstance authenticateUser(String username, String password)
      throws ClientWebApplicationException {
    String rsUri = getBASE_URI() + "authenticateUser";

    WebClient client = WebClient.create(rsUri);
    client.type("multipart/mixed").accept(MediaType.APPLICATION_XML_TYPE);

    registerJsonProvider();

    List<Attachment> atts = new LinkedList<Attachment>();

    atts.add(new Attachment("username", MediaType.TEXT_PLAIN, username));

    atts.add(new Attachment("password", MediaType.TEXT_PLAIN, password));

    //        Response response = client.post(new MultipartBody(atts));
    UserInstance userInstance = client.post(new MultipartBody(atts), UserInstance.class);
    //        UserInstance userInstance = null;

    //        userInstance = (UserInstance)response.getEntity();
    //        logger.debug("userInstance: "+userInstance);

    return userInstance;
  }
  @org.junit.Test
  public void testKerberos() throws Exception {

    URL busFile = JAXRSAuthenticationTest.class.getResource("cxf-client.xml");

    String address = "https://*****:*****@service.ws.apache.org");
    authSupplier.setServiceNameType(GSSName.NT_HOSTBASED_SERVICE);
    WebClient.getConfig(client).getHttpConduit().setAuthSupplier(authSupplier);

    Number numberToDouble = new Number();
    numberToDouble.setDescription("This is the number to double");
    numberToDouble.setNumber(25);

    Response response = client.post(numberToDouble);
    Assert.assertEquals(response.getStatus(), 200);
    Assert.assertEquals(response.readEntity(Number.class).getNumber(), 50);
  }