Search in sources :

Example 1 with StubServer

use of com.xebialabs.restito.server.StubServer 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)

Aggregations

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 RSAPrivateKey (java.security.interfaces.RSAPrivateKey)1 RSAPublicKey (java.security.interfaces.RSAPublicKey)1 BeforeExam (org.codice.ddf.test.common.annotations.BeforeExam)1