Search in sources :

Example 11 with ClientResponseFailure

use of org.jboss.resteasy.client.ClientResponseFailure in project oxTrust by GluuFederation.

the class UmaPermissionService method registerUmaPermissions.

private String registerUmaPermissions(Token patToken, String resourceSetId, String umaScope) {
    String authorization = "Bearer " + patToken.getAccessToken();
    // Register permissions for resource set
    UmaPermission resourceSetPermissionRequest = new UmaPermission();
    resourceSetPermissionRequest.setResourceSetId(resourceSetId);
    resourceSetPermissionRequest.setScopes(Arrays.asList(umaScope));
    PermissionTicket resourceSetPermissionTicket = null;
    try {
        resourceSetPermissionTicket = this.resourceSetPermissionRegistrationService.registerResourceSetPermission(authorization, getHost(umaMetadataConfiguration.getIssuer()), resourceSetPermissionRequest);
    } catch (MalformedURLException ex) {
        log.error("Failed to determine host by URI", ex);
    } catch (ClientResponseFailure ex) {
        log.error("Failed to register permissions for resource set: '{}'", ex, resourceSetId);
    }
    if ((resourceSetPermissionTicket == null) || StringHelper.isEmpty(resourceSetPermissionTicket.getTicket())) {
        log.error("Resource set permission ticket is invalid");
        return null;
    }
    return resourceSetPermissionTicket.getTicket();
}
Also used : PermissionTicket(org.xdi.oxauth.model.uma.PermissionTicket) MalformedURLException(java.net.MalformedURLException) UmaPermission(org.xdi.oxauth.model.uma.UmaPermission) ClientResponseFailure(org.jboss.resteasy.client.ClientResponseFailure)

Example 12 with ClientResponseFailure

use of org.jboss.resteasy.client.ClientResponseFailure in project oxAuth by GluuFederation.

the class AccessProtectedResourceFlowHttpTest method testHostDetermineRptStatus2.

/**
     * Host determines RPT status
     */
@Test(dependsOnMethods = { "testRequesterAccessProtectedResourceWithEnoughPermissionsRpt" })
@Parameters({ "umaAmHost" })
public void testHostDetermineRptStatus2(final String umaAmHost) throws Exception {
    showTitle("testHostDetermineRptStatus2");
    // Determine RPT token to status
    RptIntrospectionResponse tokenStatusResponse = null;
    try {
        tokenStatusResponse = this.rptStatusService.requestRptStatus("Bearer " + m_pat.getAccessToken(), this.umaObtainRptTokenFlowHttpTest.rptToken, "");
    } catch (ClientResponseFailure ex) {
        System.err.println(ex.getResponse().getEntity(String.class));
        throw ex;
    }
    UmaTestUtil.assert_(tokenStatusResponse);
// Requester RPT has permission to access this resource set with scope http://photoz.example.com/dev/scopes/view. Hence host should allow him to download this resource.
}
Also used : RptIntrospectionResponse(org.xdi.oxauth.model.uma.RptIntrospectionResponse) ClientResponseFailure(org.jboss.resteasy.client.ClientResponseFailure) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 13 with ClientResponseFailure

use of org.jboss.resteasy.client.ClientResponseFailure 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 14 with ClientResponseFailure

use of org.jboss.resteasy.client.ClientResponseFailure in project oxAuth by GluuFederation.

the class RegisterResourceSetFlowHttpTest method testDeleteResourceSet.

/**
     * Test for deleting UMA resource set descriptions
     */
@Test(dependsOnMethods = { "testGetResourceSets" })
public void testDeleteResourceSet() throws Exception {
    showTitle("testDeleteResourceSet");
    ResourceSetRegistrationService resourceSetRegistrationService = UmaClientFactory.instance().createResourceSetRegistrationService(this.metadataConfiguration);
    // Delete resource set description
    boolean deleted = false;
    try {
        resourceSetRegistrationService.deleteResourceSet("Bearer " + m_pat.getAccessToken(), this.resourceSetId);
        deleted = true;
    } catch (ClientResponseFailure ex) {
        System.err.println(ex.getResponse().getEntity(String.class));
        throw ex;
    }
    assertTrue(deleted, "Failed to delete resource set description");
}
Also used : ResourceSetRegistrationService(org.xdi.oxauth.client.uma.ResourceSetRegistrationService) ClientResponseFailure(org.jboss.resteasy.client.ClientResponseFailure) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Example 15 with ClientResponseFailure

use of org.jboss.resteasy.client.ClientResponseFailure in project oxAuth by GluuFederation.

the class RegisterResourceSetFlowHttpTest method testGetResourceSets.

/**
     * Test for getting UMA resource set description
     */
@Test(dependsOnMethods = { "testGetOneResourceSet" })
public void testGetResourceSets() throws Exception {
    showTitle("testGetResourceSets");
    ResourceSetRegistrationService resourceSetRegistrationService = UmaClientFactory.instance().createResourceSetRegistrationService(this.metadataConfiguration);
    // Get list of resource set descriptions
    List<String> resourceSets = null;
    try {
        resourceSets = resourceSetRegistrationService.getResourceSetList("Bearer " + m_pat.getAccessToken(), "");
    } catch (ClientResponseFailure ex) {
        System.err.println(ex.getResponse().getEntity(String.class));
        throw ex;
    }
    assertNotNull(resourceSets, "Resource set descriptions is null");
    assertTrue(resourceSets.contains(this.resourceSetId), "Resource set descriptions list doesn't contain added resource set description");
}
Also used : ResourceSetRegistrationService(org.xdi.oxauth.client.uma.ResourceSetRegistrationService) ClientResponseFailure(org.jboss.resteasy.client.ClientResponseFailure) Test(org.testng.annotations.Test) BaseTest(org.xdi.oxauth.BaseTest)

Aggregations

ClientResponseFailure (org.jboss.resteasy.client.ClientResponseFailure)20 Test (org.testng.annotations.Test)17 BaseTest (org.xdi.oxauth.BaseTest)17 Parameters (org.testng.annotations.Parameters)9 ResourceSetRegistrationService (org.xdi.oxauth.client.uma.ResourceSetRegistrationService)7 RptIntrospectionResponse (org.xdi.oxauth.model.uma.RptIntrospectionResponse)5 ResourceSet (org.xdi.oxauth.model.uma.ResourceSet)4 ResourceSetResponse (org.xdi.oxauth.model.uma.ResourceSetResponse)4 PermissionTicket (org.xdi.oxauth.model.uma.PermissionTicket)3 RptAuthorizationRequest (org.xdi.oxauth.model.uma.RptAuthorizationRequest)3 RptAuthorizationResponse (org.xdi.oxauth.model.uma.RptAuthorizationResponse)3 UmaPermission (org.xdi.oxauth.model.uma.UmaPermission)3 CreateRptService (org.xdi.oxauth.client.uma.CreateRptService)2 PermissionRegistrationService (org.xdi.oxauth.client.uma.PermissionRegistrationService)2 RPTResponse (org.xdi.oxauth.model.uma.RPTResponse)2 MalformedURLException (java.net.MalformedURLException)1 UmaConfigurationService (org.xdi.oxauth.client.uma.UmaConfigurationService)1 ResourceSetWithId (org.xdi.oxauth.model.uma.ResourceSetWithId)1 UmaConfiguration (org.xdi.oxauth.model.uma.UmaConfiguration)1