Skip to content

Commit

Permalink
Pass flag
Browse files Browse the repository at this point in the history
  • Loading branch information
n1v0lg committed Feb 11, 2024
1 parent 63fe554 commit db91152
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
package org.elasticsearch.xpack.core.security.action.role;

import org.elasticsearch.client.internal.Client;
import org.elasticsearch.xpack.core.security.SecurityContext;

import java.util.function.Predicate;

public interface PutRoleRequestBuilderFactory {
PutRoleRequestBuilder create(Client client, SecurityContext securityContext, Predicate<String> fileRolesStoreNameChecker);
PutRoleRequestBuilder create(Client client, boolean restrictRequest, Predicate<String> fileRolesStoreNameChecker);

class Default implements PutRoleRequestBuilderFactory {
@Override
public PutRoleRequestBuilder create(Client client, SecurityContext securityContext, Predicate<String> fileRolesStoreNameChecker) {
public PutRoleRequestBuilder create(Client client, boolean restrictRequest, Predicate<String> fileRolesStoreNameChecker) {
return new PutRoleRequestBuilder(client);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1425,13 +1425,7 @@ public List<RestHandler> getRestHandlers(
new RestPutUserAction(settings, getLicenseState()),
new RestDeleteUserAction(settings, getLicenseState()),
new RestGetRolesAction(settings, getLicenseState()),
new RestPutRoleAction(
settings,
getLicenseState(),
securityContext.get(),
putRoleRequestBuilderFactory.get(),
fileRolesStore.get()
),
new RestPutRoleAction(settings, getLicenseState(), putRoleRequestBuilderFactory.get(), fileRolesStore.get()),
new RestDeleteRoleAction(settings, getLicenseState()),
new RestChangePasswordAction(settings, securityContext.get(), getLicenseState()),
new RestSetEnabledAction(settings, getLicenseState()),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import org.elasticsearch.rest.ServerlessScope;
import org.elasticsearch.rest.action.RestBuilderListener;
import org.elasticsearch.xcontent.XContentBuilder;
import org.elasticsearch.xpack.core.security.SecurityContext;
import org.elasticsearch.xpack.core.security.action.role.PutRoleRequestBuilder;
import org.elasticsearch.xpack.core.security.action.role.PutRoleRequestBuilderFactory;
import org.elasticsearch.xpack.core.security.action.role.PutRoleResponse;
Expand All @@ -35,19 +34,16 @@
@ServerlessScope(Scope.PUBLIC)
public class RestPutRoleAction extends NativeRoleBaseRestHandler {

private final SecurityContext securityContext;
private final PutRoleRequestBuilderFactory builderFactory;
private final FileRolesStore fileRolesStore;

public RestPutRoleAction(
Settings settings,
XPackLicenseState licenseState,
SecurityContext securityContext,
PutRoleRequestBuilderFactory builderFactory,
FileRolesStore fileRolesStore
) {
super(settings, licenseState);
this.securityContext = securityContext;
this.builderFactory = builderFactory;
this.fileRolesStore = fileRolesStore;
}
Expand All @@ -67,7 +63,8 @@ public String getName() {

@Override
public RestChannelConsumer innerPrepareRequest(RestRequest request, NodeClient client) throws IOException {
final PutRoleRequestBuilder requestBuilder = builderFactory.create(client, securityContext, fileRolesStore::exists)
final boolean restrictRequest = request.hasParam(RestRequest.RESPONSE_RESTRICTED);
final PutRoleRequestBuilder requestBuilder = builderFactory.create(client, restrictRequest, fileRolesStore::exists)
.source(request.param("name"), request.requiredContent(), request.getXContentType())
.setRefreshPolicy(request.param("refresh"));
return channel -> requestBuilder.execute(new RestBuilderListener<>(channel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testFailureWhenNativeRolesDisabled() throws Exception {

try (var threadPool = createThreadPool()) {
final var nodeClient = new NoOpNodeClient(threadPool);
final RestPutRoleAction action = new RestPutRoleAction(securityDisabledSettings, licenseState, mock(), mock(), mock());
final RestPutRoleAction action = new RestPutRoleAction(securityDisabledSettings, licenseState, mock(), mock());
action.handleRequest(request, channel, nodeClient);
}

Expand Down

0 comments on commit db91152

Please sign in to comment.