use of org.gluu.oxauth.model.uma.UmaResourceResponse in project oxAuth by GluuFederation.
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.assert_(resourceStatus);
this.resourceIdWithScopeExpression = resourceStatus.getId();
return this.resourceIdWithScopeExpression;
} catch (ClientErrorException ex) {
System.err.println(ex.getResponse().readEntity(String.class));
throw ex;
}
}
use of org.gluu.oxauth.model.uma.UmaResourceResponse in project oxAuth by GluuFederation.
the class RegisterResourceFlowHttpTest method modifyResource.
/**
* Resource modification
*/
@Test(dependsOnMethods = { "addResource" })
public void modifyResource() throws Exception {
showTitle("modifyResource");
// Modify resource description
UmaResourceResponse resourceStatus = null;
try {
UmaResource resource = new UmaResource();
resource.setName("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"));
resource.setType("myType");
resourceStatus = getResourceService().updateResource("Bearer " + pat.getAccessToken(), this.resourceId, resource);
} catch (ClientErrorException ex) {
System.err.println(ex.getResponse().readEntity(String.class));
throw ex;
}
try {
UmaResource resource = new UmaResource();
resource.setName("Photo Album 2");
resource.setIconUri("http://www.example.com/icons/flower.png");
resource.setScopeExpression(MODIFY_SCOPE_EXPRESSION);
resource.setType("myType");
resourceStatus = getResourceService().updateResource("Bearer " + pat.getAccessToken(), this.resourceIdWithScopeExpression, resource);
} catch (ClientErrorException ex) {
System.err.println(ex.getResponse().readEntity(String.class));
throw ex;
}
assertNotNull(resourceStatus, "Resource status is null");
assertNotNull(this.resourceId, "Resource description id is null");
}
use of org.gluu.oxauth.model.uma.UmaResourceResponse in project oxAuth by GluuFederation.
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.assert_(resourceStatus);
this.resourceId = resourceStatus.getId();
return this.resourceId;
} catch (ClientErrorException ex) {
System.err.println(ex.getResponse().readEntity(String.class));
throw ex;
}
}
use of org.gluu.oxauth.model.uma.UmaResourceResponse in project oxAuth by GluuFederation.
the class TRegisterResource method registerResourceInternal.
private UmaResourceResponse registerResourceInternal(final Token pat, String umaRegisterResourcePath, final UmaResource resource) throws Exception {
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.assert_(registerStatus);
return registerStatus;
}
use of org.gluu.oxauth.model.uma.UmaResourceResponse in project oxAuth by GluuFederation.
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");
}
Aggregations