This commit is contained in:
Fabio Sinibaldi 2022-04-08 11:13:25 +02:00
parent c9e5cf473a
commit 28fca1bb6d
3 changed files with 12 additions and 3 deletions

View File

@ -1,6 +1,8 @@
package org.gcube.application.geoportal.service.rest; package org.gcube.application.geoportal.service.rest;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.gcube.application.cms.plugins.faults.InsufficientPrivileges;
import org.gcube.application.geoportal.common.model.rest.ConfigurationException;
import org.gcube.application.geoportal.service.model.internal.faults.InvalidLockException; import org.gcube.application.geoportal.service.model.internal.faults.InvalidLockException;
import org.gcube.application.geoportal.service.model.internal.faults.ProjectLockedException; import org.gcube.application.geoportal.service.model.internal.faults.ProjectLockedException;
import org.gcube.application.geoportal.service.model.internal.faults.ProjectNotFoundException; import org.gcube.application.geoportal.service.model.internal.faults.ProjectNotFoundException;
@ -26,14 +28,18 @@ public abstract class GuardedMethod<T> {
public GuardedMethod<T> execute() throws WebApplicationException{ public GuardedMethod<T> execute() throws WebApplicationException{
try { try {
if(!preoperations.isEmpty()) { if (!preoperations.isEmpty()) {
log.trace("Running preops (size : {} )", preoperations.size()); log.trace("Running preops (size : {} )", preoperations.size());
for (Runnable r : preoperations) for (Runnable r : preoperations)
r.run(); r.run();
} }
log.trace("Executing actual method.."); log.trace("Executing actual method..");
result=run(); result = run();
return this; return this;
}catch (ConfigurationException e){
throw new WebApplicationException("Environment is not properly configured", e,Status.EXPECTATION_FAILED);
}catch (InsufficientPrivileges e){
throw new WebApplicationException("User has insufficient privileges for requested action", e,Status.FORBIDDEN);
}catch(WebApplicationException e) { }catch(WebApplicationException e) {
log.error("Throwing Web Application Exception ", e); log.error("Throwing Web Application Exception ", e);
throw e; throw e;

View File

@ -83,7 +83,7 @@ public class UserUtils {
user.setUsername(this.getUser().getId()); user.setUsername(this.getUser().getId());
user.setRoles(roles); user.setRoles(roles);
}catch(Exception e){ }catch(Exception e){
log.warn("Unable to determine user id, using FAKE"); log.warn("Unable to determine user id, using FAKE",e);
user.setUsername("FAKE"); user.setUsername("FAKE");
user.setRoles(new HashSet<>()); user.setRoles(new HashSet<>());
user.getRoles().addAll(DEFAULT_ROLES); user.getRoles().addAll(DEFAULT_ROLES);

View File

@ -9,6 +9,7 @@ import org.gcube.application.geoportal.common.model.rest.RegisterFileSetRequest;
import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest; import org.gcube.application.geoportal.common.model.rest.StepExecutionRequest;
import org.gcube.application.geoportal.common.rest.InterfaceConstants; import org.gcube.application.geoportal.common.rest.InterfaceConstants;
import org.gcube.application.geoportal.common.utils.StorageUtils; import org.gcube.application.geoportal.common.utils.StorageUtils;
import org.gcube.application.geoportal.service.utils.UserUtils;
import org.junit.Test; import org.junit.Test;
import javax.ws.rs.client.WebTarget; import javax.ws.rs.client.WebTarget;
@ -18,6 +19,7 @@ import static org.junit.Assert.assertTrue;
public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{ public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
@Override @Override
protected WebTarget baseTarget() { protected WebTarget baseTarget() {
@ -27,6 +29,7 @@ public class ProfiledConcessioniTests extends AbstractProfiledDocumentsTests{
@Test @Test
public void testSDI() throws Exception { public void testSDI() throws Exception {
UserUtils.DEFAULT_ROLES.add("Data-Manager");
// Create new // Create new
Document theDoc=Document.parse("{\n" + Document theDoc=Document.parse("{\n" +
"\"posizionamentoScavo\" :{\n" + "\"posizionamentoScavo\" :{\n" +