Search in sources :

Example 1 with BeforeExam

use of org.codice.ddf.test.common.annotations.BeforeExam in project ddf by codice.

the class TestSecurity method beforeExam.

@BeforeExam
public void beforeExam() throws Exception {
    try {
        List<String> featurePolicies = new ArrayList<>();
        featurePolicies.addAll(Arrays.asList(getDefaultRequiredApps()));
        featurePolicies.addAll(FEATURES_TO_FILTER);
        featurePolicies.replaceAll(featureName -> featureName + "=\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=admin\"");
        List<String> servicePolicies = new ArrayList<>(SERVICES_TO_FILTER);
        servicePolicies.replaceAll(serviceName -> serviceName + "=\"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/role=admin\"");
        String adminConfigPolicyPid = "org.codice.ddf.admin.config.policy.AdminConfigPolicy";
        getAdminConfig().getConfiguration(adminConfigPolicyPid).setBundleLocation("mvn:ddf.admin.core/admin-core-configpolicy/" + System.getProperty("ddf.version"));
        adminConfigProps = configureAdminConfigPolicy(featurePolicies, servicePolicies, getAdminConfig());
    } catch (Exception e) {
        LoggingUtils.failWithThrowableStacktrace(e, "Failed in @BeforeExam: ");
    }
}
Also used : ArrayList(java.util.ArrayList) Matchers.containsString(org.hamcrest.Matchers.containsString) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) IOException(java.io.IOException) BeforeExam(org.codice.ddf.test.common.annotations.BeforeExam)

Example 2 with BeforeExam

use of org.codice.ddf.test.common.annotations.BeforeExam in project ddf by codice.

the class TestOidc method beforeTest.

@BeforeExam
public void beforeTest() {
    try {
        getServiceManager().waitForAllBundles();
        getServiceManager().waitForHttpEndpoint(WHO_AM_I_URL.getUrl());
        getServiceManager().waitForHttpEndpoint(SERVICE_ROOT + "/catalog/query");
        oldPolicyManagerProps = getSecurityPolicy().configureWebContextPolicy(OIDC_AUTH_TYPES, OIDC_AUTH_TYPES, null, null);
        // start stub server
        server = new StubServer(Integer.parseInt(IDP_PORT.getPort())).run();
        server.start();
        // Generate the RSA key pair
        KeyPairGenerator gen = KeyPairGenerator.getInstance("RSA");
        gen.initialize(2048);
        KeyPair keyPair = gen.generateKeyPair();
        RSAPrivateKey privateKey = (RSAPrivateKey) keyPair.getPrivate();
        RSAPublicKey publicKey = (RSAPublicKey) keyPair.getPublic();
        // Convert to JSON Web Key (JWK) format
        JWK sigJwk = new RSAKey.Builder(publicKey).privateKey(privateKey).keyUse(KeyUse.SIGNATURE).keyID(UUID.randomUUID().toString()).build();
        jwk = "{\"keys\": [" + sigJwk.toPublicJWK().toJSONString() + "] }";
        validAlgorithm = Algorithm.RSA256(publicKey, privateKey);
        invalidAlgorithm = Algorithm.HMAC256("WRONG");
        setUp();
        // Configure OIDC Handler
        handlerConfig = new Hashtable<>();
        handlerConfig.put("idpType", "Keycloak");
        handlerConfig.put("clientId", DDF_CLIENT_ID);
        handlerConfig.put("realm", "master");
        handlerConfig.put(SECRET, DDF_CLIENT_SECRET);
        handlerConfig.put("logoutUri", URL_START.toString() + LOGOUT_URL_PATH);
        handlerConfig.put("baseUri", URL_START.toString() + "/auth");
        handlerConfig.put("discoveryUri", URL_START.toString() + METADATA_PATH);
        handlerConfig.put(SCOPE, DDF_SCOPE);
        handlerConfig.put("useNonce", true);
        handlerConfig.put("responseMode", FORM_POST);
        setConfig();
    } catch (Exception e) {
        LoggingUtils.failWithThrowableStacktrace(e, "Failed in @BeforeExam: ");
    }
}
Also used : KeyPair(java.security.KeyPair) StubServer(com.xebialabs.restito.server.StubServer) RSAPublicKey(java.security.interfaces.RSAPublicKey) GsonBuilder(com.google.gson.GsonBuilder) KeyPairGenerator(java.security.KeyPairGenerator) RSAPrivateKey(java.security.interfaces.RSAPrivateKey) JWK(com.nimbusds.jose.jwk.JWK) BeforeExam(org.codice.ddf.test.common.annotations.BeforeExam)

Example 3 with BeforeExam

use of org.codice.ddf.test.common.annotations.BeforeExam in project ddf by codice.

the class TestFederation method beforeExam.

@BeforeExam
public void beforeExam() {
    try {
        getSecurityPolicy().configureRestForGuest();
        getCatalogBundle().setupMaxDownloadRetryAttempts(MAX_DOWNLOAD_RETRY_ATTEMPTS);
        Map<String, Object> openSearchProperties = getOpenSearchSourceProperties(OPENSEARCH_SOURCE_ID, OPENSEARCH_PATH.getUrl(), getServiceManager());
        openSearchProperties.put("username", "localhost");
        openSearchProperties.put("password", "localhost");
        openSearchPid = getServiceManager().createManagedService(OPENSEARCH_FACTORY_PID, openSearchProperties).getPid();
        cswServer = new FederatedCswMockServer(CSW_STUB_SOURCE_ID, INSECURE_ROOT, Integer.parseInt(CSW_STUB_SERVER_PORT.getPort()));
        cswServer.start();
        Map<String, Object> cswStubServerProperties = getCswSourceProperties(CSW_STUB_SOURCE_ID, CSW_PATH.getUrl(), getServiceManager());
        cswStubServerProperties.put("cswUrl", CSW_STUB_SERVER_PATH.getUrl());
        cswStubServerProperties.put(POLL_INTERVAL, CSW_SOURCE_POLL_INTERVAL);
        cswPid = getServiceManager().createManagedService(CSW_FEDERATED_SOURCE_FACTORY_PID, cswStubServerProperties).getPid();
        getServiceManager().waitForHttpEndpoint(CSW_PATH + "?_wadl");
        Map<String, Object> cswProperties = getCswSourceProperties(CSW_SOURCE_ID, CSW_PATH.getUrl(), getServiceManager());
        cswProperties.put(POLL_INTERVAL, CSW_SOURCE_POLL_INTERVAL);
        cswProperties.put("username", "localhost");
        cswProperties.put("password", "localhost");
        cswPid2 = getServiceManager().createManagedService(CSW_FEDERATED_SOURCE_FACTORY_PID, cswProperties).getPid();
        Map<String, Object> cswProperties2 = getCswSourceProperties(CSW_SOURCE_WITH_METACARD_XML_ID, CSW_PATH.getUrl(), getServiceManager());
        cswProperties2.put("outputSchema", "urn:catalog:metacard");
        cswProperties2.put(POLL_INTERVAL, CSW_SOURCE_POLL_INTERVAL);
        cswProperties2.put("username", "localhost");
        cswProperties2.put("password", "localhost");
        cswPid3 = getServiceManager().createManagedService(CSW_FEDERATED_SOURCE_FACTORY_PID, cswProperties2).getPid();
        Map<String, Object> gmdProperties = getCswSourceProperties(GMD_SOURCE_ID, GMD_CSW_FEDERATED_SOURCE_FACTORY_PID, CSW_PATH.getUrl(), getServiceManager());
        gmdProperties.put(POLL_INTERVAL, CSW_SOURCE_POLL_INTERVAL);
        gmdPid = getServiceManager().createManagedService(GMD_CSW_FEDERATED_SOURCE_FACTORY_PID, gmdProperties).getPid();
        getCatalogBundle().waitForFederatedSource(OPENSEARCH_SOURCE_ID);
        getCatalogBundle().waitForFederatedSource(CSW_STUB_SOURCE_ID);
        getCatalogBundle().waitForFederatedSource(CSW_SOURCE_ID);
        getCatalogBundle().waitForFederatedSource(CSW_SOURCE_WITH_METACARD_XML_ID);
        getCatalogBundle().waitForFederatedSource(GMD_SOURCE_ID);
        getServiceManager().waitForSourcesToBeAvailable(REST_PATH.getUrl(), OPENSEARCH_SOURCE_ID, CSW_STUB_SOURCE_ID, CSW_SOURCE_ID, CSW_SOURCE_WITH_METACARD_XML_ID, GMD_SOURCE_ID);
        LOGGER.info("Source status: \n{}", get(REST_PATH.getUrl() + "sources").body().prettyPrint());
    } catch (Exception e) {
        LoggingUtils.failWithThrowableStacktrace(e, "Failed in @BeforeExam: ");
    }
}
Also used : FederatedCswMockServer(org.codice.ddf.itests.common.csw.mock.FederatedCswMockServer) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) IOException(java.io.IOException) BeforeExam(org.codice.ddf.test.common.annotations.BeforeExam)

Aggregations

BeforeExam (org.codice.ddf.test.common.annotations.BeforeExam)3 IOException (java.io.IOException)2 GsonBuilder (com.google.gson.GsonBuilder)1 JWK (com.nimbusds.jose.jwk.JWK)1 StubServer (com.xebialabs.restito.server.StubServer)1 KeyPair (java.security.KeyPair)1 KeyPairGenerator (java.security.KeyPairGenerator)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 ArrayList (java.util.ArrayList)1 SSLHandshakeException (javax.net.ssl.SSLHandshakeException)1 FederatedCswMockServer (org.codice.ddf.itests.common.csw.mock.FederatedCswMockServer)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 Matchers.containsString (org.hamcrest.Matchers.containsString)1