Ejemplo n.º 1
0
  // 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");
  }
Ejemplo n.º 2
0
  @Test
  public void testOdata() throws Exception {
    String vdb =
        "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n"
            + "<vdb name=\"Loopy\" version=\"1\">\n"
            + "    <model name=\"MarketData\">\n"
            + "        <source name=\"text-connector2\" translator-name=\"loopback\" />\n"
            + "         <metadata type=\"DDL\"><![CDATA[\n"
            + "                CREATE FOREIGN TABLE G1 (e1 string, e2 integer PRIMARY KEY);\n"
            + "                CREATE FOREIGN TABLE G2 (e1 string, e2 integer PRIMARY KEY) 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://*****:*****@mm://localhost:31000;user=user;password=user", null);

    PreparedStatement ps =
        conn.prepareCall(
            "select t.* from xmltable('/*:Edmx/*:DataServices/*:Schema[@Alias=\"MarketData\"]' passing xmlparse(document cast(? as clob))) as t");
    ps.setAsciiStream(1, (InputStream) response.getEntity());

    ResultSet rs = ps.executeQuery();
    rs.next();

    assertEquals(
        ObjectConverterUtil.convertFileToString(
            UnitTestUtil.getTestDataFile("loopy-metadata4-results.txt")),
        rs.getString(1));

    conn.close();

    // try an invalid url
    client = WebClient.create("http://localhost:8080/odata/x/y$metadata");
    client.header(
        "Authorization",
        "Basic " + Base64.encodeBytes(("user:user").getBytes())); // $NON-NLS-1$ //$NON-NLS-2$
    response = client.invoke("GET", null);
    assertEquals(500, response.getStatus());

    admin.undeploy("loopy-vdb.xml");
  }
Ejemplo n.º 3
0
 private void doSetHeader(RuntimeDelegate rd, String name, Object value) {
   HeaderDelegate<Object> hd = HttpUtils.getHeaderDelegate(rd, value);
   if (hd != null) {
     value = hd.toString(value);
   }
   webClient.header(name, value);
 }
  public void handleMessage(Message message) throws Fault {
    SecurityContext context = message.get(SecurityContext.class);
    if (context == null) {
      return;
    }
    Principal principal = context.getUserPrincipal();
    UsernameToken usernameToken = (UsernameToken) message.get(SecurityToken.class);
    if (principal == null
        || usernameToken == null
        || !principal.getName().equals(usernameToken.getName())) {
      return;
    }

    // Read the user from Syncope and get the roles
    WebClient client =
        WebClient.create(address, Collections.singletonList(new JacksonJsonProvider()));

    String authorizationHeader =
        "Basic "
            + Base64Utility.encode(
                (usernameToken.getName() + ":" + usernameToken.getPassword()).getBytes());

    client.header("Authorization", authorizationHeader);

    client = client.path("users/self");
    UserTO user = null;
    try {
      user = client.get(UserTO.class);
      if (user == null) {
        Exception exception = new Exception("Authentication failed");
        throw new Fault(exception);
      }
    } catch (RuntimeException ex) {
      if (log.isDebugEnabled()) {
        log.debug(ex.getMessage(), ex);
      }
      throw new Fault(ex);
    }

    // Now get the roles
    List<MembershipTO> membershipList = user.getMemberships();
    Subject subject = new Subject();
    subject.getPrincipals().add(principal);
    for (MembershipTO membership : membershipList) {
      String roleName = membership.getRoleName();
      subject.getPrincipals().add(new SimpleGroup(roleName, usernameToken.getName()));
    }
    subject.setReadOnly();

    message.put(SecurityContext.class, new DefaultSecurityContext(principal, subject));
  }
Ejemplo n.º 5
0
 @Override
 public Builder cookie(String name, String value) {
   webClient.header(HttpHeaders.COOKIE, name + "=" + value);
   return this;
 }
Ejemplo n.º 6
0
 @Override
 public Builder cacheControl(CacheControl control) {
   webClient.header(HttpHeaders.CACHE_CONTROL, control.toString());
   return this;
 }