Fixes Bug #17462, rmp-common-library: check the source scope when an add or remove operation is performed

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portlets/admin/resource-management@181782 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Massimiliano Assante 2019-09-19 15:43:21 +00:00
parent a5b221edb5
commit 7e1fde30be
8 changed files with 48 additions and 25 deletions

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<classpath> <classpath>
<classpathentry kind="src" output="target/resource-management-6.6.1-SNAPSHOT/WEB-INF/classes" path="src/main/java"> <classpathentry kind="src" output="target/resource-management-6.7.0-SNAPSHOT/WEB-INF/classes" path="src/main/java">
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/resource-management-6.6.1-SNAPSHOT/WEB-INF/classes" path="src/main/resources"> <classpathentry excluding="**" kind="src" output="target/resource-management-6.7.0-SNAPSHOT/WEB-INF/classes" path="src/main/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
@ -20,11 +20,13 @@
<attributes> <attributes>
<attribute name="optional" value="true"/> <attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources"> <classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes> <attributes>
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
@ -39,5 +41,5 @@
<attribute name="maven.pomderived" value="true"/> <attribute name="maven.pomderived" value="true"/>
</attributes> </attributes>
</classpathentry> </classpathentry>
<classpathentry kind="output" path="target/resource-management-6.6.1-SNAPSHOT/WEB-INF/classes"/> <classpathentry kind="output" path="target/resource-management-6.7.0-SNAPSHOT/WEB-INF/classes"/>
</classpath> </classpath>

View File

@ -45,6 +45,16 @@
<arguments> <arguments>
</arguments> </arguments>
</buildCommand> </buildCommand>
<buildCommand>
<name>com.gwtplugins.gdt.eclipse.core.webAppProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>com.gwtplugins.gwt.eclipse.core.gwtProjectValidator</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec> </buildSpec>
<natures> <natures>
<nature>org.eclipse.m2e.core.maven2Nature</nature> <nature>org.eclipse.m2e.core.maven2Nature</nature>
@ -56,5 +66,6 @@
<nature>org.eclipse.wst.jsdt.core.jsNature</nature> <nature>org.eclipse.wst.jsdt.core.jsNature</nature>
<nature>com.google.gwt.eclipse.core.gwtNature</nature> <nature>com.google.gwt.eclipse.core.gwtNature</nature>
<nature>com.liferay.ide.core.liferayNature</nature> <nature>com.liferay.ide.core.liferayNature</nature>
<nature>com.gwtplugins.gwt.eclipse.core.gwtNature</nature>
</natures> </natures>
</projectDescription> </projectDescription>

View File

@ -0,0 +1,4 @@
eclipse.preferences.version=1
lastWarOutDir=/Users/massi/Documents/workspace/resource-management/target/resource-management-6.7.0-SNAPSHOT
warSrcDir=src/main/webapp
warSrcDirIsOutput=false

View File

@ -5,4 +5,5 @@ org.eclipse.jdt.core.compiler.compliance=1.7
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.7 org.eclipse.jdt.core.compiler.source=1.7

View File

@ -1,12 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0"> <?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="resource-management-portlet"> <wb-module deploy-name="resource-management">
<wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/> <wb-resource deploy-path="/" source-path="/target/m2e-wtp/web-resources"/>
<wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/> <wb-resource deploy-path="/" source-path="/src/main/webapp" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/java"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/> <wb-resource deploy-path="/WEB-INF/classes" source-path="/src/main/resources"/>
<dependent-module archiveName="rmp-common-library-2.8.1-SNAPSHOT.jar" deploy-path="/WEB-INF/lib" handle="module:/resource/rmp-common-library/rmp-common-library">
<dependency-type>uses</dependency-type>
</dependent-module>
<property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/> <property name="java-output-path" value="/${module}/target/www/WEB-INF/classes"/>
<property name="context-root" value="resource-management"/> <property name="context-root" value="resource-management"/>
</wb-module> </wb-module>

View File

@ -6,4 +6,5 @@
<installed facet="liferay.portlet" version="6.0"/> <installed facet="liferay.portlet" version="6.0"/>
<installed facet="jst.jaxrs" version="2.0"/> <installed facet="jst.jaxrs" version="2.0"/>
<installed facet="java" version="1.7"/> <installed facet="java" version="1.7"/>
<installed facet="com.gwtplugins.gwt.facet" version="1.0"/>
</faceted-project> </faceted-project>

View File

@ -12,7 +12,7 @@
<groupId>org.gcube.portlets.admin</groupId> <groupId>org.gcube.portlets.admin</groupId>
<artifactId>resource-management</artifactId> <artifactId>resource-management</artifactId>
<version>6.6.1-SNAPSHOT</version> <version>6.7.0-SNAPSHOT</version>
<packaging>war</packaging> <packaging>war</packaging>
<name>gCube Resource Management Portlet</name> <name>gCube Resource Management Portlet</name>
<description> <description>
@ -103,7 +103,7 @@
<dependency> <dependency>
<groupId>org.gcube.portlets.admin</groupId> <groupId>org.gcube.portlets.admin</groupId>
<artifactId>rmp-common-library</artifactId> <artifactId>rmp-common-library</artifactId>
<version>[2.7.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version> <version>[2.8.3-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency> </dependency>
<!-- FWS DEPS --> <!-- FWS DEPS -->
<dependency> <dependency>
@ -124,7 +124,7 @@
<dependency> <dependency>
<groupId>org.gcube.core</groupId> <groupId>org.gcube.core</groupId>
<artifactId>common-scope-maps</artifactId> <artifactId>common-scope-maps</artifactId>
<scope>compile</scope> <scope>provided</scope>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.gcube.resourcemanagement</groupId> <groupId>org.gcube.resourcemanagement</groupId>

View File

@ -21,16 +21,12 @@ import static org.gcube.resources.discovery.icclient.ICFactory.client;
import java.io.File; import java.io.File;
import java.io.StringReader; import java.io.StringReader;
import java.security.InvalidParameterException; import java.security.InvalidParameterException;
import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Vector; import java.util.Vector;
import javax.crypto.SecretKeyFactory;
import javax.crypto.spec.PBEKeySpec;
import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSession;
import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.DocumentBuilderFactory;
@ -38,9 +34,11 @@ import javax.xml.parsers.DocumentBuilderFactory;
import org.gcube.common.resources.gcore.utils.XPathHelper; import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.common.scope.api.ScopeProvider; import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.common.scope.impl.ScopeBean; import org.gcube.common.scope.impl.ScopeBean;
import org.gcube.common.scope.impl.ScopeBean.Type;
import org.gcube.portlets.admin.resourcemanagement.client.remote.ServiceProxy; import org.gcube.portlets.admin.resourcemanagement.client.remote.ServiceProxy;
import org.gcube.portlets.admin.resourcemanagement.server.gcube.services.StatusHandler; import org.gcube.portlets.admin.resourcemanagement.server.gcube.services.StatusHandler;
import org.gcube.portlets.admin.resourcemanagement.server.gcube.services.configuration.ConfigurationLoader; import org.gcube.portlets.admin.resourcemanagement.server.gcube.services.configuration.ConfigurationLoader;
import org.gcube.portlets.admin.resourcemanagement.shared.utils.BCrypt;
import org.gcube.resourcemanagement.support.client.utils.CurrentStatus; import org.gcube.resourcemanagement.support.client.utils.CurrentStatus;
import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator; import org.gcube.resourcemanagement.support.client.views.ResourceTypeDecorator;
import org.gcube.resourcemanagement.support.server.gcube.CacheManager; import org.gcube.resourcemanagement.support.server.gcube.CacheManager;
@ -68,9 +66,7 @@ import org.gcube.vremanagement.resourcemanager.client.RMReportingLibrary;
import org.w3c.dom.Node; import org.w3c.dom.Node;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.server.rpc.RemoteServiceServlet; import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import org.gcube.portlets.admin.resourcemanagement.shared.utils.BCrypt;
/** /**
* @author Daniele Strollo * @author Daniele Strollo
@ -168,10 +164,16 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro
checker.validate(resType != null && resType.trim().length() > 0, new Exception("Invalid parameter type")); checker.validate(resType != null && resType.trim().length() > 0, new Exception("Invalid parameter type"));
checker.validate(resourceIDs != null && resourceIDs.size() > 0, new Exception("Invalid parameter type")); checker.validate(resourceIDs != null && resourceIDs.size() > 0, new Exception("Invalid parameter type"));
checker.validate(scope != null && scope.trim().length() > 0, new Exception("Invalid parameter type")); checker.validate(scope != null && scope.trim().length() > 0, new Exception("Invalid parameter type"));
AllowedResourceTypes type = AllowedResourceTypes.valueOf(resType); AllowedResourceTypes type = AllowedResourceTypes.valueOf(resType);
ScopeBean targetScope = new ScopeBean(scope); ScopeBean targetScope = new ScopeBean(scope);
ScopeBean sourceScope = new ScopeBean(status.getCurrentScope()); ScopeBean sourceScope = new ScopeBean(status.getCurrentScope());
//new check
if (sourceScope.type() == Type.INFRASTRUCTURE && targetScope.type() == Type.VRE ) {
throw new Exception("Because adding a VRE Context from the Root VO is not allowed.");
}
String reportID = ManagementUtils.addToExistingScope(type, String reportID = ManagementUtils.addToExistingScope(type,
resourceIDs.toArray(new String[]{}), resourceIDs.toArray(new String[]{}),
@ -211,13 +213,18 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro
AllowedResourceTypes type = AllowedResourceTypes.valueOf(resType); AllowedResourceTypes type = AllowedResourceTypes.valueOf(resType);
ScopeBean targetScope = new ScopeBean(scope); ScopeBean targetScope = new ScopeBean(scope);
ScopeBean sourceScope = new ScopeBean(status.getCurrentScope()); ScopeBean sourceScope = new ScopeBean(status.getCurrentScope());
//new check
if (sourceScope.type() == Type.INFRASTRUCTURE && targetScope.type() == Type.VRE ) {
throw new Exception("Because removing a VRE Context from the Root VO is not allowed.");
}
String reportID = ManagementUtils.removeFromExistingScope(type, String reportID = ManagementUtils.removeFromExistingScope(type,
resourceIDs.toArray(new String[]{}), resourceIDs.toArray(new String[]{}),
sourceScope, sourceScope,
targetScope); targetScope);
RMReportingLibrary manager = RMReportingLibrary manager =
ResourceFactory.createResourceManager(type).getReportResourceManager(targetScope.toString()); ResourceFactory.createResourceManager(type).getReportResourceManager(targetScope.toString());
@ -265,14 +272,14 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro
Map<String, ScopeBean> scopes = ScopeManager.getAvailableScopes(); Map<String, ScopeBean> scopes = ScopeManager.getAvailableScopes();
for (ScopeBean scope : scopes.values()) for (ScopeBean scope : scopes.values())
retval.add(scope.toString()); retval.add(scope.toString());
return retval; return retval;
} catch (Exception e) { } catch (Exception e) {
retval.add("/gcube"); retval.add("/gcube");
retval.add("/gcube/devsec"); retval.add("/gcube/devsec");
e.printStackTrace(); e.printStackTrace();
} }
return retval; return retval;
} }
@ -354,12 +361,12 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro
if (results != null && results.size() > 0) { if (results != null && results.size() > 0) {
ResourceDescriptor retval = new ResourceDescriptor(); ResourceDescriptor retval = new ResourceDescriptor();
List<String> currValue = null; List<String> currValue = null;
DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); DocumentBuilder docBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Node node = docBuilder.parse(new InputSource(new StringReader(results.get(0)))).getDocumentElement(); Node node = docBuilder.parse(new InputSource(new StringReader(results.get(0)))).getDocumentElement();
XPathHelper helper = new XPathHelper(node); XPathHelper helper = new XPathHelper(node);
currValue = helper.evaluate("/Resource/ID/text()"); currValue = helper.evaluate("/Resource/ID/text()");
if (currValue != null && currValue.size() > 0) { if (currValue != null && currValue.size() > 0) {
retval.setID(currValue.get(0)); retval.setID(currValue.get(0));
@ -529,6 +536,6 @@ public class ServiceProxyImpl extends RemoteServiceServlet implements ServicePro
ServerConsole.info(LOG_PREFIX, "FAILED ATTEMPT SUPER USER MODE FROM IP: " + ipAddressCaller); ServerConsole.info(LOG_PREFIX, "FAILED ATTEMPT SUPER USER MODE FROM IP: " + ipAddressCaller);
return matched; return matched;
} }
} }