use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.
the class EndSessionRestWebServiceEmbeddedTest method requestEndSessionStep1.
@Parameters({ "registerPath", "redirectUris", "postLogoutRedirectUri" })
@Test
public void requestEndSessionStep1(final String registerPath, final String redirectUris, final String postLogoutRedirectUri) throws Exception {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + registerPath).request();
String registerRequestContent = null;
try {
RegisterRequest registerRequest = new RegisterRequest(ApplicationType.WEB, "oxAuth test app", StringUtils.spaceSeparatedToList(redirectUris));
registerRequest.setResponseTypes(Arrays.asList(ResponseType.TOKEN, ResponseType.ID_TOKEN));
registerRequest.setPostLogoutRedirectUris(Arrays.asList(postLogoutRedirectUri));
registerRequest.setFrontChannelLogoutUris(Lists.newArrayList(postLogoutRedirectUri));
registerRequest.addCustomAttribute("oxAuthTrustedClient", "true");
registerRequestContent = registerRequest.getJSONParameters().toString(4);
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage());
}
Response response = request.post(Entity.json(registerRequestContent));
String entity = response.readEntity(String.class);
showResponse("requestEndSessionStep1", response, entity);
assertEquals(response.getStatus(), 200, "Unexpected response code. " + entity);
assertNotNull(entity, "Unexpected result: " + entity);
try {
final RegisterResponse registerResponse = RegisterResponse.valueOf(entity);
ClientTestUtil.assert_(registerResponse);
JSONObject jsonObj = new JSONObject(entity);
assertTrue(jsonObj.has(CLIENT_ID.toString()));
clientId = jsonObj.getString(CLIENT_ID.toString());
} catch (JSONException e) {
e.printStackTrace();
fail(e.getMessage() + "\nResponse was: " + entity);
}
}
use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.
the class OpenIDRequestObjectEmbeddedTest method requestParameterMethodFail4.
@Parameters({ "authorizePath", "userId", "userSecret", "redirectUri" })
@Test(dependsOnMethods = "dynamicClientRegistration")
public void requestParameterMethodFail4(final String authorizePath, final String userId, final String userSecret, final String redirectUri) throws Exception {
final String state = UUID.randomUUID().toString();
Builder request = null;
try {
List<ResponseType> responseTypes = Arrays.asList(ResponseType.TOKEN);
List<String> scopes = Arrays.asList("openid");
String nonce = UUID.randomUUID().toString();
AuthorizationRequest authorizationRequest = new AuthorizationRequest(responseTypes, clientId, scopes, redirectUri, nonce);
authorizationRequest.setState(state);
authorizationRequest.getPrompts().add(Prompt.NONE);
authorizationRequest.setAuthUsername(userId);
authorizationRequest.setAuthPassword(userSecret);
OxAuthCryptoProvider cryptoProvider = new OxAuthCryptoProvider();
JwtAuthorizationRequest jwtAuthorizationRequest = new JwtAuthorizationRequest(authorizationRequest, SignatureAlgorithm.HS256, clientSecret, cryptoProvider);
jwtAuthorizationRequest.addIdTokenClaim(new Claim(JwtClaimName.SUBJECT_IDENTIFIER, ClaimValue.createSingleValue("INVALID_USER_ID")));
String authJwt = jwtAuthorizationRequest.getEncodedJwt();
authorizationRequest.setRequest(authJwt);
System.out.println("Request JWT: " + authJwt);
request = ResteasyClientBuilder.newClient().target(url.toString() + authorizePath + "?" + authorizationRequest.getQueryString()).request();
request.header("Authorization", "Basic " + authorizationRequest.getEncodedCredentials());
request.header("Accept", MediaType.TEXT_PLAIN);
} catch (Exception e) {
fail(e.getMessage(), e);
}
Response response = request.get();
String entity = response.readEntity(String.class);
showResponse("requestParameterMethodFail4", response, entity);
assertEquals(response.getStatus(), 302, "Unexpected response code.");
assertNotNull(response.getLocation(), "Unexpected result: " + response.getLocation());
if (response.getLocation() != null) {
try {
URI uri = new URI(response.getLocation().toString());
assertNotNull(uri.getFragment(), "Fragment is null");
Map<String, String> params = QueryStringDecoder.decode(uri.getFragment());
assertNotNull(params.get("error"), "The error value is null");
assertNotNull(params.get("error_description"), "The errorDescription value is null");
assertNotNull(params.get(AuthorizeResponseParam.STATE), "The state is null");
assertEquals(params.get(AuthorizeResponseParam.STATE), state);
} catch (URISyntaxException e) {
e.printStackTrace();
fail("Response URI is not well formed");
}
}
}
use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.
the class TRegisterPermission method registerPermission.
public PermissionTicket registerPermission(final Token p_pat, final String p_umaAmHost, String p_umaHost, final UmaPermission p_request, String path) {
final Holder<PermissionTicket> ticketH = new Holder<PermissionTicket>();
Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + path).request();
request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
request.header("Authorization", "Bearer " + p_pat.getAccessToken());
request.header("Host", p_umaAmHost);
String json = null;
try {
json = ServerUtil.createJsonMapper().writeValueAsString(p_request);
} catch (Exception e) {
e.printStackTrace();
fail();
}
Response response = request.post(Entity.json(json));
String entity = response.readEntity(String.class);
BaseTest.showResponse("UMA : TRegisterPermission.registerPermission() : ", response, entity);
assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), "Unexpected response code.");
try {
final PermissionTicket t = ServerUtil.createJsonMapper().readValue(entity, PermissionTicket.class);
UmaTestUtil.assert_(t);
ticketH.setT(t);
} catch (IOException e) {
e.printStackTrace();
fail();
}
return ticketH.getT();
}
use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.
the class TRegisterResourceSet method registerResourceSetInternal.
private ResourceSetResponse registerResourceSetInternal(final Token p_pat, String umaRegisterResourcePath, final ResourceSet p_resourceSet) throws Exception {
String path = umaRegisterResourcePath;
System.out.println("Path: " + path);
System.out.println("PAT: " + p_pat.getAccessToken());
Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + path).request();
request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
request.header("Authorization", "Bearer " + p_pat.getAccessToken());
String json = null;
try {
// final String json = "{\"resourceSet\":{\"name\":\"Server Photo
// Album22\",\"iconUri\":\"http://www.example.com/icons/flower.png\",\"scopes\":[\"http://photoz.example.com/dev/scopes/view\",\"http://photoz.example.com/dev/scopes/all\"]}}";
// final String json =
// ServerUtil.jsonMapperWithWrapRoot().writeValueAsString(p_resourceSet);
json = ServerUtil.createJsonMapper().writeValueAsString(p_resourceSet);
System.out.println("Json: " + json);
} catch (Exception e) {
e.printStackTrace();
fail();
}
Response response = request.post(Entity.json(json));
String entity = response.readEntity(String.class);
BaseTest.showResponse("UMA : TRegisterResourceSet.registerResourceSetInternal() : ", response, entity);
assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), "Unexpected response code.");
registerStatus = TUma.readJsonValue(entity, ResourceSetResponse.class);
UmaTestUtil.assert_(registerStatus);
return registerStatus;
}
use of javax.ws.rs.client.Invocation.Builder in project oxAuth by GluuFederation.
the class TRegisterResourceSet method getResourceSetList.
public List<String> getResourceSetList(final Token p_pat, String p_umaRegisterResourcePath) {
final List<String> result = new ArrayList<String>();
try {
Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + p_umaRegisterResourcePath).request();
request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
request.header("Authorization", "Bearer " + p_pat.getAccessToken());
Response response = request.get();
String entity = response.readEntity(String.class);
BaseTest.showResponse("UMA : TRegisterResourceSet.getResourceSetList() : ", response, entity);
assertEquals(response.getStatus(), 200, "Unexpected response code.");
List<String> list = TUma.readJsonValue(entity, List.class);
if (list != null) {
result.addAll(list);
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
return result;
}
Aggregations