Skip to content

Commit 926bdda

Browse files
willyborankinRyanL1997
authored andcommitted
Moved isStatic and isReserved methods to the SecurityDynamicConfiguration class Signed-off-by: Andrey Pleskach <ples@aiven.io>
1 parent 9cd0198 commit 926bdda

File tree

2 files changed

+15
-23
lines changed

2 files changed

+15
-23
lines changed

src/main/java/org/opensearch/security/dlic/rest/api/AbstractApiAction.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@
5757
import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator.ErrorType;
5858
import org.opensearch.security.privileges.PrivilegesEvaluator;
5959
import org.opensearch.security.securityconf.DynamicConfigFactory;
60-
import org.opensearch.security.securityconf.Hideable;
61-
import org.opensearch.security.securityconf.StaticDefinable;
6260
import org.opensearch.security.securityconf.impl.CType;
6361
import org.opensearch.security.securityconf.impl.SecurityDynamicConfiguration;
6462
import org.opensearch.security.ssl.transport.PrincipalExtractor;
@@ -588,23 +586,13 @@ protected void notImplemented(RestChannel channel, Method method) {
588586
}
589587

590588
protected final boolean isReserved(SecurityDynamicConfiguration<?> configuration, String resourceName) {
591-
if (isStatic(configuration, resourceName)) { // static is also always reserved
592-
return true;
593-
}
594-
595-
final Object o = configuration.getCEntry(resourceName);
596-
return o != null && o instanceof Hideable && ((Hideable) o).isReserved();
589+
return configuration.isStatic(resourceName) || configuration.isReserved(resourceName);
597590
}
598591

599592
protected final boolean isHidden(SecurityDynamicConfiguration<?> configuration, String resourceName) {
600593
return configuration.isHidden(resourceName) && !isSuperAdmin();
601594
}
602595

603-
protected final boolean isStatic(SecurityDynamicConfiguration<?> configuration, String resourceName) {
604-
final Object o = configuration.getCEntry(resourceName);
605-
return o != null && o instanceof StaticDefinable && ((StaticDefinable) o).isStatic();
606-
}
607-
608596
/**
609597
* Consume all defined parameters for the request. Before we handle the
610598
* request in subclasses where we actually need the parameter, some global
@@ -636,7 +624,7 @@ protected boolean isSuperAdmin() {
636624
* @return True if resource readonly
637625
*/
638626
protected boolean isReadOnly(final SecurityDynamicConfiguration<?> existingConfiguration, String name) {
639-
return isSuperAdmin() ? false : isReserved(existingConfiguration, name);
627+
return !isSuperAdmin() && isReserved(existingConfiguration, name);
640628
}
641629

642630
/**

src/main/java/org/opensearch/security/securityconf/impl/SecurityDynamicConfiguration.java

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,6 @@
4040
import com.fasterxml.jackson.databind.JsonNode;
4141

4242
import org.opensearch.ExceptionsHelper;
43-
import org.opensearch.common.bytes.BytesReference;
44-
import org.opensearch.common.xcontent.XContentHelper;
45-
import org.opensearch.common.xcontent.XContentType;
4643
import org.opensearch.core.xcontent.ToXContent;
4744
import org.opensearch.core.xcontent.XContentBuilder;
4845
import org.opensearch.security.DefaultObjectMapper;
@@ -216,11 +213,6 @@ public boolean exists(String key) {
216213
return centries.containsKey(key);
217214
}
218215

219-
@JsonIgnore
220-
public BytesReference toBytesReference() throws IOException {
221-
return XContentHelper.toXContent(this, XContentType.JSON, false);
222-
}
223-
224216
@Override
225217
public String toString() {
226218
return "SecurityDynamicConfiguration [seqNo="
@@ -322,7 +314,19 @@ public boolean containsAny(SecurityDynamicConfiguration other) {
322314

323315
public boolean isHidden(String resourceName) {
324316
final Object o = centries.get(resourceName);
325-
return o != null && o instanceof Hideable && ((Hideable) o).isHidden();
317+
return o instanceof Hideable && ((Hideable) o).isHidden();
318+
}
319+
320+
@JsonIgnore
321+
public boolean isStatic(final String resourceName) {
322+
final Object o = centries.get(resourceName);
323+
return o instanceof StaticDefinable && ((StaticDefinable) o).isStatic();
324+
}
325+
326+
@JsonIgnore
327+
public boolean isReserved(final String resourceName) {
328+
final Object o = centries.get(resourceName);
329+
return o instanceof Hideable && ((Hideable) o).isReserved();
326330
}
327331

328332
}

0 commit comments

Comments
 (0)