Search in sources :

Example 1 with OxIntializationException

use of org.gluu.exception.OxIntializationException in project oxTrust by GluuFederation.

the class AppInitializer method initOpenIdConfiguration.

@Produces
@ApplicationScoped
@Named("openIdConfiguration")
public OpenIdConfigurationResponse initOpenIdConfiguration() throws OxIntializationException {
    String oxAuthIssuer = this.configurationFactory.getAppConfiguration().getOxAuthIssuer();
    if (StringHelper.isEmpty(oxAuthIssuer)) {
        log.info("oxAuth issuer isn't specified");
        return null;
    }
    log.debug("Attempting to determine configuration endpoint URL");
    OpenIdConnectDiscoveryClient openIdConnectDiscoveryClient;
    try {
        openIdConnectDiscoveryClient = new OpenIdConnectDiscoveryClient(oxAuthIssuer);
    } catch (URISyntaxException ex) {
        throw new OxIntializationException("OpenId discovery response is invalid!", ex);
    }
    OpenIdConnectDiscoveryResponse openIdConnectDiscoveryResponse = openIdConnectDiscoveryClient.exec();
    if ((openIdConnectDiscoveryResponse.getStatus() != 200) || (openIdConnectDiscoveryResponse.getSubject() == null) || (openIdConnectDiscoveryResponse.getLinks().size() == 0)) {
        throw new OxIntializationException("OpenId discovery response is invalid!");
    }
    log.debug("Attempting to load OpenID configuration");
    String configurationEndpoint = openIdConnectDiscoveryResponse.getLinks().get(0).getHref() + "/.well-known/openid-configuration";
    OpenIdConfigurationClient client = new OpenIdConfigurationClient(configurationEndpoint);
    OpenIdConfigurationResponse openIdConfiguration;
    try {
        openIdConfiguration = client.execOpenIdConfiguration();
    } catch (Exception e) {
        log.error("Failed to load OpenId configuration!", e);
        throw new OxIntializationException("Failed to load OpenId configuration!");
    }
    if (openIdConfiguration.getStatus() != 200) {
        throw new OxIntializationException("OpenId configuration response is invalid!");
    }
    return openIdConfiguration;
}
Also used : OpenIdConnectDiscoveryClient(org.gluu.oxauth.client.OpenIdConnectDiscoveryClient) OpenIdConfigurationClient(org.gluu.oxauth.client.OpenIdConfigurationClient) OpenIdConnectDiscoveryResponse(org.gluu.oxauth.client.OpenIdConnectDiscoveryResponse) OpenIdConfigurationResponse(org.gluu.oxauth.client.OpenIdConfigurationResponse) URISyntaxException(java.net.URISyntaxException) OxIntializationException(org.gluu.exception.OxIntializationException) URISyntaxException(java.net.URISyntaxException) EncryptionException(org.gluu.util.security.StringEncrypter.EncryptionException) OxIntializationException(org.gluu.exception.OxIntializationException) Named(javax.inject.Named) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 2 with OxIntializationException

use of org.gluu.exception.OxIntializationException 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)

Aggregations

ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Produces (javax.enterprise.inject.Produces)2 Named (javax.inject.Named)2 OxIntializationException (org.gluu.exception.OxIntializationException)2 URISyntaxException (java.net.URISyntaxException)1 OpenIdConfigurationClient (org.gluu.oxauth.client.OpenIdConfigurationClient)1 OpenIdConfigurationResponse (org.gluu.oxauth.client.OpenIdConfigurationResponse)1 OpenIdConnectDiscoveryClient (org.gluu.oxauth.client.OpenIdConnectDiscoveryClient)1 OpenIdConnectDiscoveryResponse (org.gluu.oxauth.client.OpenIdConnectDiscoveryResponse)1 UmaMetadataService (org.gluu.oxauth.client.uma.UmaMetadataService)1 UmaMetadata (org.gluu.oxauth.model.uma.UmaMetadata)1 EncryptionException (org.gluu.util.security.StringEncrypter.EncryptionException)1