Package org.jboss.resteasy.skeleton.key.representations

Examples of org.jboss.resteasy.skeleton.key.representations.AccessTokenResponse


      form.param("grant_type", "authorization_code")
              .param("code", code)
              .param("redirect_uri", redirectUri);

      Response res = realmInfo.getCodeUrl().request().header(HttpHeaders.AUTHORIZATION, authHeader).post(Entity.form(form));
      AccessTokenResponse tokenResponse;
      try
      {
         if (res.getStatus() != 200)
         {
            log.error("failed to turn code into token");
            sendError(Response.Status.FORBIDDEN.getStatusCode());
            return false;
         }
         log.debug("media type: " + res.getMediaType());
         log.debug("Content-Type header: " + res.getHeaderString("Content-Type"));
         tokenResponse = res.readEntity(AccessTokenResponse.class);
      }
      finally
      {
         res.close();
      }

      tokenString = tokenResponse.getToken();
      try
      {
         token = RSATokenVerifier.verifyToken(tokenString, realmInfo.getMetadata());
         log.debug("Verification succeeded!");
      }
View Full Code Here


         }
         else if (res.getStatus() != 200)
         {
            throw new InternalServerErrorException(new Exception("Unknown error when getting acess token"));
         }
         AccessTokenResponse tokenResponse = res.readEntity(AccessTokenResponse.class);
         return tokenResponse.getToken();
      }
      finally
      {
         res.close();
      }
View Full Code Here

            {
               codeRoles.remove(role);
            }
         }
      }
      AccessTokenResponse res = accessTokenResponse(realmPrivateKey, accessCode.getToken());
      response.setStatus(200);
      response.setContentType("application/json");
      accessTokenResponseWriter.writeValue(response.getOutputStream(), res);
      response.getOutputStream().flush();
   }
View Full Code Here

   protected AccessTokenResponse accessTokenResponse(PrivateKey privateKey, SkeletonKeyToken token)
   {
      String encodedToken = buildTokenString(privateKey, token);

      AccessTokenResponse res = new AccessTokenResponse();
      res.setToken(encodedToken);
      res.setTokenType("bearer");
      if (token.getExpiration() != 0)
      {
         long time = token.getExpiration() - (System.currentTimeMillis() / 1000);
         res.setExpiresIn(time);
      }
      return res;
   }
View Full Code Here

         return;
      }
      GenericPrincipal gp = basicAuth(request, response);
      if (gp == null) return;
      SkeletonKeyToken token = buildToken(gp);
      AccessTokenResponse res = accessTokenResponse(realmPrivateKey, token);
      response.setStatus(200);
      response.setContentType("application/json");
      accessTokenResponseWriter.writeValue(response.getOutputStream(), res);
      response.getOutputStream().flush();
   }
View Full Code Here

         Map<String, String> res = new HashMap<String, String>();
         res.put("error", "invalid_grant");
         res.put("error_description", "Auth error");
         return Response.status(Response.Status.BAD_REQUEST).type(MediaType.APPLICATION_JSON_TYPE).entity(res).build();
      }
      AccessTokenResponse res = accessTokenResponse(realm.getPrivateKey(), accessCode.getToken());
      return Response.ok(res).build();

   }
View Full Code Here

      }
      String encodedToken = new JWSBuilder()
              .content(tokenBytes)
              .rsa256(privateKey);

      AccessTokenResponse res = new AccessTokenResponse();
      res.setToken(encodedToken);
      res.setTokenType("bearer");
      if (token.getExpiration() != 0)
      {
         long time = token.getExpiration() - (System.currentTimeMillis() / 1000);
         res.setExpiresIn(time);
      }
      return res;
   }
View Full Code Here

      if (res.getStatus() == 400)
      {
         System.out.println(res.readEntity(String.class));
      }
      Assert.assertEquals(200, res.getStatus());
      AccessTokenResponse tokenResponse = res.readEntity(AccessTokenResponse.class);
      res.close();

      ResourceMetadata metadata = new ResourceMetadata();
      metadata.setRealm("test-realm");
      metadata.setResourceName("Application");
      metadata.setRealmKey(realmInfo.getPublicKey());
      SkeletonKeyToken token = RSATokenVerifier.verifyToken(tokenResponse.getToken(), metadata);
      Assert.assertEquals(token.getPrincipal(), "wburke");
      Assert.assertTrue(token.getResourceAccess("Application").getRoles().contains("user"));
   }
View Full Code Here

      if (res.getStatus() == 400)
      {
         System.out.println(res.readEntity(String.class));
      }
      Assert.assertEquals(200, res.getStatus());
      AccessTokenResponse tokenResponse = res.readEntity(AccessTokenResponse.class);
      res.close();

      ResourceMetadata metadata = new ResourceMetadata();
      metadata.setRealm("test-realm");
      metadata.setResourceName("Application");
      metadata.setRealmKey(realmInfo.getPublicKey());
      SkeletonKeyToken token = RSATokenVerifier.verifyToken(tokenResponse.getToken(), metadata);
      Assert.assertEquals(token.getPrincipal(), "wburke");
      Assert.assertTrue(token.getResourceAccess("Application").getRoles().contains("user"));
   }
View Full Code Here

      Response response = client.target(realmInfo.getGrantUrl()).request().post(Entity.form(form));
      if (response.getStatus() != 200)
      {
         Assert.fail(response.readEntity(String.class));
      }
      AccessTokenResponse tokenResponse = response.readEntity(AccessTokenResponse.class);
      Assert.assertEquals("bearer", tokenResponse.getTokenType());
      ResourceMetadata metadata = new ResourceMetadata();
      metadata.setRealm("test-realm");
      metadata.setResourceName("Application");
      metadata.setRealmKey(realmInfo.getPublicKey());
      SkeletonKeyToken token = RSATokenVerifier.verifyToken(tokenResponse.getToken(), metadata);


   }
View Full Code Here

TOP

Related Classes of org.jboss.resteasy.skeleton.key.representations.AccessTokenResponse

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.