Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix batch authorization with transaction role #1325

Merged
merged 1 commit into from Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -75,6 +75,7 @@ public Request processHttpRequest(Service service, Request httpRequest, boolean
.withRequestType(type)
.withUrl(httpRequest.getPath() == null ? null : StringHelper.urlDecode(httpRequest.getPath()))
.withContent(httpRequest.getData())
.withUserPrincipal(httpRequest.getUserPrincipal())
.build();
PluginService plugin = coreSettings.getPluginManager().getServiceForRequestType(serviceRequest.getVersion(), serviceRequest.getRequestType());
final ServiceResponseDefault serviceResponse = new ServiceResponseDefault();
Expand Down Expand Up @@ -136,7 +137,7 @@ public Content processChangeset(ServiceRequest batchRequest, Service service, Ba
if (content instanceof Request) {
Request request = (Request) content;
request.updateUsingContentIds(contentIds);

request.setUserPrincipal(changeset.getUserPrincipal());
Request httpResponse = processHttpRequest(service, request, true);
if (httpResponse.isExecuteFailed()) {
service.rollbackTransaction();
Expand Down Expand Up @@ -168,12 +169,14 @@ public Batch<C> processBatch(ServiceRequest batchRequest, Service service, Batch
Content content = part.getContent();
if (content instanceof Batch) {
Batch<C> changset = (Batch<C>) content;
changset.setUserPrincipal(batchRequest.getUserPrincipal());
Content changesetResponse = processChangeset(batchRequest, service, changset);
Part newPart = batchFactory.createPart(batchVersion, service.getSettings(), false, "");
newPart.setContent(changesetResponse);
batchResponse.addPart(newPart);
} else if (content instanceof Request) {
Request request = (Request) content;
request.setUserPrincipal(batchRequest.getUserPrincipal());
Request httpResponse = processHttpRequest(service, request, false);
Part newPart = batchFactory.createPart(batchVersion, service.getSettings(), false, "");
newPart.setContent(httpResponse);
Expand Down
Expand Up @@ -3,6 +3,7 @@
import de.fraunhofer.iosb.ilt.frostserver.path.Version;
import de.fraunhofer.iosb.ilt.frostserver.service.ServiceRequest;
import de.fraunhofer.iosb.ilt.frostserver.settings.CoreSettings;
import java.security.Principal;
import java.util.ArrayList;
import java.util.List;

Expand All @@ -26,6 +27,7 @@ public abstract class Batch<C extends Content> implements Content {

protected final boolean isChangeSet;
protected final Version batchVersion;
protected Principal userPrincipal;

protected Batch(Version batchVersion, CoreSettings settings, boolean isChangeSet) {
this.batchVersion = batchVersion;
Expand Down Expand Up @@ -59,4 +61,12 @@ public Batch<C> addPart(Part<C> part) {
return this;
}

public Principal getUserPrincipal() {
return userPrincipal;
}

public void setUserPrincipal(Principal userPrincipal) {
this.userPrincipal = userPrincipal;
}

}
Expand Up @@ -3,6 +3,7 @@
import de.fraunhofer.iosb.ilt.frostserver.model.core.Id;
import de.fraunhofer.iosb.ilt.frostserver.path.Version;
import de.fraunhofer.iosb.ilt.frostserver.util.HttpMethod;
import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand All @@ -24,6 +25,8 @@ public abstract class Request implements Content {
protected HttpMethod method;
protected String version;
protected String path;
/** Batch request user. */
protected Principal userPrincipal;

protected final Map<String, String> headersOuter = new HashMap<>();
protected final Map<String, String> headersInner = new HashMap<>();
Expand Down Expand Up @@ -134,6 +137,14 @@ public Map<String, String> getHeaders() {
return headersOuter;
}

public Principal getUserPrincipal() {
return userPrincipal;
}

public void setUserPrincipal(Principal userPrincipal) {
this.userPrincipal = userPrincipal;
}

public String getVersion() {
return version;
}
Expand Down