Skip to content

Commit

Permalink
Misc changes (opensearch-project#2902)
Browse files Browse the repository at this point in the history
Moved isStatic and isReserved methods to the
SecurityDynamicConfiguration class

Signed-off-by: Andrey Pleskach <ples@aiven.io>
  • Loading branch information
willyborankin authored and RyanL1997 committed Jun 29, 2023
1 parent 9cd0198 commit 926bdda
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,6 @@
import org.opensearch.security.dlic.rest.validation.AbstractConfigurationValidator.ErrorType;
import org.opensearch.security.privileges.PrivilegesEvaluator;
import org.opensearch.security.securityconf.DynamicConfigFactory;
import org.opensearch.security.securityconf.Hideable;
import org.opensearch.security.securityconf.StaticDefinable;
import org.opensearch.security.securityconf.impl.CType;
import org.opensearch.security.securityconf.impl.SecurityDynamicConfiguration;
import org.opensearch.security.ssl.transport.PrincipalExtractor;
Expand Down Expand Up @@ -588,23 +586,13 @@ protected void notImplemented(RestChannel channel, Method method) {
}

protected final boolean isReserved(SecurityDynamicConfiguration<?> configuration, String resourceName) {
if (isStatic(configuration, resourceName)) { // static is also always reserved
return true;
}

final Object o = configuration.getCEntry(resourceName);
return o != null && o instanceof Hideable && ((Hideable) o).isReserved();
return configuration.isStatic(resourceName) || configuration.isReserved(resourceName);
}

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

protected final boolean isStatic(SecurityDynamicConfiguration<?> configuration, String resourceName) {
final Object o = configuration.getCEntry(resourceName);
return o != null && o instanceof StaticDefinable && ((StaticDefinable) o).isStatic();
}

/**
* Consume all defined parameters for the request. Before we handle the
* request in subclasses where we actually need the parameter, some global
Expand Down Expand Up @@ -636,7 +624,7 @@ protected boolean isSuperAdmin() {
* @return True if resource readonly
*/
protected boolean isReadOnly(final SecurityDynamicConfiguration<?> existingConfiguration, String name) {
return isSuperAdmin() ? false : isReserved(existingConfiguration, name);
return !isSuperAdmin() && isReserved(existingConfiguration, name);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@
import com.fasterxml.jackson.databind.JsonNode;

import org.opensearch.ExceptionsHelper;
import org.opensearch.common.bytes.BytesReference;
import org.opensearch.common.xcontent.XContentHelper;
import org.opensearch.common.xcontent.XContentType;
import org.opensearch.core.xcontent.ToXContent;
import org.opensearch.core.xcontent.XContentBuilder;
import org.opensearch.security.DefaultObjectMapper;
Expand Down Expand Up @@ -216,11 +213,6 @@ public boolean exists(String key) {
return centries.containsKey(key);
}

@JsonIgnore
public BytesReference toBytesReference() throws IOException {
return XContentHelper.toXContent(this, XContentType.JSON, false);
}

@Override
public String toString() {
return "SecurityDynamicConfiguration [seqNo="
Expand Down Expand Up @@ -322,7 +314,19 @@ public boolean containsAny(SecurityDynamicConfiguration other) {

public boolean isHidden(String resourceName) {
final Object o = centries.get(resourceName);
return o != null && o instanceof Hideable && ((Hideable) o).isHidden();
return o instanceof Hideable && ((Hideable) o).isHidden();
}

@JsonIgnore
public boolean isStatic(final String resourceName) {
final Object o = centries.get(resourceName);
return o instanceof StaticDefinable && ((StaticDefinable) o).isStatic();
}

@JsonIgnore
public boolean isReserved(final String resourceName) {
final Object o = centries.get(resourceName);
return o instanceof Hideable && ((Hideable) o).isReserved();
}

}

0 comments on commit 926bdda

Please sign in to comment.