Search in sources :

Example 1 with UmaResourceResponse

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

Example 2 with UmaResourceResponse

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

Example 3 with UmaResourceResponse

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

Example 4 with UmaResourceResponse

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

Example 5 with UmaResourceResponse

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);
}
Also used : UmaResourceResponse(io.jans.as.model.uma.UmaResourceResponse) UmaResource(io.jans.as.model.uma.UmaResource) Test(org.testng.annotations.Test) BaseTest(io.jans.as.server.BaseTest)

Aggregations

UmaResourceResponse (io.jans.as.model.uma.UmaResourceResponse)8 UmaResource (io.jans.as.model.uma.UmaResource)6 ClientErrorException (javax.ws.rs.ClientErrorException)4 Test (org.testng.annotations.Test)3 BaseTest (io.jans.as.client.BaseTest)2 Builder (javax.ws.rs.client.Invocation.Builder)2 Response (javax.ws.rs.core.Response)2 ResteasyClientBuilder (org.jboss.resteasy.client.jaxrs.ResteasyClientBuilder)2 BaseTest (io.jans.as.server.BaseTest)1 Condition (io.jans.ca.rs.protect.Condition)1