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.
Cleanup SystemIndexTests with RunAsSubjectClient (opensearch-project#…
…5027) Signed-off-by: Craig Perkins <[email protected]>
- Loading branch information
Showing
13 changed files
with
150 additions
and
260 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
48 changes: 0 additions & 48 deletions
48
...rg/opensearch/security/systemindex/sampleplugin/IndexDocumentIntoSystemIndexResponse.java
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
...tionTest/java/org/opensearch/security/systemindex/sampleplugin/PluginContextSwitcher.java
This file was deleted.
Oops, something went wrong.
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
62 changes: 62 additions & 0 deletions
62
...grationTest/java/org/opensearch/security/systemindex/sampleplugin/RunAsSubjectClient.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,62 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.opensearch.security.systemindex.sampleplugin; | ||
|
||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
|
||
import org.opensearch.action.ActionRequest; | ||
import org.opensearch.action.ActionType; | ||
import org.opensearch.client.Client; | ||
import org.opensearch.client.FilterClient; | ||
import org.opensearch.common.util.concurrent.ThreadContext; | ||
import org.opensearch.core.action.ActionListener; | ||
import org.opensearch.core.action.ActionResponse; | ||
import org.opensearch.identity.Subject; | ||
|
||
/** | ||
* Implementation of client that will run transport actions in a stashed context and inject the name of the provided | ||
* subject into the context. | ||
*/ | ||
public class RunAsSubjectClient extends FilterClient { | ||
|
||
private static final Logger logger = LogManager.getLogger(RunAsSubjectClient.class); | ||
|
||
private Subject subject; | ||
|
||
public RunAsSubjectClient(Client delegate) { | ||
super(delegate); | ||
} | ||
|
||
public RunAsSubjectClient(Client delegate, Subject subject) { | ||
super(delegate); | ||
this.subject = subject; | ||
} | ||
|
||
public void setSubject(Subject subject) { | ||
this.subject = subject; | ||
} | ||
|
||
@Override | ||
protected <Request extends ActionRequest, Response extends ActionResponse> void doExecute( | ||
ActionType<Response> action, | ||
Request request, | ||
ActionListener<Response> listener | ||
) { | ||
try (ThreadContext.StoredContext ctx = threadPool().getThreadContext().newStoredContext(false)) { | ||
subject.runAs(() -> { | ||
logger.info("Running transport action with subject: {}", subject.getPrincipal().getName()); | ||
super.doExecute(action, request, ActionListener.runBefore(listener, ctx::restore)); | ||
return null; | ||
}); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} |
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
42 changes: 0 additions & 42 deletions
42
...nTest/java/org/opensearch/security/systemindex/sampleplugin/RunClusterHealthResponse.java
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.