blob: 5e4614a7804dedba9383b92f6cb189a44eb1dfcd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.jdisc.http.guiceModules;
import com.google.inject.Binder;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.yahoo.component.ComponentId;
import com.yahoo.component.provider.ComponentRegistry;
import com.yahoo.jdisc.http.ConnectorConfig;
import com.yahoo.jdisc.http.ConnectorConfig.Builder;
import com.yahoo.jdisc.http.SecretStore;
import com.yahoo.jdisc.http.server.jetty.ConnectorFactory;
import com.yahoo.jdisc.http.server.jetty.TestDrivers;
import com.yahoo.jdisc.http.ssl.ReaderForPath;
import com.yahoo.jdisc.http.ssl.SslKeyStore;
import com.yahoo.jdisc.http.ssl.SslKeyStoreFactory;
/**
* Guice module for test ConnectorFactories
*
* @author tonytv
*/
public class ConnectorFactoryRegistryModule implements Module {
private final Builder connectorConfigBuilder;
public ConnectorFactoryRegistryModule(Builder connectorConfigBuilder) {
this.connectorConfigBuilder = connectorConfigBuilder;
}
public ConnectorFactoryRegistryModule() {
this(new Builder());
}
@Provides
public ComponentRegistry<ConnectorFactory> connectorFactoryComponentRegistry() {
ComponentRegistry<ConnectorFactory> registry = new ComponentRegistry<>();
registry.register(ComponentId.createAnonymousComponentId("connector-factory"),
new StaticKeyDbConnectorFactory(new ConnectorConfig(connectorConfigBuilder)));
registry.freeze();
return registry;
}
@Override
public void configure(Binder binder) {
}
private static class StaticKeyDbConnectorFactory extends ConnectorFactory {
public StaticKeyDbConnectorFactory(ConnectorConfig connectorConfig) {
super(connectorConfig, new ThrowingSslKeyStoreFactory(), new MockSecretStore());
}
}
private static final class ThrowingSslKeyStoreFactory implements SslKeyStoreFactory {
@Override
public SslKeyStore createKeyStore(ReaderForPath certificateFile, ReaderForPath keyFile) {
throw new UnsupportedOperationException("A SSL key store factory component is not available");
}
@Override
public SslKeyStore createTrustStore(ReaderForPath certificateFile) {
throw new UnsupportedOperationException("A SSL key store factory component is not available");
}
}
private static final class MockSecretStore implements SecretStore {
@Override
public String getSecret(String key) {
return TestDrivers.KEY_STORE_PASSWORD;
}
}
}
|