Skip to content

Commit ff01e72

Browse files
committed
ConfigModel retirement was not completely done. Now fully deleted.
Signed-off-by: Nils Bandener <[email protected]>
1 parent c963625 commit ff01e72

File tree

8 files changed

+24
-305
lines changed

8 files changed

+24
-305
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,6 @@ public Collection<Object> createComponents(
11701170
backendRegistry = new BackendRegistry(settings, adminDns, xffResolver, auditLog, threadPool, cih);
11711171
backendRegistry.registerClusterSettingsChangeListener(clusterService.getClusterSettings());
11721172
cr.subscribeOnChange(configMap -> { backendRegistry.invalidateCache(); });
1173-
tokenManager = new SecurityTokenManager(cs, threadPool, userService);
11741173

11751174
final CompatConfig compatConfig = new CompatConfig(environment, transportPassiveAuthSetting);
11761175

@@ -1181,6 +1180,7 @@ public Collection<Object> createComponents(
11811180
threadPool.getThreadContext()
11821181
);
11831182
this.roleMapper = roleMapper;
1183+
tokenManager = new SecurityTokenManager(cs, threadPool, userService, roleMapper);
11841184

11851185
PrivilegesConfiguration privilegesConfiguration = new PrivilegesConfiguration(
11861186
cr,

src/main/java/org/opensearch/security/identity/SecurityTokenManager.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
import org.opensearch.security.authtoken.jwt.ExpiringBearerAuthToken;
3333
import org.opensearch.security.authtoken.jwt.JwtVendor;
3434
import org.opensearch.security.authtoken.jwt.claims.OBOJwtClaimsBuilder;
35-
import org.opensearch.security.securityconf.ConfigModel;
35+
import org.opensearch.security.privileges.RoleMapper;
3636
import org.opensearch.security.securityconf.DynamicConfigModel;
3737
import org.opensearch.security.support.ConfigConstants;
3838
import org.opensearch.security.user.User;
@@ -53,21 +53,22 @@ public class SecurityTokenManager implements TokenManager {
5353
private final ClusterService cs;
5454
private final ThreadPool threadPool;
5555
private final UserService userService;
56+
private final RoleMapper roleMapper;
5657

5758
private Settings oboSettings = null;
58-
private ConfigModel configModel = null;
5959
private final LongSupplier timeProvider = System::currentTimeMillis;
6060
private static final Integer OBO_MAX_EXPIRY_SECONDS = 600;
6161

62-
public SecurityTokenManager(final ClusterService cs, final ThreadPool threadPool, final UserService userService) {
62+
public SecurityTokenManager(
63+
final ClusterService cs,
64+
final ThreadPool threadPool,
65+
final UserService userService,
66+
RoleMapper roleMapper
67+
) {
6368
this.cs = cs;
6469
this.threadPool = threadPool;
6570
this.userService = userService;
66-
}
67-
68-
@Subscribe
69-
public void onConfigModelChanged(final ConfigModel configModel) {
70-
this.configModel = configModel;
71+
this.roleMapper = roleMapper;
7172
}
7273

7374
@Subscribe
@@ -90,7 +91,7 @@ JwtVendor createJwtVendor(final Settings settings) {
9091
}
9192

9293
public boolean issueOnBehalfOfTokenAllowed() {
93-
return oboSettings != null && configModel != null;
94+
return oboSettings != null;
9495
}
9596

9697
@Override
@@ -117,7 +118,7 @@ public ExpiringBearerAuthToken issueOnBehalfOfToken(final Subject subject, final
117118
}
118119

119120
final TransportAddress callerAddress = null; /* OBO tokens must not roles based on location from network address */
120-
final Set<String> mappedRoles = configModel.mapSecurityRoles(user, callerAddress);
121+
final Set<String> mappedRoles = this.roleMapper.map(user, callerAddress);
121122

122123
final long currentTimeMs = timeProvider.getAsLong();
123124
final Date now = new Date(currentTimeMs);

src/main/java/org/opensearch/security/privileges/PrivilegesEvaluatorImpl.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.function.Supplier;
3939

4040
import com.google.common.collect.ImmutableList;
41+
import com.google.common.collect.ImmutableMap;
4142
import com.google.common.collect.ImmutableSet;
4243
import org.apache.logging.log4j.LogManager;
4344
import org.apache.logging.log4j.Logger;
@@ -145,7 +146,7 @@ public class PrivilegesEvaluatorImpl implements PrivilegesEvaluator {
145146
private final PitPrivilegesEvaluator pitPrivilegesEvaluator;
146147
private final Settings settings;
147148
private final AtomicReference<RoleBasedActionPrivileges> actionPrivileges = new AtomicReference<>();
148-
private final Map<String, SubjectBasedActionPrivileges> pluginIdToActionPrivileges = new HashMap<>();
149+
private final ImmutableMap<String, ActionPrivileges> pluginIdToActionPrivileges;
149150
private final RoleMapper roleMapper;
150151

151152
private volatile boolean dnfofEnabled = false;
@@ -197,7 +198,7 @@ public PrivilegesEvaluatorImpl(
197198
termsAggregationEvaluator = new TermsAggregationEvaluator();
198199
pitPrivilegesEvaluator = new PitPrivilegesEvaluator();
199200

200-
this.pluginIdToActionPrivileges.putAll(createActionPrivileges(pluginIdToRolePrivileges, staticActionGroups));
201+
this.pluginIdToActionPrivileges = createActionPrivileges(pluginIdToRolePrivileges, staticActionGroups);
201202
this.updateConfiguration(actionGroups, rolesConfiguration, generalConfiguration);
202203
}
203204

@@ -267,10 +268,7 @@ public PrivilegesEvaluationContext createContext(
267268

268269
if (user.isPluginUser()) {
269270
mappedRoles = ImmutableSet.of();
270-
actionPrivileges = this.pluginIdToActionPrivileges.get(user.getName());
271-
if (actionPrivileges == null) {
272-
actionPrivileges = ActionPrivileges.EMPTY;
273-
}
271+
actionPrivileges = this.pluginIdToActionPrivileges.getOrDefault(user.getName(), ActionPrivileges.EMPTY);
274272
} else {
275273
mappedRoles = this.roleMapper.map(user, caller);
276274
actionPrivileges = this.actionPrivileges.get();
@@ -731,7 +729,7 @@ private List<String> toString(List<AliasMetadata> aliases) {
731729
return Collections.unmodifiableList(ret);
732730
}
733731

734-
private static Map<String, SubjectBasedActionPrivileges> createActionPrivileges(
732+
private static ImmutableMap<String, ActionPrivileges> createActionPrivileges(
735733
Map<String, RoleV7> pluginIdToRolePrivileges,
736734
FlattenedActionGroups staticActionGroups
737735
) {
@@ -741,7 +739,7 @@ private static Map<String, SubjectBasedActionPrivileges> createActionPrivileges(
741739
result.put(entry.getKey(), new SubjectBasedActionPrivileges(entry.getValue(), staticActionGroups));
742740
}
743741

744-
return result;
742+
return ImmutableMap.copyOf(result);
745743
}
746744

747745
private static boolean isDnfofEnabled(ConfigV7 generalConfiguration) {

src/main/java/org/opensearch/security/securityconf/ConfigModel.java

Lines changed: 0 additions & 36 deletions
This file was deleted.

src/main/java/org/opensearch/security/securityconf/ConfigModelV7.java

Lines changed: 0 additions & 193 deletions
This file was deleted.

src/main/java/org/opensearch/security/securityconf/DynamicConfigFactory.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,6 @@ public void onChange(ConfigurationMap typeToConfig) {
236236

237237
final DynamicConfigModel dcm;
238238
final InternalUsersModel ium;
239-
final ConfigModel cm;
240239
final NodesDnModel nm = new NodesDnModelImpl(nodesDn);
241240
final AllowlistingSettings allowlist = cr.getConfiguration(CType.ALLOWLIST).getCEntry("config");
242241
final AuditConfig audit = cr.getConfiguration(CType.AUDIT).getCEntry("config");
@@ -278,10 +277,8 @@ public void onChange(ConfigurationMap typeToConfig) {
278277
// rebuild v7 Models
279278
dcm = new DynamicConfigModelV7(getConfigV7(config), opensearchSettings, configPath, iab, this.cih);
280279
ium = new InternalUsersModelV7(internalusers, roles, rolesmapping);
281-
cm = new ConfigModelV7(roles, rolesmapping, dcm, opensearchSettings);
282280

283281
// notify subscribers
284-
eventBus.post(cm);
285282
eventBus.post(dcm);
286283
eventBus.post(ium);
287284
eventBus.post(nm);

src/test/java/org/opensearch/security/auth/http/saml/HTTPSamlAuthenticatorTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,11 @@ public boolean detailedErrorsEnabled() {
999999
return false;
10001000
}
10011001

1002+
@Override
1003+
public boolean detailedErrorStackTraceEnabled() {
1004+
return false;
1005+
}
1006+
10021007
@Override
10031008
public void sendResponse(RestResponse response) {
10041009
this.response = response;

0 commit comments

Comments
 (0)