Search in sources :

Example 1 with UmaResourceResponse

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;
    }
}
Also used : UmaResourceResponse(org.gluu.oxauth.model.uma.UmaResourceResponse) ClientErrorException(javax.ws.rs.ClientErrorException) UmaResource(org.gluu.oxauth.model.uma.UmaResource)

Example 2 with UmaResourceResponse

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");
}
Also used : UmaResourceResponse(org.gluu.oxauth.model.uma.UmaResourceResponse) ClientErrorException(javax.ws.rs.ClientErrorException) UmaResource(org.gluu.oxauth.model.uma.UmaResource) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Example 3 with UmaResourceResponse

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;
    }
}
Also used : UmaResourceResponse(org.gluu.oxauth.model.uma.UmaResourceResponse) ClientErrorException(javax.ws.rs.ClientErrorException) UmaResource(org.gluu.oxauth.model.uma.UmaResource)

Example 4 with UmaResourceResponse

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;
}
Also used : Response(javax.ws.rs.core.Response) UmaResourceResponse(org.gluu.oxauth.model.uma.UmaResourceResponse) UmaResourceResponse(org.gluu.oxauth.model.uma.UmaResourceResponse) ResteasyClientBuilder(org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder) Builder(javax.ws.rs.client.Invocation.Builder)

Example 5 with UmaResourceResponse

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");
}
Also used : UmaResourceResponse(org.gluu.oxauth.model.uma.UmaResourceResponse) ClientErrorException(javax.ws.rs.ClientErrorException) UmaResource(org.gluu.oxauth.model.uma.UmaResource) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Aggregations

UmaResourceResponse (org.gluu.oxauth.model.uma.UmaResourceResponse)7 UmaResource (org.gluu.oxauth.model.uma.UmaResource)5 ClientErrorException (javax.ws.rs.ClientErrorException)4 BaseTest (org.gluu.oxauth.BaseTest)3 Test (org.testng.annotations.Test)3 Builder (javax.ws.rs.client.Invocation.Builder)2 Response (javax.ws.rs.core.Response)2 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)2