Skip to content

Commit

Permalink
Address code review feedback
Browse files Browse the repository at this point in the history
Signed-off-by: Craig Perkins <[email protected]>
  • Loading branch information
cwperks committed Oct 14, 2024
1 parent 275a346 commit 0216cc0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -428,7 +427,7 @@ public boolean authenticate(final SecurityRequestChannel request) {
User anonymousUser = new User(User.ANONYMOUS.getName(), new HashSet<String>(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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* GitHub history for details.
*/

package org.opensearch.security.identity;
package org.opensearch.security.auth;

import java.util.concurrent.TimeUnit;

Expand All @@ -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);
Expand All @@ -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()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,7 +53,7 @@ public void testSecurityUserSubjectRunAs() throws Exception {

assertNull(threadPool.getThreadContext().getTransient(OPENDISTRO_SECURITY_USER));

SecurityUserSubjectTests.terminate(threadPool);
SecurityUserTests.terminate(threadPool);
}

@Test
Expand All @@ -78,7 +79,7 @@ public void testPluginContextSwitcherRunAs() throws Exception {

assertNull(threadPool.getThreadContext().getTransient(OPENDISTRO_SECURITY_USER));

SecurityUserSubjectTests.terminate(threadPool);
SecurityUserTests.terminate(threadPool);
}

@Test
Expand Down

0 comments on commit 0216cc0

Please sign in to comment.