From 0216cc051dd2b106dfd0d178959cc3caa160c7a2 Mon Sep 17 00:00:00 2001 From: Craig Perkins Date: Mon, 14 Oct 2024 15:34:57 -0400 Subject: [PATCH] Address code review feedback Signed-off-by: Craig Perkins --- .../java/org/opensearch/security/auth/BackendRegistry.java | 7 +++---- .../SecurityUserSubject.java => auth/SecurityUser.java} | 6 +++--- .../SecurityUserTests.java} | 6 +++--- .../identity/ContextProvidingPluginSubjectTests.java | 5 +++-- 4 files changed, 12 insertions(+), 12 deletions(-) rename src/main/java/org/opensearch/security/{identity/SecurityUserSubject.java => auth/SecurityUser.java} (89%) rename src/test/java/org/opensearch/security/{identity/SecurityUserSubjectTests.java => auth/SecurityUserTests.java} (90%) diff --git a/src/main/java/org/opensearch/security/auth/BackendRegistry.java b/src/main/java/org/opensearch/security/auth/BackendRegistry.java index fb8eae59fe..5be7e9622a 100644 --- a/src/main/java/org/opensearch/security/auth/BackendRegistry.java +++ b/src/main/java/org/opensearch/security/auth/BackendRegistry.java @@ -64,7 +64,6 @@ import org.opensearch.security.filter.SecurityRequestChannel; import org.opensearch.security.filter.SecurityResponse; import org.opensearch.security.http.XFFResolver; -import org.opensearch.security.identity.SecurityUserSubject; import org.opensearch.security.securityconf.DynamicConfigModel; import org.opensearch.security.support.ConfigConstants; import org.opensearch.security.support.WildcardMatcher; @@ -226,7 +225,7 @@ public boolean authenticate(final SecurityRequestChannel request) { if (adminDns.isAdminDN(sslPrincipal)) { // PKI authenticated REST call User superuser = new User(sslPrincipal); - UserSubject subject = new SecurityUserSubject(threadPool, superuser); + UserSubject subject = new SecurityUser(threadPool, superuser); threadPool.getThreadContext().putPersistent(ConfigConstants.OPENDISTRO_SECURITY_AUTHENTICATED_USER, subject); threadContext.putTransient(ConfigConstants.OPENDISTRO_SECURITY_USER, superuser); auditLog.logSucceededLogin(sslPrincipal, true, null, request); @@ -394,7 +393,7 @@ public boolean authenticate(final SecurityRequestChannel request) { final User impersonatedUser = impersonate(request, authenticatedUser); threadPool.getThreadContext() .putTransient(ConfigConstants.OPENDISTRO_SECURITY_USER, impersonatedUser == null ? authenticatedUser : impersonatedUser); - UserSubject subject = new SecurityUserSubject(threadPool, impersonatedUser == null ? authenticatedUser : impersonatedUser); + UserSubject subject = new SecurityUser(threadPool, impersonatedUser == null ? authenticatedUser : impersonatedUser); threadPool.getThreadContext().putPersistent(ConfigConstants.OPENDISTRO_SECURITY_AUTHENTICATED_USER, subject); auditLog.logSucceededLogin( (impersonatedUser == null ? authenticatedUser : impersonatedUser).getName(), @@ -428,7 +427,7 @@ public boolean authenticate(final SecurityRequestChannel request) { User anonymousUser = new User(User.ANONYMOUS.getName(), new HashSet(User.ANONYMOUS.getRoles()), null); anonymousUser.setRequestedTenant(tenant); - UserSubject subject = new SecurityUserSubject(threadPool, anonymousUser); + UserSubject subject = new SecurityUser(threadPool, anonymousUser); threadPool.getThreadContext().putTransient(ConfigConstants.OPENDISTRO_SECURITY_USER, anonymousUser); threadPool.getThreadContext().putPersistent(ConfigConstants.OPENDISTRO_SECURITY_AUTHENTICATED_USER, subject); diff --git a/src/main/java/org/opensearch/security/identity/SecurityUserSubject.java b/src/main/java/org/opensearch/security/auth/SecurityUser.java similarity index 89% rename from src/main/java/org/opensearch/security/identity/SecurityUserSubject.java rename to src/main/java/org/opensearch/security/auth/SecurityUser.java index 5fab960ffd..8ce4bfb3a1 100644 --- a/src/main/java/org/opensearch/security/identity/SecurityUserSubject.java +++ b/src/main/java/org/opensearch/security/auth/SecurityUser.java @@ -7,7 +7,7 @@ * compatible open source license. * */ -package org.opensearch.security.identity; +package org.opensearch.security.auth; import java.security.Principal; import java.util.concurrent.Callable; @@ -20,12 +20,12 @@ import org.opensearch.security.user.User; import org.opensearch.threadpool.ThreadPool; -public class SecurityUserSubject implements UserSubject { +public class SecurityUser implements UserSubject { private final NamedPrincipal userPrincipal; private final ThreadPool threadPool; private final User user; - public SecurityUserSubject(ThreadPool threadPool, User user) { + SecurityUser(ThreadPool threadPool, User user) { this.threadPool = threadPool; this.user = user; this.userPrincipal = new NamedPrincipal(user.getName()); diff --git a/src/test/java/org/opensearch/security/identity/SecurityUserSubjectTests.java b/src/test/java/org/opensearch/security/auth/SecurityUserTests.java similarity index 90% rename from src/test/java/org/opensearch/security/identity/SecurityUserSubjectTests.java rename to src/test/java/org/opensearch/security/auth/SecurityUserTests.java index d6d9da3ba5..4ae15ef303 100644 --- a/src/test/java/org/opensearch/security/identity/SecurityUserSubjectTests.java +++ b/src/test/java/org/opensearch/security/auth/SecurityUserTests.java @@ -9,7 +9,7 @@ * GitHub history for details. */ -package org.opensearch.security.identity; +package org.opensearch.security.auth; import java.util.concurrent.TimeUnit; @@ -24,7 +24,7 @@ import static org.opensearch.security.support.ConfigConstants.OPENDISTRO_SECURITY_USER; import static org.junit.Assert.assertNull; -public class SecurityUserSubjectTests { +public class SecurityUserTests { public static boolean terminate(ThreadPool threadPool) { return ThreadPool.terminate(threadPool, 10, TimeUnit.SECONDS); @@ -36,7 +36,7 @@ public void testSecurityUserSubjectRunAs() throws Exception { User user = new User("testUser"); - SecurityUserSubject subject = new SecurityUserSubject(threadPool, user); + SecurityUser subject = new SecurityUser(threadPool, user); assertThat(subject.getPrincipal().getName(), equalTo(user.getName())); diff --git a/src/test/java/org/opensearch/security/identity/ContextProvidingPluginSubjectTests.java b/src/test/java/org/opensearch/security/identity/ContextProvidingPluginSubjectTests.java index 0b98913ab8..48851c48b3 100644 --- a/src/test/java/org/opensearch/security/identity/ContextProvidingPluginSubjectTests.java +++ b/src/test/java/org/opensearch/security/identity/ContextProvidingPluginSubjectTests.java @@ -16,6 +16,7 @@ import org.opensearch.common.settings.Settings; import org.opensearch.plugins.IdentityAwarePlugin; import org.opensearch.plugins.Plugin; +import org.opensearch.security.auth.SecurityUserTests; import org.opensearch.security.user.User; import org.opensearch.threadpool.TestThreadPool; import org.opensearch.threadpool.ThreadPool; @@ -52,7 +53,7 @@ public void testSecurityUserSubjectRunAs() throws Exception { assertNull(threadPool.getThreadContext().getTransient(OPENDISTRO_SECURITY_USER)); - SecurityUserSubjectTests.terminate(threadPool); + SecurityUserTests.terminate(threadPool); } @Test @@ -78,7 +79,7 @@ public void testPluginContextSwitcherRunAs() throws Exception { assertNull(threadPool.getThreadContext().getTransient(OPENDISTRO_SECURITY_USER)); - SecurityUserSubjectTests.terminate(threadPool); + SecurityUserTests.terminate(threadPool); } @Test