Search in sources :

Example 1 with UmaMetadataService

use of org.gluu.oxauth.client.uma.UmaMetadataService in project oxTrust by GluuFederation.

the class UmaPermissionService method initUmaMetadataConfiguration.

@Produces
@ApplicationScoped
@Named("umaMetadataConfiguration")
public UmaMetadata initUmaMetadataConfiguration() throws OxIntializationException {
    String umaConfigurationEndpoint = getUmaConfigurationEndpoint();
    if (StringHelper.isEmpty(umaConfigurationEndpoint)) {
        return null;
    }
    log.info("##### Getting UMA metadata ...");
    UmaMetadataService metaDataConfigurationService;
    if (this.clientHttpEngine == null) {
        metaDataConfigurationService = UmaClientFactory.instance().createMetadataService(umaConfigurationEndpoint);
    } else {
        metaDataConfigurationService = UmaClientFactory.instance().createMetadataService(umaConfigurationEndpoint, this.clientHttpEngine);
    }
    UmaMetadata metadataConfiguration = null;
    int max_attempts = 10;
    for (int attempt = 1; attempt <= max_attempts; attempt++) {
        try {
            metadataConfiguration = metaDataConfigurationService.getMetadata();
        } catch (javax.ws.rs.ServiceUnavailableException ex) {
            if ((attempt == max_attempts) || (ex.getResponse().getStatus() != javax.ws.rs.core.Response.Status.SERVICE_UNAVAILABLE.getStatusCode())) {
                throw ex;
            }
            try {
                java.lang.Thread.sleep(3000);
            } catch (InterruptedException ex2) {
                throw ex;
            }
            log.info("##### Attempting to load UMA metadata ... {}", attempt);
        }
    }
    log.info("##### Getting UMA metadata ... DONE");
    if (metadataConfiguration == null) {
        throw new OxIntializationException("UMA meta data configuration is invalid!");
    }
    return metadataConfiguration;
}
Also used : UmaMetadata(org.gluu.oxauth.model.uma.UmaMetadata) OxIntializationException(org.gluu.exception.OxIntializationException) UmaMetadataService(org.gluu.oxauth.client.uma.UmaMetadataService) Named(javax.inject.Named) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 2 with UmaMetadataService

use of org.gluu.oxauth.client.uma.UmaMetadataService in project oxAuth by GluuFederation.

the class MetaDataFlowHttpTest method testGetUmaMetaDataConfiguration.

/**
 * Test for getting meta data configuration
 */
@Test
@Parameters({ "umaMetaDataUrl" })
public void testGetUmaMetaDataConfiguration(final String umaMetaDataUrl) throws Exception {
    showTitle("testGetUmaMetaDataConfiguration");
    UmaMetadataService metaDataConfigurationService = UmaClientFactory.instance().createMetadataService(umaMetaDataUrl, clientEngine(true));
    // Get meta data
    UmaMetadata c = null;
    try {
        c = metaDataConfigurationService.getMetadata();
    } catch (ClientErrorException ex) {
        System.err.println(ex.getResponse().readEntity(String.class));
        throw ex;
    }
    UmaTestUtil.assert_(c);
}
Also used : UmaMetadata(org.gluu.oxauth.model.uma.UmaMetadata) ClientErrorException(javax.ws.rs.ClientErrorException) UmaMetadataService(org.gluu.oxauth.client.uma.UmaMetadataService) Parameters(org.testng.annotations.Parameters) BaseTest(org.gluu.oxauth.BaseTest) Test(org.testng.annotations.Test)

Aggregations

UmaMetadataService (org.gluu.oxauth.client.uma.UmaMetadataService)2 UmaMetadata (org.gluu.oxauth.model.uma.UmaMetadata)2 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Produces (javax.enterprise.inject.Produces)1 Named (javax.inject.Named)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 OxIntializationException (org.gluu.exception.OxIntializationException)1 BaseTest (org.gluu.oxauth.BaseTest)1 Parameters (org.testng.annotations.Parameters)1 Test (org.testng.annotations.Test)1