Skip to content

Commit 1d49b0e

Browse files
Removes artistry introduced in opensearch-project#5186
Signed-off-by: Darshit Chanpura <[email protected]>
1 parent db60398 commit 1d49b0e

File tree

2 files changed

+4
-21
lines changed

2 files changed

+4
-21
lines changed

src/main/java/org/opensearch/security/OpenSearchSecurityPlugin.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,6 @@ public final class OpenSearchSecurityPlugin extends OpenSearchSecuritySSLPlugin
273273
private volatile RestLayerPrivilegesEvaluator restLayerEvaluator;
274274
private volatile ConfigurationRepository cr;
275275
private volatile AdminDNs adminDns;
276-
private volatile org.opensearch.security.common.configuration.AdminDNs adminDNsCommon;
277276
private volatile ClusterService cs;
278277
private volatile AtomicReference<DiscoveryNode> localNode = new AtomicReference<>();
279278
private volatile AuditLog auditLog;
@@ -1138,7 +1137,6 @@ public Collection<Object> createComponents(
11381137
sslExceptionHandler = new AuditLogSslExceptionHandler(auditLog);
11391138

11401139
adminDns = new AdminDNs(settings);
1141-
adminDNsCommon = new org.opensearch.security.common.configuration.AdminDNs(settings);
11421140

11431141
cr = ConfigurationRepository.create(settings, this.configPath, threadPool, localClient, clusterService, auditLog);
11441142

@@ -1169,7 +1167,7 @@ public Collection<Object> createComponents(
11691167

11701168
final var resourceSharingIndex = ResourceSharingConstants.OPENSEARCH_RESOURCE_SHARING_INDEX;
11711169
ResourceSharingIndexHandler rsIndexHandler = new ResourceSharingIndexHandler(resourceSharingIndex, localClient, threadPool);
1172-
ResourceAccessHandler resourceAccessHandler = new ResourceAccessHandler(threadPool, rsIndexHandler, adminDNsCommon);
1170+
ResourceAccessHandler resourceAccessHandler = new ResourceAccessHandler(threadPool, rsIndexHandler, adminDns);
11731171
resourceAccessHandler.initializeRecipientTypes();
11741172
// Resource Sharing index is enabled by default
11751173
boolean isResourceSharingEnabled = settings.getAsBoolean(
@@ -1258,7 +1256,6 @@ public Collection<Object> createComponents(
12581256
}
12591257

12601258
components.add(adminDns);
1261-
components.add(adminDNsCommon);
12621259
components.add(cr);
12631260
components.add(xffResolver);
12641261
components.add(backendRegistry);

src/main/java/org/opensearch/security/auth/BackendRegistry.java

+3-17
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ public boolean authenticate(final SecurityRequestChannel request) {
225225
if (adminDns.isAdminDN(sslPrincipal)) {
226226
// PKI authenticated REST call
227227
User superuser = new User(sslPrincipal);
228-
UserSubject subject = new UserSubjectImpl(threadPool, new org.opensearch.security.common.user.User(sslPrincipal));
228+
UserSubject subject = new UserSubjectImpl(threadPool, superuser);
229229
threadContext.putPersistent(ConfigConstants.OPENDISTRO_SECURITY_AUTHENTICATED_USER, subject);
230230
threadContext.putTransient(ConfigConstants.OPENDISTRO_SECURITY_USER, superuser);
231231
return true;
@@ -393,14 +393,7 @@ public boolean authenticate(final SecurityRequestChannel request) {
393393
final User effectiveUser = impersonatedUser == null ? authenticatedUser : impersonatedUser;
394394
threadPool.getThreadContext().putTransient(ConfigConstants.OPENDISTRO_SECURITY_USER, effectiveUser);
395395

396-
// TODO: The following artistry must be reverted when User class is completely moved to :opensearch-security-common
397-
org.opensearch.security.common.user.User effUser = new org.opensearch.security.common.user.User(
398-
effectiveUser.getName(),
399-
effectiveUser.getRoles(),
400-
null
401-
);
402-
effUser.setAttributes(effectiveUser.getCustomAttributesMap());
403-
UserSubject subject = new UserSubjectImpl(threadPool, effUser);
396+
UserSubject subject = new UserSubjectImpl(threadPool, effectiveUser);
404397
threadPool.getThreadContext().putPersistent(ConfigConstants.OPENDISTRO_SECURITY_AUTHENTICATED_USER, subject);
405398
} else {
406399
if (isDebugEnabled) {
@@ -428,14 +421,7 @@ public boolean authenticate(final SecurityRequestChannel request) {
428421
User anonymousUser = new User(User.ANONYMOUS.getName(), new HashSet<String>(User.ANONYMOUS.getRoles()), null);
429422
anonymousUser.setRequestedTenant(tenant);
430423

431-
org.opensearch.security.common.user.User anonymousUserCommon = new org.opensearch.security.common.user.User(
432-
User.ANONYMOUS.getName(),
433-
new HashSet<>(User.ANONYMOUS.getRoles()),
434-
null
435-
);
436-
anonymousUserCommon.setRequestedTenant(tenant);
437-
438-
UserSubject subject = new UserSubjectImpl(threadPool, anonymousUserCommon);
424+
UserSubject subject = new UserSubjectImpl(threadPool, anonymousUser);
439425

440426
threadPool.getThreadContext().putTransient(ConfigConstants.OPENDISTRO_SECURITY_USER, anonymousUser);
441427
threadPool.getThreadContext().putPersistent(ConfigConstants.OPENDISTRO_SECURITY_AUTHENTICATED_USER, subject);

0 commit comments

Comments
 (0)