Search in sources :

Example 1 with ResourceSetResponse

use of org.xdi.oxauth.model.uma.ResourceSetResponse in project oxAuth by GluuFederation.

the class RegisterResourceSetFlowHttpTest method testModifyResourceSet.

/**
     * Test UMA resource set description modification
     */
@Test(dependsOnMethods = { "testRegisterResourceSet" })
public void testModifyResourceSet() throws Exception {
    showTitle("testModifyResourceSet");
    ResourceSetRegistrationService resourceSetRegistrationService = UmaClientFactory.instance().createResourceSetRegistrationService(this.metadataConfiguration);
    // Modify resource set description
    ResourceSetResponse resourceSetStatus = null;
    try {
        ResourceSet resourceSet = new ResourceSet();
        resourceSet.setName("Photo Album 2");
        resourceSet.setIconUri("http://www.example.com/icons/flower.png");
        resourceSet.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view", "http://photoz.example.com/dev/scopes/all"));
        resourceSetStatus = resourceSetRegistrationService.updateResourceSet("Bearer " + m_pat.getAccessToken(), this.resourceSetId, resourceSet);
    } catch (ClientResponseFailure ex) {
        System.err.println(ex.getResponse().getEntity(String.class));
        throw ex;
    }
    assertNotNull(resourceSetStatus, "Resource set status is null");
    this.resourceSetId = resourceSetStatus.getId();
    assertNotNull(this.resourceSetId, "Resource set description id is null");
}
Also used : ResourceSetRegistrationService(org.xdi.oxauth.client.uma.ResourceSetRegistrationService) ResourceSetResponse(org.xdi.oxauth.model.uma.ResourceSetResponse) ResourceSet(org.xdi.oxauth.model.uma.ResourceSet) ClientResponseFailure(org.jboss.resteasy.client.ClientResponseFailure) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 2 with ResourceSetResponse

use of org.xdi.oxauth.model.uma.ResourceSetResponse in project oxAuth by GluuFederation.

the class RegisterResourceSetWSTest method testModifyResourceSet.

@Test(dependsOnMethods = { "testRegisterResourceSet" })
public void testModifyResourceSet() throws Exception {
    final ResourceSet resourceSet = new ResourceSet();
    resourceSet.setName("Server Photo Album 2");
    resourceSet.setIconUri("http://www.example.com/icons/flower.png");
    resourceSet.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view", "http://photoz.example.com/dev/scopes/all"));
    final ResourceSetResponse status = TUma.modifyResourceSet(url, pat, umaRegisterResourcePath, resourceSetStatus.getId(), resourceSet);
    UmaTestUtil.assert_(status);
}
Also used : ResourceSetResponse(org.xdi.oxauth.model.uma.ResourceSetResponse) ResourceSet(org.xdi.oxauth.model.uma.ResourceSet) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 3 with ResourceSetResponse

use of org.xdi.oxauth.model.uma.ResourceSetResponse in project oxAuth by GluuFederation.

the class ResourceSetRegistrationWS method putResourceSetImpl.

private Response putResourceSetImpl(Response.Status status, String authorization, String rsid, ResourceSet resourceSet) throws IllegalAccessException, InvocationTargetException, IOException {
    log.trace("putResourceSetImpl, rsid: {}, status:", rsid, status.name());
    String patToken = tokenService.getTokenFromAuthorizationParameter(authorization);
    AuthorizationGrant authorizationGrant = authorizationGrantList.getAuthorizationGrantByAccessToken(patToken);
    String userDn = authorizationGrant.getUserDn();
    String clientDn = authorizationGrant.getClientDn();
    final String resourceSetDn;
    if (status == Response.Status.CREATED) {
        resourceSetDn = addResourceSet(rsid, resourceSet, userDn, clientDn);
    } else {
        resourceSetDn = updateResourceSet(rsid, resourceSet);
    }
    // Load resource set description
    org.xdi.oxauth.model.uma.persistence.ResourceSet ldapUpdatedResourceSet = resourceSetService.getResourceSetByDn(resourceSetDn);
    ResourceSetResponse response = new ResourceSetResponse();
    response.setId(ldapUpdatedResourceSet.getId());
    return Response.status(status).entity(ServerUtil.asJson(response)).build();
}
Also used : ResourceSetResponse(org.xdi.oxauth.model.uma.ResourceSetResponse) AuthorizationGrant(org.xdi.oxauth.model.common.AuthorizationGrant)

Example 4 with ResourceSetResponse

use of org.xdi.oxauth.model.uma.ResourceSetResponse in project oxAuth by GluuFederation.

the class RegisterResourceSetFlowHttpTest method testModifyResourceSetWithInvalidPat.

/**
     * Test UMA resource set description modification with invalid PAT
     */
@Test(dependsOnMethods = { "testModifyResourceSet" })
public void testModifyResourceSetWithInvalidPat() throws Exception {
    showTitle("testModifyResourceSetWithInvalidPat");
    ResourceSetRegistrationService resourceSetRegistrationService = UmaClientFactory.instance().createResourceSetRegistrationService(this.metadataConfiguration);
    // Modify resource set description with invalid PAT
    ResourceSetResponse resourceSetStatus = null;
    try {
        ResourceSet resourceSet = new ResourceSet();
        resourceSet.setName("Photo Album 4");
        resourceSet.setIconUri("http://www.example.com/icons/flower.png");
        resourceSet.setScopes(Arrays.asList("http://photoz.example.com/dev/scopes/view", "http://photoz.example.com/dev/scopes/all"));
        resourceSetStatus = resourceSetRegistrationService.updateResourceSet("Bearer " + m_pat.getAccessToken() + "_invalid", this.resourceSetId + "_invalid", resourceSet);
    } catch (ClientResponseFailure ex) {
        System.err.println(ex.getResponse().getEntity(String.class));
        assertEquals(ex.getResponse().getStatus(), Response.Status.UNAUTHORIZED.getStatusCode(), "Unexpected response status");
    }
    assertNull(resourceSetStatus, "Resource set status is not null");
}
Also used : ResourceSetRegistrationService(org.xdi.oxauth.client.uma.ResourceSetRegistrationService) ResourceSetResponse(org.xdi.oxauth.model.uma.ResourceSetResponse) ResourceSet(org.xdi.oxauth.model.uma.ResourceSet) ClientResponseFailure(org.jboss.resteasy.client.ClientResponseFailure) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 5 with ResourceSetResponse

use of org.xdi.oxauth.model.uma.ResourceSetResponse in project oxAuth by GluuFederation.

the class RegisterResourceSetFlowHttpTest method registerResourceSet.

public String registerResourceSet(List<String> scopes) throws Exception {
    ResourceSetRegistrationService resourceSetRegistrationService = UmaClientFactory.instance().createResourceSetRegistrationService(this.metadataConfiguration);
    // Add resource set description
    ResourceSetResponse resourceSetStatus = null;
    try {
        ResourceSet resourceSet = new ResourceSet();
        resourceSet.setName("Photo Album");
        resourceSet.setIconUri("http://www.example.com/icons/flower.png");
        resourceSet.setScopes(scopes);
        resourceSetStatus = resourceSetRegistrationService.addResourceSet("Bearer " + m_pat.getAccessToken(), resourceSet);
    } catch (ClientResponseFailure ex) {
        System.err.println(ex.getResponse().getEntity(String.class));
        throw ex;
    }
    UmaTestUtil.assert_(resourceSetStatus);
    this.resourceSetId = resourceSetStatus.getId();
    return this.resourceSetId;
}
Also used : ResourceSetRegistrationService(org.xdi.oxauth.client.uma.ResourceSetRegistrationService) ResourceSetResponse(org.xdi.oxauth.model.uma.ResourceSetResponse) ResourceSet(org.xdi.oxauth.model.uma.ResourceSet) ClientResponseFailure(org.jboss.resteasy.client.ClientResponseFailure)

Aggregations

ResourceSetResponse (org.xdi.oxauth.model.uma.ResourceSetResponse)6 ResourceSet (org.xdi.oxauth.model.uma.ResourceSet)5 ClientResponseFailure (org.jboss.resteasy.client.ClientResponseFailure)4 Test (org.testng.annotations.Test)4 BaseTest (org.xdi.oxauth.BaseTest)4 ResourceSetRegistrationService (org.xdi.oxauth.client.uma.ResourceSetRegistrationService)4 AuthorizationGrant (org.xdi.oxauth.model.common.AuthorizationGrant)1