forked from opensearch-project/security
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Switch to built-in security transports from core (opensearch-project#…
…4119) ### Description The security plugin does not need to provide the secure transports anymore but SecureSettingsFactory so the core transport modules will be able to configure those. ### Issues Resolved Closes opensearch-project#4118 Is this a backport? If so, please add backport PR # and/or commits # ### Testing [Please provide details of testing done: unit testing, integration testing and manual testing] ### Check List - [ ] New functionality includes testing - [ ] New functionality has been documented - [ ] Commits are signed per the DCO using --signoff By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. For more information on following Developer Certificate of Origin and signing off your commits, please check [here](https://github.com/opensearch-project/OpenSearch/blob/main/CONTRIBUTING.md#developer-certificate-of-origin). --------- Signed-off-by: Andriy Redko <[email protected]>
- Loading branch information
Showing
14 changed files
with
487 additions
and
957 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
src/main/java/org/opensearch/security/ssl/OpenSearchSecureSettingsFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
* | ||
* The OpenSearch Contributors require contributions made to | ||
* this file be licensed under the Apache-2.0 license or a | ||
* compatible open source license. | ||
* | ||
* Modifications Copyright OpenSearch Contributors. See | ||
* GitHub history for details. | ||
*/ | ||
|
||
package org.opensearch.security.ssl; | ||
|
||
import java.util.Optional; | ||
import javax.net.ssl.SSLEngine; | ||
import javax.net.ssl.SSLException; | ||
|
||
import org.opensearch.common.settings.Settings; | ||
import org.opensearch.http.HttpServerTransport; | ||
import org.opensearch.plugins.SecureSettingsFactory; | ||
import org.opensearch.plugins.SecureTransportSettingsProvider; | ||
import org.opensearch.transport.TcpTransport; | ||
|
||
public class OpenSearchSecureSettingsFactory implements SecureSettingsFactory { | ||
private final Settings settings; | ||
private final SecurityKeyStore sks; | ||
private final SslExceptionHandler sslExceptionHandler; | ||
|
||
public OpenSearchSecureSettingsFactory(Settings settings, SecurityKeyStore sks, SslExceptionHandler sslExceptionHandler) { | ||
this.settings = settings; | ||
this.sks = sks; | ||
this.sslExceptionHandler = sslExceptionHandler; | ||
} | ||
|
||
@Override | ||
public Optional<SecureTransportSettingsProvider> getSecureTransportSettingsProvider(Settings settings) { | ||
return Optional.of(new SecureTransportSettingsProvider() { | ||
@Override | ||
public Optional<ServerExceptionHandler> buildHttpServerExceptionHandler(Settings settings, HttpServerTransport transport) { | ||
return Optional.of(new ServerExceptionHandler() { | ||
@Override | ||
public void onError(Throwable t) { | ||
sslExceptionHandler.logError(t, true); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public Optional<ServerExceptionHandler> buildServerTransportExceptionHandler(Settings settings, TcpTransport transport) { | ||
return Optional.of(new ServerExceptionHandler() { | ||
@Override | ||
public void onError(Throwable t) { | ||
sslExceptionHandler.logError(t, false); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public Optional<SSLEngine> buildSecureHttpServerEngine(Settings settings, HttpServerTransport transport) throws SSLException { | ||
return Optional.of(sks.createHTTPSSLEngine()); | ||
} | ||
|
||
@Override | ||
public Optional<SSLEngine> buildSecureServerTransportEngine(Settings settings, TcpTransport transport) throws SSLException { | ||
return Optional.of(sks.createServerTransportSSLEngine()); | ||
} | ||
|
||
@Override | ||
public Optional<SSLEngine> buildSecureClientTransportEngine(Settings settings, String hostname, int port) throws SSLException { | ||
return Optional.of(sks.createClientTransportSSLEngine(hostname, port)); | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.