Search in sources :

Example 1 with UmaResource

use of io.jans.as.model.uma.UmaResource 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 UmaResource

use of io.jans.as.model.uma.UmaResource 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 UmaResource

use of io.jans.as.model.uma.UmaResource 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 UmaResource

use of io.jans.as.model.uma.UmaResource 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)

Example 5 with UmaResource

use of io.jans.as.model.uma.UmaResource in project jans by JanssenProject.

the class RsModifyOperation method getResource.

private UmaResource getResource(UmaResourceService resourceService, RsModifyParams params, String resourceId) {
    String pat = getUmaTokenService().getPat(params.getRpId()).getToken();
    UmaResourceWithId umaResourceWithId = resourceService.getResource("Bearer " + pat, resourceId);
    UmaResource umaResource = new UmaResource();
    umaResource.setDescription(umaResourceWithId.getDescription());
    umaResource.setIat(umaResourceWithId.getIat());
    umaResource.setIconUri(umaResourceWithId.getIconUri());
    umaResource.setName(umaResourceWithId.getName());
    umaResource.setScopes(params.getScopes());
    umaResource.setScopeExpression(null);
    umaResource.setType(umaResourceWithId.getType());
    if (!Strings.isNullOrEmpty(params.getScopeExpression()) && !params.getScopeExpression().equals("null")) {
        umaResource.setScopeExpression(params.getScopeExpression());
        umaResource.setScopes(JsonLogicNodeParser.parseNode(params.getScopeExpression().toString()).getData());
    }
    return umaResource;
}
Also used : UmaResourceWithId(io.jans.as.model.uma.UmaResourceWithId) UmaResource(io.jans.as.model.uma.UmaResource)

Aggregations

UmaResource (io.jans.as.model.uma.UmaResource)9 UmaResourceResponse (io.jans.as.model.uma.UmaResourceResponse)6 ClientErrorException (javax.ws.rs.ClientErrorException)6 Test (org.testng.annotations.Test)4 BaseTest (io.jans.as.client.BaseTest)3 UmaResourceService (io.jans.as.client.uma.UmaResourceService)1 UmaMetadata (io.jans.as.model.uma.UmaMetadata)1 UmaResourceWithId (io.jans.as.model.uma.UmaResourceWithId)1 BaseTest (io.jans.as.server.BaseTest)1 Condition (io.jans.ca.rs.protect.Condition)1 PatProvider (io.jans.ca.rs.protect.resteasy.PatProvider)1 HttpException (io.jans.ca.server.HttpException)1 Rp (io.jans.ca.server.service.Rp)1 WebApplicationException (javax.ws.rs.WebApplicationException)1