Search in sources :

Example 1 with UmaMetadata

use of org.gluu.oxauth.model.uma.UmaMetadata 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 UmaMetadata

use of org.gluu.oxauth.model.uma.UmaMetadata in project oxTrust by GluuFederation.

the class BaseApiTest method getAuthorizedRpt.

private void getAuthorizedRpt(String asUri, String ticket) {
    try {
        UmaMetadata umaMetadata = UmaClientFactory.instance().createMetadataService(asUri).getMetadata();
        if (umaMetadata == null) {
            throw new IllegalArgumentException(String.format("Failed to load valid UMA metadata configuration from: %s", asUri));
        }
        TokenRequest tokenRequest = getAuthorizationTokenRequest(umaMetadata);
        UmaTokenService tokenService = UmaClientFactory.instance().createTokenService(umaMetadata);
        UmaTokenResponse rptResponse = tokenService.requestJwtAuthorizationRpt(ClientAssertionType.JWT_BEARER.toString(), tokenRequest.getClientAssertion(), GrantType.OXAUTH_UMA_TICKET.getValue(), ticket, null, null, null, null, null);
        if (rptResponse == null) {
            throw new IllegalArgumentException("UMA RPT token response is invalid");
        }
        if (StringUtils.isBlank(rptResponse.getAccessToken())) {
            throw new IllegalArgumentException("UMA RPT is invalid");
        }
        this.rpt = rptResponse.getAccessToken();
        System.out.println("RPT IS:" + this.rpt);
    } catch (Exception ex) {
        throw new IllegalArgumentException(ex.getMessage(), ex);
    }
}
Also used : UmaMetadata(org.gluu.oxauth.model.uma.UmaMetadata) UmaTokenResponse(org.gluu.oxauth.model.uma.UmaTokenResponse) UmaTokenService(org.gluu.oxauth.client.uma.UmaTokenService) TokenRequest(org.gluu.oxauth.client.TokenRequest) KeyStoreException(java.security.KeyStoreException) IOException(java.io.IOException) KeyManagementException(java.security.KeyManagementException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 3 with UmaMetadata

use of org.gluu.oxauth.model.uma.UmaMetadata in project oxAuth by GluuFederation.

the class ScopeHttpTest method scopePresence.

@Test
@Parameters({ "umaMetaDataUrl" })
public void scopePresence(final String umaMetaDataUrl) {
    final UmaMetadata metadata = UmaClientFactory.instance().createMetadataService(umaMetaDataUrl).getMetadata();
    final UmaScopeService scopeService = UmaClientFactory.instance().createScopeService(metadata.getScopeEndpoint());
    final UmaScopeDescription modifyScope = scopeService.getScope("modify");
    UmaTestUtil.assert_(modifyScope);
}
Also used : UmaMetadata(org.gluu.oxauth.model.uma.UmaMetadata) UmaScopeDescription(org.gluu.oxauth.model.uma.UmaScopeDescription) UmaScopeService(org.gluu.oxauth.client.uma.UmaScopeService) Parameters(org.testng.annotations.Parameters) Test(org.testng.annotations.Test)

Example 4 with UmaMetadata

use of org.gluu.oxauth.model.uma.UmaMetadata 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)

Example 5 with UmaMetadata

use of org.gluu.oxauth.model.uma.UmaMetadata in project oxAuth by GluuFederation.

the class UmaMetadataWS method getConfiguration.

@GET
@Produces({ UmaConstants.JSON_MEDIA_TYPE })
public Response getConfiguration() {
    try {
        final String baseEndpointUri = appConfiguration.getBaseEndpoint();
        final UmaMetadata c = new UmaMetadata();
        c.setIssuer(appConfiguration.getIssuer());
        c.setGrantTypesSupported(new String[] { GrantType.AUTHORIZATION_CODE.getValue(), GrantType.IMPLICIT.getValue(), GrantType.CLIENT_CREDENTIALS.getValue(), GrantType.OXAUTH_UMA_TICKET.getValue() });
        c.setResponseTypesSupported(new String[] { ResponseType.CODE.getValue(), ResponseType.ID_TOKEN.getValue(), ResponseType.TOKEN.getValue() });
        c.setTokenEndpointAuthMethodsSupported(appConfiguration.getTokenEndpointAuthMethodsSupported().toArray(new String[appConfiguration.getTokenEndpointAuthMethodsSupported().size()]));
        c.setTokenEndpointAuthSigningAlgValuesSupported(appConfiguration.getTokenEndpointAuthSigningAlgValuesSupported().toArray(new String[appConfiguration.getTokenEndpointAuthSigningAlgValuesSupported().size()]));
        c.setUiLocalesSupported(appConfiguration.getUiLocalesSupported().toArray(new String[appConfiguration.getUiLocalesSupported().size()]));
        c.setOpTosUri(appConfiguration.getOpTosUri());
        c.setOpPolicyUri(appConfiguration.getOpPolicyUri());
        c.setJwksUri(appConfiguration.getJwksUri());
        c.setServiceDocumentation(appConfiguration.getServiceDocumentation());
        c.setUmaProfilesSupported(new String[0]);
        c.setRegistrationEndpoint(appConfiguration.getRegistrationEndpoint());
        c.setTokenEndpoint(appConfiguration.getTokenEndpoint());
        c.setAuthorizationEndpoint(appConfiguration.getAuthorizationEndpoint());
        c.setIntrospectionEndpoint(baseEndpointUri + "/rpt/status");
        c.setResourceRegistrationEndpoint(baseEndpointUri + "/host/rsrc/resource_set");
        c.setPermissionEndpoint(baseEndpointUri + "/host/rsrc_pr");
        c.setScopeEndpoint(baseEndpointUri + UMA_SCOPES_SUFFIX);
        c.setClaimsInteractionEndpoint(baseEndpointUri + UMA_CLAIMS_GATHERING_PATH);
        // convert manually to avoid possible conflicts between resteasy providers, e.g. jettison, jackson
        final String entity = ServerUtil.asPrettyJson(c);
        log.trace("Uma metadata: {}", entity);
        return Response.ok(entity).build();
    } catch (Throwable ex) {
        log.error(ex.getMessage(), ex);
        throw errorResponseFactory.createWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, UmaErrorResponseType.SERVER_ERROR, "Internal error.");
    }
}
Also used : UmaMetadata(org.gluu.oxauth.model.uma.UmaMetadata) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

UmaMetadata (org.gluu.oxauth.model.uma.UmaMetadata)6 Parameters (org.testng.annotations.Parameters)3 Test (org.testng.annotations.Test)3 BaseTest (org.gluu.oxauth.BaseTest)2 UmaMetadataService (org.gluu.oxauth.client.uma.UmaMetadataService)2 IOException (java.io.IOException)1 KeyManagementException (java.security.KeyManagementException)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 ApplicationScoped (javax.enterprise.context.ApplicationScoped)1 Produces (javax.enterprise.inject.Produces)1 Named (javax.inject.Named)1 ClientErrorException (javax.ws.rs.ClientErrorException)1 GET (javax.ws.rs.GET)1 Produces (javax.ws.rs.Produces)1 OxIntializationException (org.gluu.exception.OxIntializationException)1 TokenRequest (org.gluu.oxauth.client.TokenRequest)1 UmaScopeService (org.gluu.oxauth.client.uma.UmaScopeService)1 UmaTokenService (org.gluu.oxauth.client.uma.UmaTokenService)1 UmaScopeDescription (org.gluu.oxauth.model.uma.UmaScopeDescription)1