use of io.jans.as.model.uma.UmaResourceResponse in project jans by JanssenProject.
the class RegisterResourceFlowHttpTest method registerResourceWithScopeExpression.
public String registerResourceWithScopeExpression(String scopeExpression) throws Exception {
try {
UmaResource resource = new UmaResource();
resource.setName("Photo Album");
resource.setIconUri("http://www.example.com/icons/flower.png");
resource.setScopeExpression(scopeExpression);
resource.setType("myType");
UmaResourceResponse resourceStatus = getResourceService().addResource("Bearer " + pat.getAccessToken(), resource);
UmaTestUtil.assertIt(resourceStatus);
this.resourceIdWithScopeExpression = resourceStatus.getId();
return this.resourceIdWithScopeExpression;
} catch (ClientErrorException ex) {
System.err.println(ex.getResponse().readEntity(String.class));
throw ex;
}
}
use of io.jans.as.model.uma.UmaResourceResponse in project jans by JanssenProject.
the class RegisterResourceFlowHttpTest method registerResource.
public String registerResource(List<String> scopes) throws Exception {
try {
UmaResource resource = new UmaResource();
resource.setName("Photo Album");
resource.setIconUri("http://www.example.com/icons/flower.png");
resource.setScopes(scopes);
resource.setType("myType");
UmaResourceResponse resourceStatus = getResourceService().addResource("Bearer " + pat.getAccessToken(), resource);
UmaTestUtil.assertIt(resourceStatus);
this.resourceId = resourceStatus.getId();
return this.resourceId;
} catch (ClientErrorException ex) {
System.err.println(ex.getResponse().readEntity(String.class));
throw ex;
}
}
use of io.jans.as.model.uma.UmaResourceResponse in project jans by JanssenProject.
the class RegisterResourceFlowHttpTest method testModifyResourceWithInvalidPat.
/**
* Test UMA resource description modification with invalid PAT
*/
@Test(dependsOnMethods = { "modifyResource" })
public void testModifyResourceWithInvalidPat() throws Exception {
showTitle("testModifyResourceWithInvalidPat");
UmaResourceResponse resourceStatus = null;
try {
UmaResource resource = new UmaResource();
resource.setName("Photo Album 4");
resource.setIconUri("http://www.example.com/icons/flower.png");
resource.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view", "http://photoz.example.com/dev/scopes/all"));
resourceStatus = getResourceService().updateResource("Bearer " + pat.getAccessToken() + "_invalid", this.resourceId + "_invalid", resource);
} catch (ClientErrorException ex) {
System.err.println(ex.getResponse().readEntity(String.class));
assertEquals(ex.getResponse().getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "Unexpected response status");
}
assertNull(resourceStatus, "Resource status is not null");
}
use of io.jans.as.model.uma.UmaResourceResponse in project jans by JanssenProject.
the class TRegisterResource method registerResourceInternal.
private UmaResourceResponse registerResourceInternal(final Token pat, String umaRegisterResourcePath, final UmaResource resource) {
String path = umaRegisterResourcePath;
System.out.println("Path: " + path);
System.out.println("PAT: " + pat.getAccessToken());
Builder request = ResteasyClientBuilder.newClient().target(baseUri.toString() + path).request();
request.header("Accept", UmaConstants.JSON_MEDIA_TYPE);
request.header("Authorization", "Bearer " + pat.getAccessToken());
String json = null;
try {
// final String json = "{\"resource\":{\"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(resource);
json = ServerUtil.createJsonMapper().writeValueAsString(resource);
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 : TRegisterResource.registerResourceInternal() : ", response, entity);
assertEquals(response.getStatus(), Response.Status.CREATED.getStatusCode(), "Unexpected response code.");
registerStatus = TUma.readJsonValue(entity, UmaResourceResponse.class);
UmaTestUtil.assertIt(registerStatus);
return registerStatus;
}
use of io.jans.as.model.uma.UmaResourceResponse in project jans by JanssenProject.
the class UmaRegisterResourceWSTest method testModifyResource.
@Test(dependsOnMethods = { "testRegisterResource" })
public void testModifyResource() throws Exception {
final UmaResource resource = new UmaResource();
resource.setName("Server Photo Album 2");
resource.setIconUri("http://www.example.com/icons/flower.png");
resource.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view", "http://photoz.example.com/dev/scopes/all"));
final UmaResourceResponse status = TUma.modifyResource(url, pat, umaRegisterResourcePath, resourceStatus.getId(), resource);
UmaTestUtil.assertIt(status);
}
Aggregations