Search in sources :

Example 1 with IDataEncrypter

use of io.apiman.common.util.crypt.IDataEncrypter in project apiman by apiman.

the class AesDataEncrypterTest method dataEncrypterWithKey.

@Test
public void dataEncrypterWithKey() {
    Map<String, String> config = new HashMap<>();
    config.put("secretKey", "a2a0aa80-84Zd2a6");
    IDataEncrypter dataEncrypter = new AesDataEncrypter(config);
    String result = dataEncrypter.encrypt("Hello, world.", encryptionCtx);
    assertNotNull(result);
    assertEquals("$CRYPT::XtwdsXC3Tv6vlQXQQPrxdg==", result);
    result = dataEncrypter.decrypt(result, encryptionCtx);
    assertEquals("Hello, world.", result);
}
Also used : HashMap(java.util.HashMap) AesDataEncrypter(io.apiman.common.util.crypt.AesDataEncrypter) IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter) Test(org.junit.Test)

Example 2 with IDataEncrypter

use of io.apiman.common.util.crypt.IDataEncrypter in project apiman by apiman.

the class AesDataEncrypterTest method dataEncrypterWithDifferentKey.

@Test
public void dataEncrypterWithDifferentKey() {
    Map<String, String> config = new HashMap<>();
    config.put("secretKey", "H2a9a780-m4Zd2a0");
    IDataEncrypter dataEncrypter = new AesDataEncrypter(config);
    String result = dataEncrypter.encrypt("Hello, world.", encryptionCtx);
    assertNotNull(result);
    assertEquals("$CRYPT::dLklbimUARc6EfsrxpSG2Q==", result);
    result = dataEncrypter.decrypt(result, encryptionCtx);
    assertEquals("Hello, world.", result);
}
Also used : HashMap(java.util.HashMap) AesDataEncrypter(io.apiman.common.util.crypt.AesDataEncrypter) IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter) Test(org.junit.Test)

Example 3 with IDataEncrypter

use of io.apiman.common.util.crypt.IDataEncrypter in project apiman by apiman.

the class AesDataEncrypterTest method dataEncrypterWithoutKey.

@Test(expected = RuntimeException.class)
public void dataEncrypterWithoutKey() {
    Map<String, String> config = new HashMap<>();
    IDataEncrypter dataEncrypter = new AesDataEncrypter(config);
    dataEncrypter.encrypt("Hello, world.", encryptionCtx);
}
Also used : HashMap(java.util.HashMap) AesDataEncrypter(io.apiman.common.util.crypt.AesDataEncrypter) IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter) Test(org.junit.Test)

Example 4 with IDataEncrypter

use of io.apiman.common.util.crypt.IDataEncrypter in project apiman by apiman.

the class ManagerApiMicroServiceCdiFactory method provideDataEncrypter.

@Produces
@ApplicationScoped
public static IDataEncrypter provideDataEncrypter(ManagerApiMicroServiceConfig config, IPluginRegistry pluginRegistry, @New DefaultDataEncrypter defaultEncrypter) {
    try {
        IDataEncrypter encrypter = createCustomComponent(IDataEncrypter.class, config.getDataEncrypterType(), config.getDataEncrypterProperties(), pluginRegistry, defaultEncrypter);
        CurrentDataEncrypter.instance = encrypter;
        return encrypter;
    } catch (Throwable t) {
        // $NON-NLS-1$
        throw new RuntimeException("Error or unknown data encrypter type: " + config.getDataEncrypterType(), t);
    }
}
Also used : IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter) Produces(javax.enterprise.inject.Produces) ApplicationScoped(javax.enterprise.context.ApplicationScoped)

Example 5 with IDataEncrypter

use of io.apiman.common.util.crypt.IDataEncrypter in project apiman by apiman.

the class ConfigDrivenEngineFactory method createDataEncrypter.

/**
 * @see io.apiman.gateway.engine.impl.AbstractEngineFactory#createDataEncrypter(io.apiman.gateway.engine.IPluginRegistry)
 */
@Override
protected IDataEncrypter createDataEncrypter(IPluginRegistry pluginRegistry) {
    try {
        Class<? extends IDataEncrypter> c = engineConfig.getDataEncrypterClass(pluginRegistry);
        Map<String, String> config = engineConfig.getDataEncrypterConfig();
        IDataEncrypter encrypter = create(c, config);
        return encrypter;
    } catch (RuntimeException e) {
        if ("No IDataEncrypter class configured.".equals(e.getMessage())) {
            // $NON-NLS-1$
            // $NON-NLS-1$ //$NON-NLS-2$
            LOGGER.info("NOTE: No explicit Data Encrypter found.  Falling back to the Default. [" + e.getMessage() + "]");
            return new DefaultDataEncrypter();
        } else {
            throw e;
        }
    }
}
Also used : IDataEncrypter(io.apiman.common.util.crypt.IDataEncrypter)

Aggregations

IDataEncrypter (io.apiman.common.util.crypt.IDataEncrypter)7 AesDataEncrypter (io.apiman.common.util.crypt.AesDataEncrypter)3 HashMap (java.util.HashMap)3 Test (org.junit.Test)3 ApplicationScoped (javax.enterprise.context.ApplicationScoped)2 Produces (javax.enterprise.inject.Produces)2 IApiRequestPathParser (io.apiman.gateway.engine.IApiRequestPathParser)1 IComponentRegistry (io.apiman.gateway.engine.IComponentRegistry)1 IConnectorFactory (io.apiman.gateway.engine.IConnectorFactory)1 IGatewayInitializer (io.apiman.gateway.engine.IGatewayInitializer)1 IMetrics (io.apiman.gateway.engine.IMetrics)1 IPluginRegistry (io.apiman.gateway.engine.IPluginRegistry)1 IRegistry (io.apiman.gateway.engine.IRegistry)1 IPolicyFactory (io.apiman.gateway.engine.policy.IPolicyFactory)1