Search in sources :

Example 1 with SSLProperties

use of org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties in project java-chassis by ServiceComb.

the class TransportUtils method createSSLProperties.

public static SSLProperties createSSLProperties(boolean sslEnabled, Configuration configuration, String tag) {
    SSLProperties sslProperties = new SSLProperties();
    sslProperties.setEnabled(sslEnabled);
    if (!sslEnabled) {
        return sslProperties;
    }
    SSLOption option = new SSLOption();
    option.setEngine(getStringProperty(configuration, DEFAULT_OPTION.getEngine(), "ssl." + tag + ".engine", "ssl.engine"));
    option.setProtocols(getStringProperty(configuration, DEFAULT_OPTION.getProtocols(), "ssl." + tag + ".protocols", "ssl.protocols"));
    option.setCiphers(getStringProperty(configuration, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".ciphers", "ssl.ciphers"));
    option.setAuthPeer(getBooleanProperty(configuration, DEFAULT_OPTION.isAuthPeer(), "ssl." + tag + ".authPeer", "ssl.authPeer"));
    option.setCheckCNHost(getBooleanProperty(configuration, DEFAULT_OPTION.isCheckCNHost(), "ssl." + tag + ".checkCN.host", "ssl.checkCN.host"));
    option.setCheckCNWhite(getBooleanProperty(configuration, DEFAULT_OPTION.isCheckCNWhite(), "ssl." + tag + ".checkCN.white", "ssl.checkCN.white"));
    option.setCheckCNWhiteFile(getStringProperty(configuration, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".checkCN.white.file", "ssl.checkCN.white.file"));
    option.setAllowRenegociate(getBooleanProperty(configuration, DEFAULT_OPTION.isAllowRenegociate(), "ssl." + tag + ".allowRenegociate", "ssl.allowRenegociate"));
    option.setStorePath(getStringProperty(configuration, DEFAULT_OPTION.getStorePath(), "ssl." + tag + ".storePath", "ssl.storePath"));
    option.setClientAuth(getStringProperty(configuration, DEFAULT_OPTION.getClientAuth(), "ssl." + tag + ".clientAuth", "ssl.clientAuth"));
    option.setTrustStore(getStringProperty(configuration, DEFAULT_OPTION.getTrustStore(), "ssl." + tag + ".trustStore", "ssl.trustStore"));
    option.setTrustStoreType(getStringProperty(configuration, DEFAULT_OPTION.getTrustStoreType(), "ssl." + tag + ".trustStoreType", "ssl.trustStoreType"));
    option.setTrustStoreValue(getStringProperty(configuration, DEFAULT_OPTION.getTrustStoreValue(), "ssl." + tag + ".trustStoreValue", "ssl.trustStoreValue"));
    option.setKeyStore(getStringProperty(configuration, DEFAULT_OPTION.getKeyStore(), "ssl." + tag + ".keyStore", "ssl.keyStore"));
    option.setKeyStoreType(getStringProperty(configuration, DEFAULT_OPTION.getKeyStoreType(), "ssl." + tag + ".keyStoreType", "ssl.keyStoreType"));
    option.setKeyStoreValue(getStringProperty(configuration, DEFAULT_OPTION.getKeyStoreValue(), "ssl." + tag + ".keyStoreValue", "ssl.keyStoreValue"));
    option.setCrl(getStringProperty(configuration, DEFAULT_OPTION.getCrl(), "ssl." + tag + ".crl", "ssl.crl"));
    option.setSslCustomClass(getStringProperty(configuration, null, "ssl." + tag + ".sslCustomClass", "ssl.sslCustomClass"));
    sslProperties.setSslOption(option);
    sslProperties.setSslCustom(SSLCustom.createSSLCustom(option.getSslCustomClass()));
    return sslProperties;
}
Also used : SSLProperties(org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties) SSLOption(org.apache.servicecomb.foundation.ssl.SSLOption)

Example 2 with SSLProperties

use of org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties in project java-chassis by ServiceComb.

the class TransportUtils method createSSLProperties.

public static SSLProperties createSSLProperties(boolean sslEnabled, Configuration configuration, String tag) {
    SSLProperties sslProperties = new SSLProperties();
    sslProperties.setEnabled(sslEnabled);
    if (!sslEnabled) {
        return sslProperties;
    }
    SSLOption option = new SSLOption();
    option.setEngine(getStringProperty(configuration, DEFAULT_OPTION.getEngine(), "ssl." + tag + ".engine", "ssl.engine"));
    option.setProtocols(getStringProperty(configuration, DEFAULT_OPTION.getProtocols(), "ssl." + tag + ".protocols", "ssl.protocols"));
    option.setCiphers(getStringProperty(configuration, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".ciphers", "ssl.ciphers"));
    option.setAuthPeer(getBooleanProperty(configuration, DEFAULT_OPTION.isAuthPeer(), "ssl." + tag + ".authPeer", "ssl.authPeer"));
    option.setCheckCNHost(getBooleanProperty(configuration, DEFAULT_OPTION.isCheckCNHost(), "ssl." + tag + ".checkCN.host", "ssl.checkCN.host"));
    option.setCheckCNWhite(getBooleanProperty(configuration, DEFAULT_OPTION.isCheckCNWhite(), "ssl." + tag + ".checkCN.white", "ssl.checkCN.white"));
    option.setCheckCNWhiteFile(getStringProperty(configuration, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".checkCN.white.file", "ssl.checkCN.white.file"));
    option.setAllowRenegociate(getBooleanProperty(configuration, DEFAULT_OPTION.isAllowRenegociate(), "ssl." + tag + ".allowRenegociate", "ssl.allowRenegociate"));
    option.setStorePath(getStringProperty(configuration, DEFAULT_OPTION.getStorePath(), "ssl." + tag + ".storePath", "ssl.storePath"));
    option.setClientAuth(getStringProperty(configuration, DEFAULT_OPTION.getClientAuth(), "ssl." + tag + ".clientAuth", "ssl.clientAuth"));
    option.setTrustStore(getStringProperty(configuration, DEFAULT_OPTION.getTrustStore(), "ssl." + tag + ".trustStore", "ssl.trustStore"));
    option.setTrustStoreType(getStringProperty(configuration, DEFAULT_OPTION.getTrustStoreType(), "ssl." + tag + ".trustStoreType", "ssl.trustStoreType"));
    option.setTrustStoreValue(getStringProperty(configuration, DEFAULT_OPTION.getTrustStoreValue(), "ssl." + tag + ".trustStoreValue", "ssl.trustStoreValue"));
    option.setKeyStore(getStringProperty(configuration, DEFAULT_OPTION.getKeyStore(), "ssl." + tag + ".keyStore", "ssl.keyStore"));
    option.setKeyStoreType(getStringProperty(configuration, DEFAULT_OPTION.getKeyStoreType(), "ssl." + tag + ".keyStoreType", "ssl.keyStoreType"));
    option.setKeyStoreValue(getStringProperty(configuration, DEFAULT_OPTION.getKeyStoreValue(), "ssl." + tag + ".keyStoreValue", "ssl.keyStoreValue"));
    option.setCrl(getStringProperty(configuration, DEFAULT_OPTION.getCrl(), "ssl." + tag + ".crl", "ssl.crl"));
    option.setSslCustomClass(getStringProperty(configuration, null, "ssl." + tag + ".sslCustomClass", "ssl.sslCustomClass"));
    sslProperties.setSslOption(option);
    sslProperties.setSslCustom(SSLCustom.createSSLCustom(option.getSslCustomClass()));
    return sslProperties;
}
Also used : SSLProperties(org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties) SSLOption(org.apache.servicecomb.foundation.ssl.SSLOption)

Example 3 with SSLProperties

use of org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties in project java-chassis by ServiceComb.

the class RBACBootStrapService method createSSLProperties.

private SSLProperties createSSLProperties(Environment environment, String tag) {
    SSLProperties sslProperties = new SSLProperties();
    SSLOption option = new SSLOption();
    option.setEngine(getStringProperty(environment, DEFAULT_OPTION.getEngine(), "ssl." + tag + ".engine", "ssl.engine"));
    option.setProtocols(getStringProperty(environment, DEFAULT_OPTION.getProtocols(), "ssl." + tag + ".protocols", "ssl.protocols"));
    option.setCiphers(getStringProperty(environment, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".ciphers", "ssl.ciphers"));
    option.setAuthPeer(getBooleanProperty(environment, DEFAULT_OPTION.isAuthPeer(), "ssl." + tag + ".authPeer", "ssl.authPeer"));
    option.setCheckCNHost(getBooleanProperty(environment, DEFAULT_OPTION.isCheckCNHost(), "ssl." + tag + ".checkCN.host", "ssl.checkCN.host"));
    option.setCheckCNWhite(getBooleanProperty(environment, DEFAULT_OPTION.isCheckCNWhite(), "ssl." + tag + ".checkCN.white", "ssl.checkCN.white"));
    option.setCheckCNWhiteFile(getStringProperty(environment, DEFAULT_OPTION.getCiphers(), "ssl." + tag + ".checkCN.white.file", "ssl.checkCN.white.file"));
    option.setAllowRenegociate(getBooleanProperty(environment, DEFAULT_OPTION.isAllowRenegociate(), "ssl." + tag + ".allowRenegociate", "ssl.allowRenegociate"));
    option.setStorePath(getStringProperty(environment, DEFAULT_OPTION.getStorePath(), "ssl." + tag + ".storePath", "ssl.storePath"));
    option.setClientAuth(getStringProperty(environment, DEFAULT_OPTION.getClientAuth(), "ssl." + tag + ".clientAuth", "ssl.clientAuth"));
    option.setTrustStore(getStringProperty(environment, DEFAULT_OPTION.getTrustStore(), "ssl." + tag + ".trustStore", "ssl.trustStore"));
    option.setTrustStoreType(getStringProperty(environment, DEFAULT_OPTION.getTrustStoreType(), "ssl." + tag + ".trustStoreType", "ssl.trustStoreType"));
    option.setTrustStoreValue(getStringProperty(environment, DEFAULT_OPTION.getTrustStoreValue(), "ssl." + tag + ".trustStoreValue", "ssl.trustStoreValue"));
    option.setKeyStore(getStringProperty(environment, DEFAULT_OPTION.getKeyStore(), "ssl." + tag + ".keyStore", "ssl.keyStore"));
    option.setKeyStoreType(getStringProperty(environment, DEFAULT_OPTION.getKeyStoreType(), "ssl." + tag + ".keyStoreType", "ssl.keyStoreType"));
    option.setKeyStoreValue(getStringProperty(environment, DEFAULT_OPTION.getKeyStoreValue(), "ssl." + tag + ".keyStoreValue", "ssl.keyStoreValue"));
    option.setCrl(getStringProperty(environment, DEFAULT_OPTION.getCrl(), "ssl." + tag + ".crl", "ssl.crl"));
    option.setSslCustomClass(getStringProperty(environment, null, "ssl." + tag + ".sslCustomClass", "ssl.sslCustomClass"));
    sslProperties.setSslOption(option);
    sslProperties.setSslCustom(SSLCustom.createSSLCustom(option.getSslCustomClass()));
    return sslProperties;
}
Also used : SSLProperties(org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties) SSLOption(org.apache.servicecomb.foundation.ssl.SSLOption)

Example 4 with SSLProperties

use of org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties in project java-chassis by ServiceComb.

the class RegistryClientTest method testRestTransport.

@Override
public void testRestTransport() throws Exception {
    AddressManager addressManager = new AddressManager("default", Arrays.asList("http://127.0.0.1:30100"), new EventBus());
    SSLProperties sslProperties = new SSLProperties();
    sslProperties.setEnabled(false);
    ServiceCenterClient serviceCenterClient = new ServiceCenterClient(addressManager, sslProperties, new DefaultRequestAuthHeaderProvider(), "default", null);
    EventBus eventBus = new SimpleEventBus();
    ServiceCenterConfiguration serviceCenterConfiguration = new ServiceCenterConfiguration();
    ServiceCenterRegistration serviceCenterRegistration = new ServiceCenterRegistration(serviceCenterClient, serviceCenterConfiguration, eventBus);
    Microservice microservice = new Microservice();
    microservice.setAppId("app_registry");
    microservice.setServiceName("name_registry");
    microservice.setVersion("1.0.0");
    microservice.setEnvironment("development");
    List<String> schemas = new ArrayList<>();
    schemas.add("SchemaA");
    schemas.add("SchemaB");
    microservice.setSchemas(schemas);
    MicroserviceInstance microserviceInstance = new MicroserviceInstance();
    microserviceInstance.setHostName("host_registry");
    List<String> endpoints = new ArrayList<>();
    endpoints.add("rest://127.0.0.1/");
    microserviceInstance.setEndpoints(endpoints);
    List<SchemaInfo> schemaInfos = new ArrayList<>();
    SchemaInfo schemaA = new SchemaInfo();
    schemaA.setSchemaId("SchemaA");
    schemaA.setSchema("schema contents in any format");
    schemaA.setSummary(Hashing.sha256().newHasher().putString("schema contents in any format".toString(), Charsets.UTF_8).hash().toString());
    schemaInfos.add(schemaA);
    SchemaInfo schemaB = new SchemaInfo();
    schemaB.setSchemaId("SchemaA");
    schemaB.setSchema("schema contents in any format");
    schemaB.setSummary(Hashing.sha256().newHasher().putString("schema contents in any format".toString(), Charsets.UTF_8).hash().toString());
    schemaInfos.add(schemaB);
    serviceCenterRegistration.setMicroservice(microservice);
    serviceCenterRegistration.setMicroserviceInstance(microserviceInstance);
    serviceCenterRegistration.setSchemaInfos(schemaInfos);
    eventBus.register(this);
    serviceCenterRegistration.startRegistration();
    registrationCounter.await(30000, TimeUnit.MILLISECONDS);
    if (hasRegistered) {
        TestMgr.check(events.size() >= 3, true);
        TestMgr.check(events.get(0).isSuccess(), true);
        TestMgr.check(events.get(0) instanceof MicroserviceRegistrationEvent, true);
        TestMgr.check(events.get(1).isSuccess(), true);
        TestMgr.check(events.get(1) instanceof MicroserviceInstanceRegistrationEvent, true);
        TestMgr.check(events.get(2).isSuccess(), true);
        TestMgr.check(events.get(2) instanceof HeartBeatEvent, true);
    } else {
        TestMgr.check(events.size() >= 4, true);
        TestMgr.check(events.get(0).isSuccess(), true);
        TestMgr.check(events.get(0) instanceof MicroserviceRegistrationEvent, true);
        TestMgr.check(events.get(1).isSuccess(), true);
        TestMgr.check(events.get(1) instanceof SchemaRegistrationEvent, true);
        TestMgr.check(events.get(2).isSuccess(), true);
        TestMgr.check(events.get(2) instanceof MicroserviceInstanceRegistrationEvent, true);
        TestMgr.check(events.get(3).isSuccess(), true);
        TestMgr.check(events.get(3) instanceof HeartBeatEvent, true);
    }
    ServiceCenterDiscovery discovery = new ServiceCenterDiscovery(serviceCenterClient, eventBus);
    discovery.updateMyselfServiceId(microservice.getServiceId());
    discovery.startDiscovery();
    discovery.registerIfNotPresent(new SubscriptionKey(microservice.getAppId(), microservice.getServiceName()));
    discoveryCounter.await(30000, TimeUnit.MILLISECONDS);
    TestMgr.check(instances != null, true);
    TestMgr.check(instances.size(), 1);
    discovery.stop();
    serviceCenterRegistration.stop();
    serviceCenterClient.deleteMicroserviceInstance(microservice.getServiceId(), microserviceInstance.getInstanceId());
}
Also used : SchemaRegistrationEvent(org.apache.servicecomb.service.center.client.RegistrationEvents.SchemaRegistrationEvent) AddressManager(org.apache.servicecomb.service.center.client.AddressManager) SubscriptionKey(org.apache.servicecomb.service.center.client.ServiceCenterDiscovery.SubscriptionKey) ServiceCenterConfiguration(org.apache.servicecomb.service.center.client.model.ServiceCenterConfiguration) ServiceCenterRegistration(org.apache.servicecomb.service.center.client.ServiceCenterRegistration) ServiceCenterDiscovery(org.apache.servicecomb.service.center.client.ServiceCenterDiscovery) SSLProperties(org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties) ArrayList(java.util.ArrayList) MicroserviceInstance(org.apache.servicecomb.service.center.client.model.MicroserviceInstance) EventBus(com.google.common.eventbus.EventBus) SimpleEventBus(org.apache.servicecomb.foundation.common.event.SimpleEventBus) DefaultRequestAuthHeaderProvider(org.apache.servicecomb.http.client.auth.DefaultRequestAuthHeaderProvider) MicroserviceRegistrationEvent(org.apache.servicecomb.service.center.client.RegistrationEvents.MicroserviceRegistrationEvent) HeartBeatEvent(org.apache.servicecomb.service.center.client.RegistrationEvents.HeartBeatEvent) Microservice(org.apache.servicecomb.service.center.client.model.Microservice) ServiceCenterClient(org.apache.servicecomb.service.center.client.ServiceCenterClient) SimpleEventBus(org.apache.servicecomb.foundation.common.event.SimpleEventBus) MicroserviceInstanceRegistrationEvent(org.apache.servicecomb.service.center.client.RegistrationEvents.MicroserviceInstanceRegistrationEvent) SchemaInfo(org.apache.servicecomb.service.center.client.model.SchemaInfo)

Example 5 with SSLProperties

use of org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties in project java-chassis by ServiceComb.

the class RBACBootStrapService method startup.

@Override
public void startup(Environment environment) {
    if (!getBooleanProperty(environment, false, RBAC_ENABLED)) {
        return;
    }
    AddressManager addressManager = createAddressManager(environment);
    SSLProperties sslProperties = createSSLProperties(environment, "sc.consumer");
    sslProperties.setEnabled(addressManager.sslEnabled());
    // header: x-domain-name and url: /v1/{project}/ are all token from getTenantName。
    ServiceCenterClient serviceCenterClient = new ServiceCenterClient(addressManager, sslProperties, new DefaultRequestAuthHeaderProvider(), getTenantName(environment), new HashMap<>(0));
    Map<String, ServiceCenterClient> clients = new HashMap<>(1);
    clients.put(DEFAULT_REGISTRY_NAME, serviceCenterClient);
    TokenCacheManager.getInstance().setServiceCenterClients(clients);
    TokenCacheManager.getInstance().addTokenCache(DEFAULT_REGISTRY_NAME, getStringProperty(environment, null, ACCOUNT_NAME_KEY), getStringProperty(environment, null, PASSWORD_KEY), getCipher(getStringProperty(environment, DefaultCipher.CIPHER_NAME, CIPHER_KEY)));
}
Also used : AddressManager(org.apache.servicecomb.service.center.client.AddressManager) ServiceCenterClient(org.apache.servicecomb.service.center.client.ServiceCenterClient) HashMap(java.util.HashMap) SSLProperties(org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties) DefaultRequestAuthHeaderProvider(org.apache.servicecomb.http.client.auth.DefaultRequestAuthHeaderProvider)

Aggregations

SSLProperties (org.apache.servicecomb.http.client.common.HttpConfiguration.SSLProperties)5 SSLOption (org.apache.servicecomb.foundation.ssl.SSLOption)3 DefaultRequestAuthHeaderProvider (org.apache.servicecomb.http.client.auth.DefaultRequestAuthHeaderProvider)2 AddressManager (org.apache.servicecomb.service.center.client.AddressManager)2 ServiceCenterClient (org.apache.servicecomb.service.center.client.ServiceCenterClient)2 EventBus (com.google.common.eventbus.EventBus)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 SimpleEventBus (org.apache.servicecomb.foundation.common.event.SimpleEventBus)1 HeartBeatEvent (org.apache.servicecomb.service.center.client.RegistrationEvents.HeartBeatEvent)1 MicroserviceInstanceRegistrationEvent (org.apache.servicecomb.service.center.client.RegistrationEvents.MicroserviceInstanceRegistrationEvent)1 MicroserviceRegistrationEvent (org.apache.servicecomb.service.center.client.RegistrationEvents.MicroserviceRegistrationEvent)1 SchemaRegistrationEvent (org.apache.servicecomb.service.center.client.RegistrationEvents.SchemaRegistrationEvent)1 ServiceCenterDiscovery (org.apache.servicecomb.service.center.client.ServiceCenterDiscovery)1 SubscriptionKey (org.apache.servicecomb.service.center.client.ServiceCenterDiscovery.SubscriptionKey)1 ServiceCenterRegistration (org.apache.servicecomb.service.center.client.ServiceCenterRegistration)1 Microservice (org.apache.servicecomb.service.center.client.model.Microservice)1 MicroserviceInstance (org.apache.servicecomb.service.center.client.model.MicroserviceInstance)1 SchemaInfo (org.apache.servicecomb.service.center.client.model.SchemaInfo)1 ServiceCenterConfiguration (org.apache.servicecomb.service.center.client.model.ServiceCenterConfiguration)1