use of org.gluu.oxauth.model.uma.PermissionTicket in project oxAuth by GluuFederation.
the class TRegisterPermission method registerPermission.
public PermissionTicket registerPermission(final Token p_pat, 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());
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 org.gluu.oxauth.model.uma.PermissionTicket in project oxAuth by GluuFederation.
the class RegisterPermissionWSTest method testRegisterPermissionWithInvalidResource.
@Test(dependsOnMethods = { "testRegisterPermission" })
public void testRegisterPermissionWithInvalidResource() {
final String path = umaPermissionPath;
try {
Builder request = ResteasyClientBuilder.newClient().target(url.toString() + path).request();
request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
request.header("Authorization", "Bearer " + pat.getAccessToken());
String json = null;
try {
final UmaPermission r = new UmaPermission();
r.setResourceId(resource.getId() + "x");
json = ServerUtil.createJsonMapper().writeValueAsString(r);
} catch (IOException e) {
e.printStackTrace();
fail();
}
Response response = request.post(Entity.json(json));
String entity = response.readEntity(String.class);
BaseTest.showResponse("UMA : RegisterPermissionWSTest.testRegisterPermissionWithInvalidResource() : ", response, entity);
assertEquals(response.getStatus(), Response.Status.NOT_FOUND.getStatusCode(), "Unexpected response code.");
try {
final PermissionTicket t = ServerUtil.createJsonMapper().readValue(entity, PermissionTicket.class);
Assert.assertNull(t);
} catch (Exception e) {
// it's ok if it fails here, we expect ticket as null.
}
} catch (Exception e) {
e.printStackTrace();
fail();
}
}
Aggregations