Package org.jboss.resteasy.client.jaxrs

Examples of org.jboss.resteasy.client.jaxrs.ResteasyClient


      }
      finally
      {
         Thread.currentThread().setContextClassLoader(old);
      }
      ResteasyClient client = new ResteasyClientBuilder()
              .providerFactory(providerFactory)
              .connectionPoolSize(size)
              .hostnameVerification(policy)
              .trustStore(resourceMetadata.getTruststore())
              .keyStore(resourceMetadata.getClientKeystore(), resourceMetadata.getClientKeyPassword())
              .build();
      realmConfiguration.setClient(client);
      realmConfiguration.setAuthUrl(UriBuilder.fromUri(authUrl).queryParam("client_id", client_id));
      realmConfiguration.setCodeUrl(client.target(tokenUrl));
   }
View Full Code Here


   }

   @Test
   public void testBasic() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      ResteasyWebTarget target = client.target(generateURL("/test"));
      String val = target.request().get(String.class);
      Assert.assertEquals("hello world", val);
   }
View Full Code Here

   }

   @Test
   public void testUnhandledException() throws Exception
   {
      ResteasyClient client = new ResteasyClientBuilder().build();
      ResteasyWebTarget target = client.target(generateURL("/exception"));
      Response resp = target.request().get();
      Assert.assertEquals(500, resp.getStatus());
   }
View Full Code Here

      Assert.assertEquals(500, resp.getStatus());
   }

    @Test
    public void testChannelContext() throws Exception {
      ResteasyClient client = new ResteasyClientBuilder().build();
      ResteasyWebTarget target = client.target(generateURL("/context"));
      String val = target.request().get(String.class);
      Assert.assertNotNull(val);
      Assert.assertFalse(val.isEmpty());
    }
View Full Code Here

         token.audience(skeletonKeyConfig.getRealm());
         SkeletonKeyToken.Access realmAccess = new SkeletonKeyToken.Access();
         realmAccess.addRole(skeletonKeyConfig.getAdminRole());
         token.setRealmAccess(realmAccess);
         String tokenString = buildTokenString(realmPrivateKey, token);
         ResteasyClient client = new ResteasyClientBuilder()
                 .providerFactory(providers)
                 .hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.ANY)
                 .trustStore(resourceMetadata.getTruststore())
                 .keyStore(resourceMetadata.getClientKeystore(), resourceMetadata.getClientKeyPassword())
                 .build();
         try
         {
            for (String resource : skeletonKeyConfig.getResources())
            {
               try
               {
                  log.debug("logging out: " + resource);
                  WebTarget target = client.target(resource).path(ServletActionURLs.J_OAUTH_REMOTE_LOGOUT);
                  if (username != null) target = target.queryParam("user", username);
                  javax.ws.rs.core.Response response = target.request()
                          .header("Authorization", "Bearer " + tokenString)
                          .put(null);
                  if (response.getStatus() != 204) log.error("Failed to log out");
                  response.close();
               }
               catch (Exception ignored)
               {
                  log.error("Failed to log out", ignored);
               }
            }
         }
         finally
         {
            client.close();
         }
      }
   }
View Full Code Here

      // You really should come up with a better way to initialize
      // and obtain the ServletOAuthClient.  I actually suggest downloading the ServletOAuthClient code
      // and take a look how it works.
      ServletOAuthClient oAuthClient = (ServletOAuthClient)request.getServletContext().getAttribute(ServletOAuthClient.class.getName());
      String token = oAuthClient.getBearerToken(request);
      ResteasyClient client = new ResteasyClientBuilder()
                 .trustStore(oAuthClient.getTruststore())
                 .hostnameVerification(ResteasyClientBuilder.HostnameVerificationPolicy.ANY).build();
      try
      {
         // invoke without the Authorization header
         Response response = client.target("https://localhost:8443/database/products").request().get();
         response.close();
         if (response.getStatus() != 401)
         {
            response.close();
            client.close();
            throw new RuntimeException("Expecting an auth status code: " + response.getStatus());
         }
      }
      finally
      {
      }
      try
      {
         Response response = client.target("https://localhost:8443/database/products").request()
                 .header(HttpHeaders.AUTHORIZATION, "Bearer " + token).get();
         return response.readEntity(new GenericType<List<String>>(){});
      }
      finally
      {
         client.close();
      }
   }
View Full Code Here

   public void testAuth() throws Exception
   {
      // Use our own providerFactory to test json context provider
      ResteasyProviderFactory providerFactory = new ResteasyProviderFactory();
      RegisterBuiltin.register(providerFactory);
      ResteasyClient client = new ResteasyClientBuilder().providerFactory(providerFactory).build();
      WebTarget target = client.target(generateBaseUrl());
      SkeletonKeyAdminClient admin = new SkeletonKeyClientBuilder().username("wburke").password("geheim").idp(target).admin();

      StoredUser newUser = new StoredUser();
      newUser.setName("John Smith");
      newUser.setUsername("jsmith");
      newUser.setEnabled(true);
      Map creds = new HashMap();
      creds.put("password", "foobar");
      newUser.setCredentials(creds);
      Response response = admin.users().create(newUser);
      User user = response.readEntity(User.class);
      response = admin.roles().create("user");
      Role role = response.readEntity(Role.class);
      Projects projects = admin.projects().query("Skeleton Key");
      Project project = projects.getList().get(0);
      admin.projects().addUserRole(project.getId(), user.getId(), role.getId());

      admin = new SkeletonKeyClientBuilder().username("jsmith").password("foobar").idp(target).admin();
      response = admin.roles().create("error");
      Assert.assertEquals(403, response.getStatus());
      client.close();
   }
View Full Code Here

   public void testSignedAuth() throws Exception
   {
      // Use our own providerFactory to test json context provider
      ResteasyProviderFactory providerFactory = new ResteasyProviderFactory();
      RegisterBuiltin.register(providerFactory);
      ResteasyClient client = new ResteasyClientBuilder().providerFactory(providerFactory).build();
      WebTarget target = client.target(generateBaseUrl());
      SkeletonKeyAdminClient admin = new SkeletonKeyClientBuilder().username("wburke").password("geheim").idp(target).admin();

      StoredUser newUser = new StoredUser();
      newUser.setName("John Smith");
      newUser.setUsername("jsmith");
      newUser.setEnabled(true);
      Map creds = new HashMap();
      creds.put("password", "foobar");
      newUser.setCredentials(creds);
      Response response = admin.users().create(newUser);
      User user = response.readEntity(User.class);
      response = admin.roles().create("user");
      Role role = response.readEntity(Role.class);
      Projects projects = admin.projects().query("Skeleton Key");
      Project project = projects.getList().get(0);
      admin.projects().addUserRole(project.getId(), user.getId(), role.getId());

      String signed = new SkeletonKeyClientBuilder().username("jsmith").password("foobar").idp(target).obtainSignedToken("Skeleton Key");
      System.out.println(signed);
      PKCS7SignatureInput input = new PKCS7SignatureInput(signed);
      input.setCertificate(certificate);
      Assert.assertTrue(input.verify());
      client.close();
   }
View Full Code Here

   public void testNotAuthenticated()
   {
      {
         // assuming @RolesAllowed is on class level. Too lazy to test it all!
         String newUser = "{ \"user\" : { \"username\" : \"wburke\", \"name\" : \"Bill Burke\", \"email\" : \"bburke@redhat.com\", \"enabled\" : true, \"credentials\" : { \"password\" : \"geheim\" }} }";
         ResteasyClient client = new ResteasyClientBuilder().providerFactory(deployment.getProviderFactory()).build();
         Response response = client.target(generateURL("/users")).request().post(Entity.json(newUser));
         Assert.assertEquals(response.getStatus(), 403);
         response.close();
         client.close();
      }
      {
         String newRole = "{ \"role\" : { \"name\" : \"admin\"} }";
         ResteasyClient client = new ResteasyClientBuilder().providerFactory(deployment.getProviderFactory()).build();
         Response response = client.target(generateURL("/roles")).request().post(Entity.json(newRole));
         Assert.assertEquals(response.getStatus(), 403);
         response.close();
         client.close();

      }
      {
         String newProject = "{ \"project\" : { \"id\" : \"5\", \"name\" : \"Resteasy\", \"description\" : \"The Best of REST\", \"enabled\" : true } }";
         ResteasyClient client = new ResteasyClientBuilder().providerFactory(deployment.getProviderFactory()).build();
         Response response = client.target(generateURL("/projects")).request().post(Entity.json(newProject));
         Assert.assertEquals(response.getStatus(), 403);
         response.close();
         client.close();
      }
   }
View Full Code Here

   @Test
   public void testCMD() throws Exception
   {
      Authentication auth = new SkeletonKeyClientBuilder().username("wburke").password("geheim").authentication("Skeleton Key");
      ResteasyClient client = new ResteasyClientBuilder().build();
      WebTarget target = client.target(generateBaseUrl());
      Mappers.registerContextResolver(client);
      String tiny = target.path("tokens").path("url").request().post(Entity.json(auth), String.class);
      System.out.println(tiny);
      System.out.println("tiny.size: " + tiny.length());
      Security.addProvider(new BouncyCastleProvider());


      KeyPair keyPair = KeyPairGenerator.getInstance("RSA", "BC").generateKeyPair();
      PrivateKey privateKey = keyPair.getPrivate();
      X509Certificate cert = KeyTools.generateTestCertificate(keyPair);

      byte[] signed = p7s(privateKey, cert, null, tiny.getBytes());


      CMSSignedData data = new CMSSignedData(signed);
      byte[] bytes = (byte[])data.getSignedContent().getContent();
      System.out.println("BYTES: " + new String(bytes));
      System.out.println("size:" + signed.length);
      System.out.println("Base64.size: " + Base64.encodeBytes(signed).length());

      SignerInformation signer = (SignerInformation)data.getSignerInfos().getSigners().iterator().next();
      System.out.println("valid: " + signer.verify(cert, "BC"));
      client.close();


   }
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.client.jaxrs.ResteasyClient

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.