本文整理汇总了Java中org.glassfish.grizzly.ssl.SSLEngineConfigurator类的典型用法代码示例。如果您正苦于以下问题:Java SSLEngineConfigurator类的具体用法?Java SSLEngineConfigurator怎么用?Java SSLEngineConfigurator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SSLEngineConfigurator类属于org.glassfish.grizzly.ssl包,在下文中一共展示了SSLEngineConfigurator类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createHttpsServer
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
private HttpServer createHttpsServer() {
SSLContextConfigurator sslContextConfig = new SSLContextConfigurator();
// set up security context
sslContextConfig.setKeyStoreFile(this.serverKeystore); // contains server cert and key
sslContextConfig.setKeyStorePass(this.serverKeystorePwd);
// Create context and have exceptions raised if anything wrong with keystore or password
SSLContext sslContext = sslContextConfig.createSSLContext(true);
// Create server but do not start it
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(URI.create(this.baseUri),false);
//LOGGER.debug("About to loop through listeners");
//for (NetworkListener listener : server.getListeners()) {
// LOGGER.debug("About to setSecure on listener name: " + listener.getName());
//}
// grizzly is the default listener name
server.getListener("grizzly").setSecure(true);
// One way authentication
server.getListener("grizzly").setSSLEngineConfig(new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false));
return server;
}
示例2: startServer
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
public void startServer() throws TelegramApiException {
SSLContextConfigurator sslContext = new SSLContextConfigurator();
// set up security context
sslContext.setKeyStoreFile(KEYSTORE_SERVER_FILE); // contains server keypair
sslContext.setKeyStorePass(KEYSTORE_SERVER_PWD);
ResourceConfig rc = new ResourceConfig();
rc.register(restApi);
rc.register(JacksonFeature.class);
rc.property(JSONConfiguration.FEATURE_POJO_MAPPING, true);
final HttpServer grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(
getBaseURI(),
rc,
true,
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false));
try {
grizzlyServer.start();
} catch (IOException e) {
throw new TelegramApiException("Error starting webhook server", e);
}
}
示例3: startServer
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
public void startServer() throws TelegramApiRequestException {
ResourceConfig rc = new ResourceConfig();
rc.register(restApi);
rc.register(JacksonFeature.class);
final HttpServer grizzlyServer;
if (keystoreServerFile != null && keystoreServerPwd != null) {
SSLContextConfigurator sslContext = new SSLContextConfigurator();
// set up security context
sslContext.setKeyStoreFile(keystoreServerFile); // contains server keypair
sslContext.setKeyStorePass(keystoreServerPwd);
grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc, true,
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false));
} else {
grizzlyServer = GrizzlyHttpServerFactory.createHttpServer(getBaseURI(), rc);
}
try {
grizzlyServer.start();
} catch (IOException e) {
throw new TelegramApiRequestException("Error starting webhook server", e);
}
}
示例4: httpServer
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
@Bean
public HttpServer httpServer()
throws IOException, NoSuchAlgorithmException, InvalidKeySpecException, KeyStoreException,
FileNotFoundException, CertificateException, UnrecoverableEntryException, ConfigurationException {
HttpServer server = HttpServer.createSimpleServer("./", 8080);
WebSocketAddOn addon = new WebSocketAddOn();
server.getListeners().stream().forEach((listen) -> {
listen.registerAddOn(addon);
listen.setSecure(true);
listen.setSSLEngineConfig(
new SSLEngineConfigurator(this.sslConf()).setClientMode(false).setNeedClientAuth(false));
});
String messengerPath = configuration().getString(GlobalConfig.MESSENGER_PATH);
if (messengerPath == null) {
messengerPath = GlobalConfig.MESSENGER_PATH_DEFAULT;
}
ChatApplication application = this.chatApplication();
WebSocketEngine.getEngine().register("", messengerPath, application);
return server;
}
示例5: start
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
public static void start() {
WebappContext webappContext = new WebappContext("TestContext");
ServletRegistration registration = webappContext.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, "org.moskito.central.connectors.rest;org.codehaus.jackson.jaxrs");
registration.addMapping("/*");
SSLContextConfigurator sslConfigurator = new SSLContextConfigurator();
sslConfigurator.setKeyStoreFile("./target/test-classes/central_server_keystore.jks");
sslConfigurator.setKeyStorePass("moskito");
SSLContext sslContext = sslConfigurator.createSSLContext();
try {
server = GrizzlyServerFactory.createHttpServer(
getBaseURI(),
null,
true,
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false)
);
webappContext.deploy(server);
server.start();
} catch (Exception e) {
System.out.println("Error while starting the test server: " + e);
}
}
示例6: startSecureServer
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
/**
* Starts Grizzly HTTP server exposing JAX-RS resources defined in this
* application.
*
* @return Grizzly HTTP server.
*/
public static HttpServer startSecureServer ()
{
if (false)
System.setProperty ("javax.net.debug", "all");
final WebappContext aContext = _createContext (BASE_URI_HTTPS);
final SSLContextConfigurator aSSLContext = new SSLContextConfigurator ();
aSSLContext.setKeyStoreFile ("src/test/resources/test-https-keystore.jks");
aSSLContext.setKeyStorePass ("password");
aSSLContext.setKeyStoreType ("JKS");
aSSLContext.setTrustStoreBytes (StreamHelper.getAllBytes (new ClassPathResource (PeppolKeyStoreHelper.TRUSTSTORE_COMPLETE_CLASSPATH)));
aSSLContext.setTrustStorePass (PeppolKeyStoreHelper.TRUSTSTORE_PASSWORD);
aSSLContext.setTrustStoreType ("JKS");
aSSLContext.setSecurityProtocol ("TLSv1.2");
final SSLEngineConfigurator aSSLEngine = new SSLEngineConfigurator (aSSLContext);
aSSLEngine.setClientMode (false);
aSSLEngine.setNeedClientAuth (true);
aSSLEngine.setEnabledCipherSuites (new String [] { "TLS_RSA_WITH_AES_128_CBC_SHA",
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256",
"TLS_RSA_WITH_AES_128_CBC_SHA256",
"TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA",
"TLS_RSA_WITH_AES_128_CBC_SHA" });
// create and start a new instance of grizzly https server
// exposing the Jersey application at BASE_URI
final HttpServer ret = GrizzlyHttpServerFactory.createHttpServer (URI.create (BASE_URI_HTTPS),
(GrizzlyHttpContainer) null,
true,
aSSLEngine,
true);
aContext.deploy (ret);
return ret;
}
示例7: build
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
/**
* Creates the conversion server that is specified by this builder.
*
* @return The conversion server that is specified by this builder.
*/
public HttpServer build() {
checkNotNull(baseUri);
StandaloneWebConverterConfiguration configuration = makeConfiguration();
// The configuration has to be configured both by a binder to make it injectable
// and directly in order to trigger life cycle methods on the deployment container.
ResourceConfig resourceConfig = ResourceConfig
.forApplication(new WebConverterApplication(configuration))
.register(configuration);
if (sslContext == null) {
return GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
} else {
return GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig, true, new SSLEngineConfigurator(sslContext));
}
}
示例8: getWssConfigurator
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
public SSLEngineConfigurator getWssConfigurator() {
SSLEngineConfigurator config = new SSLEngineConfigurator(sManager.getWssConfigurator().getSslContext(), false, false, false);
return config;
}
示例9: connect
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
private void connect() throws Exception {
this.mgrApi = getMgrAPI();
this.clientEndpoint = new WebSocketClientEndPoint(this.mc, this.mgrApi, this.managerApis);
this.client = ClientManager.createClient();
if (this.mgrApi.isHttps()) {
SSLEngineConfigurator sslEngineConfigurator = new SSLEngineConfigurator(SslContextProvider.getInstance().getSSLContext(), true,
false, false);
this.client.getProperties().put(ClientManager.SSL_ENGINE_CONFIGURATOR, sslEngineConfigurator);
}
//TODO: Future. replace idle timeout with a better way of detecting unreachable server
this.client.setDefaultMaxSessionIdleTimeout(DEFAULT_WEBSOCKET_IDLE_TIMEOUT);
// configuring client properties
this.client.getProperties().put(ClientManager.RECONNECT_HANDLER, this.reconnectHandler);
this.client.getProperties().put(GrizzlyClientContainer.SHARED_CONTAINER, true);
// setting maximum selector thread.
this.client.getProperties().put(
GrizzlyClientSocket.SELECTOR_THREAD_POOL_CONFIG,
ThreadPoolConfig.defaultConfig().setPoolName("WebSocket-Shared-Selector-Thread-Pool")
.setMaxPoolSize(WEBSOCKET_SHARED_THREAD_POOL_SIZE)
.setCorePoolSize(WEBSOCKET_SHARED_THREAD_POOL_SIZE).setQueueLimit(THREAD_QUEUE_LIMIT));
// setting Maximum worker thread
this.client.getProperties().put(
GrizzlyClientSocket.WORKER_THREAD_POOL_CONFIG,
ThreadPoolConfig.defaultConfig().setPoolName("WebSocket-Shared-Worker-Thread-Pool")
.setMaxPoolSize(WEBSOCKET_SHARED_THREAD_POOL_SIZE)
.setCorePoolSize(WEBSOCKET_SHARED_THREAD_POOL_SIZE).setQueueLimit(THREAD_QUEUE_LIMIT));
// creating URI
final String uri = initURI(this.mc, WebSocketClient.this.mgrApi.getPort(), this.mgrApi.getUrl(),
WebSocketClient.this.mgrApi.isHttps());
log.info("Connecting to web socket notifier for MC: " + URI.create(uri));
WebSocketClient.this.wsSession = WebSocketClient.this.client.connectToServer(
WebSocketClient.this.clientEndpoint, getClientEndpointConfig(), URI.create(uri));
log.info("Successfully connected to web socket notifier for MC: " + URI.create(uri));
// Launch Ping thread to keep this connection alive...
startPinging();
}
示例10: start
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
public boolean start() throws IOException {
if (!server.isPresent()) {
if (secure) {
log.debug("RestServer: Creating secure server.");
server = Optional.of(GrizzlyHttpServerFactory.createHttpServer(
getServerURI(), getResourceConfig(), true,
new SSLEngineConfigurator(sslContext.get())
.setNeedClientAuth(true).setClientMode(false)));
}
else {
log.debug("RestServer: Creating server.");
server = Optional.of(GrizzlyHttpServerFactory.createHttpServer(
getServerURI(), getResourceConfig()));
}
NetworkListener listener = server.get().getListener("grizzly");
server.get().getServerConfiguration().setMaxBufferedPostSize(server.get().getServerConfiguration().getMaxBufferedPostSize()*10);
if (staticPath.isPresent()) {
StaticHttpHandler staticHttpHandler = new StaticHttpHandler(staticPath.get());
server.get().getServerConfiguration().addHttpHandler(staticHttpHandler, relativePath.get());
if (listener != null) {
listener.getFileCache().setSecondsMaxAge(fileCacheMaxAge);
}
}
}
if (!server.get().isStarted()) {
try {
log.debug("RestServer: starting server.");
server.get().start();
} catch (IOException ex) {
log.error("Failed to start HTTP Server", ex);
throw ex;
}
}
return true;
}
示例11: createListeners
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static List<NetworkListener> createListeners(List<Connector> connectors, CompressionConfig compression) {
List<NetworkListener> listeners = Lists.newArrayList();
for (Connector connector : connectors) {
final String host = (connector.getHost() == null) ? Connector.DEFAULT_NETWORK_HOST
: connector.getHost();
final int port = (connector.getPort() == -1) ? 80 : connector.getPort();
final NetworkListener listener = new NetworkListener(
StringUtils.defaultString(connector.getName(), DEFAULT_NETWORK_LISTENER_NAME),
host,
port);
listener.setSecure(connector.isSecureEnabled());
SSLEngineConfigurator sslEngineConfigurator = createSslEngineConfigurator(connector);
if (sslEngineConfigurator != null) {
listener.setSSLEngineConfig(sslEngineConfigurator);
if (connector.isSecureEnabled() && !connector.isAjpEnabled()) {
listener.registerAddOn(new Http2AddOn());
listener.registerAddOn(new SpdyAddOn());
}
}
if (connector.isAjpEnabled()) {
listener.registerAddOn(new AjpAddOn());
}
CompressionConfig compressionConfig = listener.getCompressionConfig();
CompressionConfig compressionCfg = createCompressionConfig(null, (Map) connector.getRawProperties());
if (compression != null) {
if (compressionCfg.getCompressionMode() == null) {
compressionCfg.setCompressionMode(compression.getCompressionMode());
}
if (compressionCfg.getCompressionMode() != CompressionConfig.CompressionMode.OFF) {
if (compressionCfg.getCompressionMinSize() < 512) {
compressionCfg.setCompressionMinSize(compression.getCompressionMinSize());
}
Set<String> mimeTypes = compressionCfg.getCompressibleMimeTypes();
Set<String> newTypes = Sets.newConcurrentHashSet(compression.getCompressibleMimeTypes());
newTypes.addAll(mimeTypes);
compressionCfg.setCompressibleMimeTypes(newTypes);
Set<String> agents = compressionCfg.getNoCompressionUserAgents();
Set<String> newAgents = Sets.newConcurrentHashSet(compression.getNoCompressionUserAgents());
newAgents.addAll(agents);
compressionCfg.setNoCompressionUserAgents(newAgents);
}
}
if (compressionCfg != null) {
compressionConfig.set(compressionCfg);
}
listener.setMaxHttpHeaderSize(98304);
listeners.add(listener);
}
return listeners;
}
示例12: createServer
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
private HttpServer createServer(URI uri, ResourceConfig configuration) {
GrizzlyHttpContainer handler = ContainerFactory.createContainer(GrizzlyHttpContainer.class, configuration);
boolean secure = false;
SSLEngineConfigurator sslEngineConfigurator = null;
boolean start = false;
final String host = (uri.getHost() == null) ? NetworkListener.DEFAULT_NETWORK_HOST
: uri.getHost();
final int port = (uri.getPort() == -1) ? 80 : uri.getPort();
final HttpServer server = new HttpServer();
final NetworkListener listener = new NetworkListener("grizzly", host, port);
listener.setSecure(secure);
if (sslEngineConfigurator != null) {
listener.setSSLEngineConfig(sslEngineConfigurator);
}
// insert
// listener.
CompressionConfig cg = listener.getCompressionConfig();
cg.setCompressionMode(CompressionConfig.CompressionMode.ON);
// cg.setCompressableMimeTypes("text","application/json");
// end insert
server.addListener(listener);
// Map the path to the processor.
final ServerConfiguration config = server.getServerConfiguration();
if (handler != null) {
config.addHttpHandler(handler, uri.getPath());
}
config.setPassTraceRequest(true);
if (start) {
try {
// Start the server.
server.start();
} catch (IOException ex) {
throw new ProcessingException("IOException thrown when trying to start grizzly server", ex);
}
}
return server;
}
示例13: build
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
public SSLEngineConfigurator build(SSLProperties sslProperties) {
SSLContextConfigurator sslContext = new SSLContextConfigurator();
sslContext.setKeyStoreFile(sslProperties.getKeyStoreFile()); // contains server keypair
sslContext.setKeyStorePass(sslProperties.getKeyStorePass());
/**
* trustStore stores public key or certificates from CA (Certificate Authorities)
* which is used to trust remote party or SSL connection. So should be optional
*/
sslProperties.getTrustStoreFile().ifPresent(file->sslContext.setTrustStoreFile(file)); // contains client certificate
sslProperties.getTrustStorePass().ifPresent(pass->sslContext.setTrustStorePass(pass));
sslProperties.getKeyStoreType().ifPresent(type->sslContext.setKeyStoreType(type));
sslProperties.getKeyStoreProvider().ifPresent(provider->sslContext.setKeyStoreProvider(provider));
sslProperties.getTrustStoreType().ifPresent(type->sslContext.setTrustStoreType(type));
sslProperties.getTrustStoreProvider().ifPresent(provider->sslContext.setTrustStoreProvider(provider));
SSLEngineConfigurator sslConf = new SSLEngineConfigurator(sslContext).setClientMode(false);
sslProperties.getClientAuth().filter(auth-> auth.toLowerCase().equals("want"))
.ifPresent(auth->sslConf.setWantClientAuth(true));
sslProperties.getClientAuth().filter(auth-> auth.toLowerCase().equals("need"))
.ifPresent(auth->sslConf.setNeedClientAuth(true));
Maybe.fromOptional(sslProperties.getCiphers()).peek(ciphers->sslConf.setEnabledCipherSuites(ciphers.split(",")))
.forEach(c-> sslConf.setCipherConfigured(true));
Maybe.fromOptional(sslProperties.getProtocol()).peek(pr->sslConf.setEnabledProtocols(pr.split(",")))
.forEach(p->sslConf.setProtocolConfigured(true));
return sslConf;
}
示例14: makeSSLConfig
import org.glassfish.grizzly.ssl.SSLEngineConfigurator; //导入依赖的package包/类
private static SSLEngineConfigurator makeSSLConfig(PropertiesConfiguration properties){
SSLContextConfigurator sslContextConfig = new SSLContextConfigurator();
sslContextConfig.setKeyStoreFile(properties.getString(PROPERTY_KEYSTORE_FILE));
sslContextConfig.setKeyStorePass(properties.getString(PROPERTY_KEYSTORE_PASS));
return new SSLEngineConfigurator(sslContextConfig.createSSLContext(), false, false, false);
}