Merged release gcube 4.15.0

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/spatial-data/sdi-service@182281 82a268e6-3cf1-43bd-a215-b396298e98cf
master
Fabio Sinibaldi 4 years ago
parent aa401e40cd
commit ee43e4ed1f

@ -4,11 +4,11 @@
<parent>
<groupId>org.gcube.tools</groupId>
<artifactId>maven-parent</artifactId>
<version>LATEST</version>
<version>1.1.0</version>
</parent>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>sdi-service</artifactId>
<version>1.3.0-SNAPSHOT</version>
<version>1.4.0-SNAPSHOT</version>
<name>SDI Service</name>
<description>REST Interface towards SDI facilities</description>
<packaging>war</packaging>
@ -35,29 +35,33 @@
<dependencies>
<dependency>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>gis-interface</artifactId>
<version>[2.4.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
<exclusions>
<exclusion>
<artifactId>slf4j-log4j12</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<!-- <dependency> -->
<!-- <groupId>org.gcube.spatial.data</groupId> -->
<!-- <artifactId>gis-interface</artifactId> -->
<!-- <version>[2.4.0-SNAPSHOT,3.0.0-SNAPSHOT)</version> -->
<!-- <exclusions> -->
<!-- <exclusion> -->
<!-- <artifactId>slf4j-log4j12</artifactId> -->
<!-- <groupId>org.slf4j</groupId> -->
<!-- </exclusion> -->
<!-- </exclusions> -->
<!-- </dependency> -->
<dependency>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>sdi-interface</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>uri-resolver-manager</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.gcube.data.transfer</groupId>
<artifactId>data-transfer-library</artifactId>
<version>[1.2.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<version>[1.2.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
@ -222,6 +226,61 @@
</exclusions>
</dependency>
<!-- GN EXTERNAL -->
<dependency>
<groupId>it.geosolutions</groupId>
<artifactId>geonetwork-manager</artifactId>
<version>1.4-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.geotoolkit</groupId>
<artifactId>geotk-metadata</artifactId>
<version>3.20</version>
</dependency>
<dependency>
<groupId>org.w3c</groupId>
<artifactId>dom</artifactId>
<version>2.3.0-jaxb-1.0.6</version>
</dependency>
<dependency>
<groupId>org.geotoolkit</groupId>
<artifactId>geotk-referencing</artifactId>
<version>3.20</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.9</version>
</dependency>
<!-- META -->
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.25-incubating</version>
</dependency>
<!-- GS EXTERNAL -->
<dependency>
<groupId>it.geosolutions</groupId>
<artifactId>geoserver-manager</artifactId>
<version>1.5.2</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>jcl-over-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- test -->
<dependency>

@ -36,7 +36,7 @@ public class LocalConfiguration {
final static public String GEONETWORK_SE_CONFIDENTIAL_GROUP_PREFIX="gn.se.confidential.group.prefix";
final static public String GEONETWORK_SE_CONTEXT_GROUP_PREFIX="gn.se.context.group.prefix";
final static public String GEONETWORK_GROUP_ALL="gn.groups.all";
final static public String GEONETWORK_GROUP_MAX_LENGTH="gn.groups.max_length";
final static public String GEONETWORK_MANDATORY_SG="gn.mandatorySG";

@ -1,70 +0,0 @@
package org.gcube.spatial.data.sdi;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.util.ArrayList;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class ScopeUtils {
public static String getCurrentScope(){
// try{
// String token=SecurityTokenProvider.instance.get();
// log.debug("Token is : "+token);
// if(token==null) throw new Exception("Security Token is null");
// AuthorizationEntry entry = authorizationService().get(token);
// return entry.getContext();
// }catch(Exception e ){
// log.debug("Unable to resolve token, checking scope provider..",e);
// return ScopeProvider.instance.get();
// }
String scope=ScopeProvider.instance.get();
if(scope!=null) {
log.debug("Found scope provider {}, skipping token",scope);
return scope;
}else{
try{
log.debug("Scope provider not set, reverting to token");
String token=SecurityTokenProvider.instance.get();
log.debug("Token is : "+token);
if(token==null) throw new Exception("Security Token is null");
AuthorizationEntry entry = authorizationService().get(token);
return entry.getContext();
}catch(Exception e){
throw new RuntimeException("Unable to evaluate scope ",e);
}
}
}
public static String getCurrentScopeName(){
return getScopeName(getCurrentScope());
}
public static String getScopeName(String scope) {
return scope.substring(scope.lastIndexOf('/')+1);
}
public static ArrayList<String> getParentScopes(String scope){
String[] splitted=scope.substring(1).split("/");
ArrayList<String> toReturn=new ArrayList<String>();
for(int i=0;i<splitted.length-1;i++){
toReturn.add(splitted[i]);
}
return toReturn;
}
public static String getParentScope(String scope) {
if(scope.lastIndexOf("/")==0) return null; // NO PARENT
else return scope.substring(0, scope.lastIndexOf("/"));
}
}

@ -3,7 +3,6 @@ package org.gcube.spatial.data.sdi.engine.impl;
import javax.inject.Inject;
import javax.inject.Singleton;
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import org.gcube.spatial.data.sdi.engine.GISManager;
import org.gcube.spatial.data.sdi.engine.GeoNetworkManager;
import org.gcube.spatial.data.sdi.engine.SDIManager;
@ -18,6 +17,7 @@ import org.gcube.spatial.data.sdi.model.services.GeoNetworkServiceDefinition;
import org.gcube.spatial.data.sdi.model.services.GeoServerDefinition;
import org.gcube.spatial.data.sdi.model.services.ServiceDefinition;
import org.gcube.spatial.data.sdi.model.services.ThreddsDefinition;
import org.gcube.spatial.data.sdi.utils.ScopeUtils;
import lombok.extern.slf4j.Slf4j;

@ -33,12 +33,14 @@ public class ThreddsManagerImpl extends AbstractManager<ThreddsDescriptor, Thred
private ThreddsRetriever retriever=null;
@Inject
TemplateManager templateManager;
private TemplateManager templateManager=null;
public ThreddsManagerImpl() {
@Inject
public ThreddsManagerImpl(TemplateManager templateManager) {
retriever=new ThreddsRetriever();
cluster=new ThreddsCluster(LocalConfiguration.getTTL(LocalConfiguration.THREDDS_CACHE_TTL),retriever,"Thredds Cache");
cluster=new ThreddsCluster(LocalConfiguration.getTTL(LocalConfiguration.THREDDS_CACHE_TTL),retriever,"Thredds Cache");
this.templateManager=templateManager;
}
@Override

@ -7,7 +7,7 @@ import java.util.Comparator;
import java.util.concurrent.ConcurrentHashMap;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import org.gcube.spatial.data.sdi.utils.ScopeUtils;
import org.gcube.spatial.data.sdi.NetUtils;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.engine.impl.faults.InvalidServiceEndpointException;

@ -18,11 +18,11 @@ public class GeoNetworkCluster extends AbstractCluster<GeoNetworkDescriptor,GeoN
private static final Comparator<GeoNetworkController> comparator=new Comparator<GeoNetworkController>() {
@Override
public int compare(GeoNetworkController o1, GeoNetworkController o2) {
return o1.getDescriptor().getPriority().compareTo(o2.getDescriptor().getPriority());
return o1.getPriority().compareTo(o2.getPriority());
}
};
public GeoNetworkCluster(long objectsTTL, ISModule retriever, String cacheName) {
super(objectsTTL, retriever, cacheName);
// TODO Auto-generated constructor stub
@ -32,20 +32,21 @@ public class GeoNetworkCluster extends AbstractCluster<GeoNetworkDescriptor,GeoN
protected Comparator<GeoNetworkController> getComparator() {
return comparator;
}
@Override
protected GeoNetworkController translate(ServiceEndpoint e) throws InvalidServiceEndpointException {
return new GeoNetworkController(e);
}
@Override
protected ArrayList<GeoNetworkController> getLiveControllerCollection() throws ConfigurationNotFoundException {
ArrayList<GeoNetworkController> toReturn= super.getLiveControllerCollection();
try{
toReturn.get(0).configure();
}catch(ServiceInteractionException e) {
log.warn("Unexpected exception while configuring GeoNetwork SE [ID : "+toReturn.get(0).getServiceEndpoint().id()+"]",e);
}
for(GeoNetworkController controller:toReturn)
try{
controller.configure();
}catch(ServiceInteractionException e) {
log.warn("Unexpected exception while configuring GeoNetwork SE [ID : "+controller.getServiceEndpoint().id()+"]",e);
}
return toReturn;
}
}

@ -9,49 +9,76 @@ import java.util.Set;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
import org.gcube.spatial.data.geonetwork.model.Group;
import org.gcube.spatial.data.geonetwork.model.User;
import org.gcube.spatial.data.geonetwork.utils.UserUtils;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.ScopeUtils;
import org.gcube.spatial.data.sdi.engine.impl.faults.InvalidServiceEndpointException;
import org.gcube.spatial.data.sdi.engine.impl.faults.OutdatedServiceEndpointException;
import org.gcube.spatial.data.sdi.engine.impl.faults.ServiceInteractionException;
import org.gcube.spatial.data.sdi.engine.impl.gn.extension.GeoNetworkClient;
import org.gcube.spatial.data.sdi.engine.impl.gn.extension.GeoNetworkUtils;
import org.gcube.spatial.data.sdi.engine.impl.gn.utils.UserUtils;
import org.gcube.spatial.data.sdi.engine.impl.is.ISUtils;
import org.gcube.spatial.data.sdi.model.credentials.AccessType;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
import org.gcube.spatial.data.sdi.model.gn.Group;
import org.gcube.spatial.data.sdi.model.gn.User;
import org.gcube.spatial.data.sdi.model.service.GeoNetworkDescriptor;
import org.gcube.spatial.data.sdi.utils.ScopeUtils;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GeoNetworkController extends GeoServiceController<GeoNetworkDescriptor>{
String scopeUserPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_SCOPE_USER_PREFIX);
String scopePasswordPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_SCOPE_PASSWORD_PREFIX);
String ckanUserPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_CKAN_USER_PREFIX);
String ckanPasswordPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_CKAN_PASSWORD_PREFIX);
String managerUserPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_MANAGER_USER_PREFIX);
String managerPasswordPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_MANAGER_PASSWORD_PREFIX);
String assignedScopePrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_ASSIGNED_SCOPE_PREFIX);
String defaultGroupPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_DEFAULT_GROUP_PREFIX);
String sharedGroupPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_SHARED_GROUP_PREFIX);
String confidentialGroupPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_CONFIDENTIAL_GROUP_PREFIX);
String contextGroupPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_CONTEXT_GROUP_PREFIX);
String suffixesProperty=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_SUFFIXES);
String priorityProperty=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_PRIORITY);
private String suffixes=null;
private static String scopeUserPrefix=null;
private static String scopePasswordPrefix=null;
private static String ckanUserPrefix=null;
private static String ckanPasswordPrefix=null;
private static String managerUserPrefix=null;
private static String managerPasswordPrefix=null;
private static String assignedScopePrefix=null;
private static String defaultGroupPrefix=null;
private static String sharedGroupPrefix=null;
private static String confidentialGroupPrefix=null;
private static String contextGroupPrefix=null;
private static String suffixesProperty=null;
private static String priorityProperty=null;
static{
scopeUserPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_SCOPE_USER_PREFIX);
scopePasswordPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_SCOPE_PASSWORD_PREFIX);
ckanUserPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_CKAN_USER_PREFIX);
ckanPasswordPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_CKAN_PASSWORD_PREFIX);
managerUserPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_MANAGER_USER_PREFIX);
managerPasswordPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_MANAGER_PASSWORD_PREFIX);
assignedScopePrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_ASSIGNED_SCOPE_PREFIX);
defaultGroupPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_DEFAULT_GROUP_PREFIX);
sharedGroupPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_SHARED_GROUP_PREFIX);
confidentialGroupPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_CONFIDENTIAL_GROUP_PREFIX);
contextGroupPrefix=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_CONTEXT_GROUP_PREFIX);
suffixesProperty=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_SUFFIXES);
priorityProperty=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_SE_PRIORITY);
}
private String suffixes;
private Integer priority;
public Integer getPriority() {
return priority;
}
public GeoNetworkController(ServiceEndpoint serviceEndpoint) throws InvalidServiceEndpointException {
super(serviceEndpoint);
super(serviceEndpoint);
}
@Override
protected void setServiceEndpoint(ServiceEndpoint toSet) {
super.setServiceEndpoint(toSet);
suffixes=getSEProperty(suffixesProperty, true);
priority=Integer.parseInt(getSEProperty(priorityProperty, true));
}
@ -63,44 +90,45 @@ public class GeoNetworkController extends GeoServiceController<GeoNetworkDescrip
descriptor.setBaseEndpoint(baseURL);
descriptor.setVersion(version);
String currentScopeName=ScopeUtils.getCurrentScopeName();
String suffix=getSuffixByScope(currentScopeName);
ArrayList<Credentials> availableCredentials=new ArrayList<Credentials>();
availableCredentials.add(adminAccount);
Credentials context=new Credentials(getSEProperty(scopeUserPrefix+suffix, true),
getSEProperty(scopePasswordPrefix+suffix, true), AccessType.CONTEXT_USER);
availableCredentials.add(context);
Credentials ckan=new Credentials(getSEProperty(ckanUserPrefix+suffix, true),
getSEProperty(ckanPasswordPrefix+suffix, true), AccessType.CKAN);
availableCredentials.add(ckan);
String managerUser=getSEProperty(managerUserPrefix+suffix, false);
if(managerUser!=null) {
Credentials manager=new Credentials(managerUser,getSEProperty(managerPasswordPrefix+suffix, true),AccessType.CONTEXT_MANAGER);
availableCredentials.add(manager);
}
descriptor.setAccessibleCredentials(availableCredentials);
descriptor.setPriority(priority);
descriptor.setContextGroup(getSEProperty(contextGroupPrefix+suffix, true));
descriptor.setSharedGroup(getSEProperty(sharedGroupPrefix+suffix, true));
String confidentialGroup=getSEProperty(confidentialGroupPrefix+suffix, false);
if(confidentialGroup!=null)
descriptor.setConfidentialGroup(confidentialGroup);
descriptor.setDefaultGroup(getSEProperty(defaultGroupPrefix+suffix, true));
descriptor.setPublicGroup(LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_GROUP_ALL));
return descriptor;
}
@Override
protected AccessPoint getTheRightAccessPoint(ServiceEndpoint endpoint) {
for(AccessPoint declaredPoint:endpoint.profile().accessPoints().asCollection()) {
@ -110,22 +138,25 @@ public class GeoNetworkController extends GeoServiceController<GeoNetworkDescrip
}
return null;
}
@Override
protected void initServiceEndpoint() throws OutdatedServiceEndpointException, ServiceInteractionException {
String scopeName=ScopeUtils.getCurrentScopeName();
String suffix=getSuffixByScope(scopeName);
if(suffix==null) {
try {
if(getSuffixByScope(scopeName)==null) throw new InvalidServiceEndpointException("Scope not present in resource");
}catch(InvalidServiceEndpointException e) {
insertScopeInfo(ScopeUtils.getCurrentScope());
}
}
}
private void insertScopeInfo(String scope) throws OutdatedServiceEndpointException, ServiceInteractionException {
String scopeName=ScopeUtils.getScopeName(scope);
log.info("Creating scope {} configuration for GeoNetwork at {} ",scopeName,baseURL);
//Get GN Client
log.debug("Instantiating client as admin..");
@ -133,109 +164,132 @@ public class GeoNetworkController extends GeoServiceController<GeoNetworkDescrip
log.debug("Getting Users and groups from instance..");
Set<Group> existingGroups=gnClient.getGroups();
Set<User> existingUsers=gnClient.getUsers();
// Get parent scopes users and groups
// configure parent [mng,ctx] to access [sh]
// configure siblings [mng,ctx] to access [sh]
// configure users [mng,ctx] to access siblings [sh] and parent [ctx,sh]
ArrayList<User> sharedGroupExternalUsers=new ArrayList<User>();
ArrayList<Integer> externalGroupsToAccess=new ArrayList<Integer>();
// gathering users and groups from siblings
log.debug("Getting Siblings information from SE..");
for(String siblingScope:ISUtils.getSiblingsScopesInResource(serviceEndpoint, scope)) {
for(String username:getUserNamesByScope(siblingScope, true, true, false))
sharedGroupExternalUsers.add(UserUtils.getByName(existingUsers, username));
externalGroupsToAccess.addAll(getGroupIDSByScope(siblingScope, true, false, false));
}
for(String siblingScope:ISUtils.getSiblingsScopesInResource(serviceEndpoint, scope))
try {
getSuffixByScope(ScopeUtils.getScopeName(siblingScope));
for(String username:getUserNamesByScope(siblingScope, true, true, false))
sharedGroupExternalUsers.add(UserUtils.getByName(existingUsers, username));
externalGroupsToAccess.addAll(getGroupIDSByScope(siblingScope, true, false, false));
}catch(InvalidServiceEndpointException e) {
log.debug("Sibling scope {} not found in resource. Skipping.",siblingScope);
}
log.debug("Getting Parents information from SE..");
// gathering users and groups from parents
for(String parentScope:ScopeUtils.getParentScopes(scope)) {
for(String username:getUserNamesByScope(parentScope, true, true, false))
sharedGroupExternalUsers.add(UserUtils.getByName(existingUsers, username));
externalGroupsToAccess.addAll(getGroupIDSByScope(parentScope, true, true, false));
}
for(String parentScope:ScopeUtils.getParentScopes(scope))
try {
getSuffixByScope(ScopeUtils.getScopeName(parentScope));
for(String username:getUserNamesByScope(parentScope, true, true, false))
sharedGroupExternalUsers.add(UserUtils.getByName(existingUsers, username));
externalGroupsToAccess.addAll(getGroupIDSByScope(parentScope, true, true, false));
}catch(InvalidServiceEndpointException e) {
log.debug("Parent scope {} not found in resource. Skipping it. ",parentScope);
}
// Creating groups
log.debug("Creating groups..");
String contactMail=LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_MAIL);
int passwordLength=Integer.parseInt(LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_PASSWORD_LENGTH, "10"));
// create user & groups [sh,conf,ctx]
Group shared=GeoNetworkUtils.generateGroup(existingGroups, "Shared_"+scopeName, "Shared metadata group for "+scopeName, contactMail);
shared=gnClient.createGroup(shared);
existingGroups.add(shared);
Group context=GeoNetworkUtils.generateGroup(existingGroups, "Context_"+scopeName, "Context metadata group for "+scopeName, contactMail);
context=gnClient.createGroup(context);
existingGroups.add(context);
Group confidential=GeoNetworkUtils.generateGroup(existingGroups, "Confidential_"+scopeName, "Confidential metadata group for "+scopeName, contactMail);
confidential=gnClient.createGroup(context);
confidential=gnClient.createGroup(confidential);
existingGroups.add(confidential);
// Giving access to shared group
log.debug("Giving access to shared group from external scopes..");
for(User toUpdate:sharedGroupExternalUsers)
gnClient.editUser(toUpdate, Collections.singleton(shared.getId()));
log.debug("Creating users..");
// CKAN -> sh,ctx
User ckan=GeoNetworkUtils.generateUser(existingUsers, passwordLength, "CKAN_"+scopeName);
ckan=gnClient.createUsers(ckan, Arrays.asList(shared.getId(),context.getId()));
User ckan=GeoNetworkUtils.generateUser(existingUsers, passwordLength, "CKAN_"+scopeName);
ckan.setId(gnClient.createUsers(ckan, Arrays.asList(shared.getId(),context.getId())).getId());
existingUsers.add(ckan);
// CTX-USR -> sh,ctx,siblings [sh], parents [sh,ctx]
User ctx=GeoNetworkUtils.generateUser(existingUsers, passwordLength, "Ctx_"+scopeName);
ArrayList<Integer> ctxUserAccessibleGroups=new ArrayList<>();
ctxUserAccessibleGroups.addAll(externalGroupsToAccess);
ctxUserAccessibleGroups.add(shared.getId());
ctxUserAccessibleGroups.add(context.getId());
ctx=gnClient.createUsers(ctx, ctxUserAccessibleGroups);
ctx.setId(gnClient.createUsers(ctx, ctxUserAccessibleGroups).getId());
existingUsers.add(ctx);
// CTX-MANAGER -> sh,ctx,conf siblings [sh], parents [sh,ctx]
User manager=GeoNetworkUtils.generateUser(existingUsers, passwordLength, "Mng_"+scopeName);
ctxUserAccessibleGroups.add(confidential.getId());
manager.setId(gnClient.createUsers(manager, ctxUserAccessibleGroups).getId());
existingUsers.add(manager);
// Setting information in Service Endpoint
log.debug("Inserting configuration in Service Endpoint");
String generatedSuffix=generateSuffix(suffixes);
ArrayList<Property> toUpdateProperties=new ArrayList<>();
toUpdateProperties.add( new Property().nameAndValue(assignedScopePrefix+generatedSuffix, scopeName));
toUpdateProperties.add( new Property().nameAndValue(scopeUserPrefix+generatedSuffix, ctx.getUsername()));
toUpdateProperties.add( new Property().nameAndValue(scopePasswordPrefix+generatedSuffix, ctx.getPassword()).encrypted(true));
toUpdateProperties.add( new Property().nameAndValue(scopePasswordPrefix+generatedSuffix, ISUtils.encryptString(ctx.getPassword())).encrypted(true));
toUpdateProperties.add( new Property().nameAndValue(ckanUserPrefix+generatedSuffix, ckan.getUsername()));
toUpdateProperties.add( new Property().nameAndValue(ckanPasswordPrefix+generatedSuffix, ckan.getPassword()).encrypted(true));
toUpdateProperties.add( new Property().nameAndValue(ckanPasswordPrefix+generatedSuffix, ISUtils.encryptString(ckan.getPassword())).encrypted(true));
toUpdateProperties.add( new Property().nameAndValue(managerUserPrefix+generatedSuffix, manager.getUsername()));
toUpdateProperties.add( new Property().nameAndValue(managerPasswordPrefix+generatedSuffix, manager.getPassword()).encrypted(true));
toUpdateProperties.add( new Property().nameAndValue(managerPasswordPrefix+generatedSuffix, ISUtils.encryptString(manager.getPassword())).encrypted(true));
toUpdateProperties.add( new Property().nameAndValue(sharedGroupPrefix+generatedSuffix, shared.getId()+""));
toUpdateProperties.add( new Property().nameAndValue(defaultGroupPrefix+generatedSuffix, shared.getId()+""));
toUpdateProperties.add( new Property().nameAndValue(confidentialGroupPrefix+generatedSuffix, confidential.getId()+""));
toUpdateProperties.add( new Property().nameAndValue(contextGroupPrefix+generatedSuffix, context.getId()+""));
toUpdateProperties.add(new Property().nameAndValue(suffixesProperty, suffixes+","+generatedSuffix));
String suffixesList=(suffixes!=null&&!suffixes.trim().isEmpty()&&suffixes!=",")?suffixes+","+generatedSuffix:generatedSuffix;
toUpdateProperties.add(new Property().nameAndValue(suffixesProperty, suffixesList));
accessPoint.properties().addAll(toUpdateProperties);
throw new OutdatedServiceEndpointException("Created scope configuration for "+scopeName);
}
private String getSuffixByScope(String scopeName) {
log.debug("looking for scope {} suffix. Available suffixes are : {} ",scopeName,suffixes);
for(String suff:suffixes.split(","))
if(getSEProperty(assignedScopePrefix+suff, true).equals(scopeName)) return suff;
if(suffixes!=null)
for(String suff:suffixes.split(","))
if(suff!=null&&!suff.isEmpty()) {
String propertyValue=getSEProperty(assignedScopePrefix+suff, false);
if(propertyValue!=null&&propertyValue.equals(scopeName)) return suff;
}
return null;
}
private static String generateSuffix(String existingSuffixes){
log.debug("Generating suffix, existing are : "+existingSuffixes);
String[] suffixArray=existingSuffixes.split(",");
String[] suffixArray=existingSuffixes==null?new String[0]:existingSuffixes.split(",");
int maxIndex=0;
for(String suff:suffixArray){
try{
@ -249,8 +303,8 @@ public class GeoNetworkController extends GeoServiceController<GeoNetworkDescrip
log.debug("Generated suffix is : "+generated);
return generated;
}
private HashSet<String> getUserNamesByScope(String scope, boolean getContext, boolean getManager, boolean getCKAN){
HashSet<String> toReturn=new HashSet<String>();
String scopeName=ScopeUtils.getScopeName(scope);
@ -265,7 +319,7 @@ public class GeoNetworkController extends GeoServiceController<GeoNetworkDescrip
}
return toReturn;
}
private HashSet<Integer> getGroupIDSByScope(String scope, boolean getShared,boolean getContext,boolean getConfidential){
HashSet<Integer> toReturn=new HashSet<Integer>();
String scopeName=ScopeUtils.getScopeName(scope);
@ -280,6 +334,6 @@ public class GeoNetworkController extends GeoServiceController<GeoNetworkDescrip
}
return toReturn;
}
}

@ -10,7 +10,7 @@ import java.util.Set;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import org.gcube.spatial.data.sdi.utils.ScopeUtils;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.impl.faults.InvalidServiceEndpointException;
import org.gcube.spatial.data.sdi.engine.impl.faults.OutdatedServiceEndpointException;

@ -52,7 +52,7 @@ public abstract class GeoServiceController<T extends GeoServiceDescriptor> {
public void onUpdateServiceEndpoint() {
setServiceEndpoint(ISUtils.updateAndWait(serviceEndpoint));
cachedDescriptor.invalidate();
if(cachedDescriptor!=null)cachedDescriptor.invalidate();
}
protected void setServiceEndpoint(ServiceEndpoint toSet) {
@ -84,7 +84,8 @@ public abstract class GeoServiceController<T extends GeoServiceDescriptor> {
protected String getSEProperty(String property, boolean mandatory) throws InvalidServiceEndpointException{
if(!propertyMap.containsKey(property))
if(mandatory)throw new InvalidServiceEndpointException("Expected property "+property+" was not found.");
if(mandatory)
throw new InvalidServiceEndpointException("Expected property "+property+" was not found. in Resource ID "+getServiceEndpoint().id());
else return null;
else {
Property prop=propertyMap.get(property);

@ -5,11 +5,11 @@ import java.util.Collection;
import java.util.List;
import java.util.Set;
import org.gcube.spatial.data.geonetwork.model.Group;
import org.gcube.spatial.data.geonetwork.model.User;
import org.gcube.spatial.data.geonetwork.model.User.Profile;
import org.gcube.spatial.data.geonetwork.utils.GroupUtils;
import org.gcube.spatial.data.geonetwork.utils.UserUtils;
import org.gcube.spatial.data.sdi.engine.impl.gn.utils.GroupUtils;
import org.gcube.spatial.data.sdi.engine.impl.gn.utils.UserUtils;
import org.gcube.spatial.data.sdi.model.gn.Group;
import org.gcube.spatial.data.sdi.model.gn.User;
import org.gcube.spatial.data.sdi.model.gn.User.Profile;
import org.jdom.Element;
import it.geosolutions.geonetwork.GNClient;

@ -5,8 +5,8 @@ import java.net.MalformedURLException;
import java.util.Collection;
import java.util.List;
import org.gcube.spatial.data.geonetwork.model.User;
import org.gcube.spatial.data.geonetwork.model.User.Profile;
import org.gcube.spatial.data.sdi.model.gn.User;
import org.gcube.spatial.data.sdi.model.gn.User.Profile;
import org.jdom.Element;
import org.jdom.output.Format;
import org.jdom.output.XMLOutputter;

@ -5,13 +5,12 @@ import java.util.Collection;
import java.util.EnumSet;
import java.util.Set;
import org.gcube.spatial.data.geonetwork.model.Group;
import org.gcube.spatial.data.geonetwork.model.User;
import org.gcube.spatial.data.geonetwork.model.faults.MissingServiceEndpointException;
import org.gcube.spatial.data.geonetwork.utils.GroupUtils;
import org.gcube.spatial.data.geonetwork.utils.UserUtils;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.impl.faults.ServiceInteractionException;
import org.gcube.spatial.data.sdi.engine.impl.gn.utils.GroupUtils;
import org.gcube.spatial.data.sdi.engine.impl.gn.utils.UserUtils;
import org.gcube.spatial.data.sdi.model.gn.Group;
import org.gcube.spatial.data.sdi.model.gn.User;
import org.gcube.spatial.data.sdi.model.service.GeoNetworkDescriptor;
import org.gcube.spatial.data.sdi.model.service.Version;
@ -30,16 +29,17 @@ public class GeoNetworkClient {
private ServerAccess access;
private GNClientExtension theClient=null;
private GeoNetworkDescriptor descriptor;
private GeoNetworkDescriptor descriptor=null;
public GeoNetworkClient(String baseURL, Version version, String password, String user, GeoNetworkDescriptor descriptor) {
this(baseURL,version,password,user);
theClient=new GNClientExtension(access);
this.descriptor=descriptor;
}
public GeoNetworkClient(String baseURL, Version version, String password, String user) {
super();
this.access=new ServerAccess(baseURL,version,password,user);
theClient=new GNClientExtension(access);
}
//************************************** GROUPS AND USERS

@ -4,11 +4,12 @@ import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.gcube.spatial.data.geonetwork.model.Group;
import org.gcube.spatial.data.geonetwork.model.User;
import org.gcube.spatial.data.geonetwork.model.User.Profile;
import org.gcube.spatial.data.geonetwork.utils.StringUtils;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.impl.faults.gn.MetadataNotFoundException;
import org.gcube.spatial.data.sdi.model.gn.Group;
import org.gcube.spatial.data.sdi.model.gn.User;
import org.gcube.spatial.data.sdi.model.gn.User.Profile;
import org.gcube.spatial.data.sdi.utils.StringUtils;
import it.geosolutions.geonetwork.exception.GNLibException;
import it.geosolutions.geonetwork.exception.GNServerException;
@ -21,7 +22,6 @@ import lombok.extern.slf4j.Slf4j;
@Slf4j
public class GeoNetworkUtils {
/**
* Adds a suffix to groupName if needed
*
@ -38,7 +38,9 @@ public class GeoNetworkUtils {
}
String toUseName=clashSafeString(groupName,existingNames);
Integer maxLength=Integer.parseInt(LocalConfiguration.getProperty(LocalConfiguration.GEONETWORK_GROUP_MAX_LENGTH, "30"));
if(toUseName.length()>maxLength)
return generateGroup(existing, toUseName.substring(0, maxLength-2), description, contactMail);
return new Group(toUseName, description, contactMail, maxId+1);
}
@ -51,7 +53,7 @@ public class GeoNetworkUtils {
return new User(0, // NB will be updated when creating it..
toUseUserName,
StringUtils.generateRandomString(passwordLength),Profile.RegisteredUser);
StringUtils.generateRandomString(passwordLength),Profile.Reviewer);
}

@ -0,0 +1,88 @@
package org.gcube.spatial.data.sdi.engine.impl.gn.utils;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathFactory;
import org.gcube.spatial.data.sdi.model.gn.Group;
import org.gcube.spatial.data.sdi.utils.StringUtils;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.json.JSONArray;
import org.json.JSONObject;
import it.geosolutions.geonetwork.exception.GNLibException;
public class GroupUtils {
private static XPath xpath = XPathFactory.newInstance().newXPath();
public static Set<Group> parseGroupXMLResponse(String xml) throws GNLibException {
try{
HashSet<Group> toReturn=new HashSet<>();
SAXBuilder builder = new SAXBuilder();
org.jdom.Element responseEl= builder.build(new StringReader(xml)).detachRootElement();
for(Object recordObj:responseEl.getChildren("record")){
org.jdom.Element record=(org.jdom.Element) recordObj;
Integer id=Integer.parseInt(record.getChild("id").getText());
String name=record.getChild("name").getText();
Element descElement=record.getChild("description");
String description=descElement!=null?descElement.getText():"";
Element mailElement=record.getChild("email");
String email=mailElement!=null?mailElement.getText():"";
toReturn.add(new Group(name,description,email,id));
}
return toReturn;
}catch(Exception e){
throw new GNLibException("Unable to parse response", e);
}
}
public static Set<Group> parseUserJSONResponse(String groupResponse) throws GNLibException {
try{
HashSet<Group> toReturn=new HashSet<>();
JSONArray array=new JSONArray(groupResponse);
for(int i=0;i<array.length();i++){
JSONObject groupObj=array.getJSONObject(i);
Integer id=groupObj.getInt("id");
String name=groupObj.getString("name");
String description=groupObj.getString("description");
String email=groupObj.getString("email");
toReturn.add(new Group(name,description,email,id));
}
return toReturn;
}catch(Exception e){
throw new GNLibException("Unable to parse group JSON response ",e);
}
}
public static Group generateRandomGroup(Set<Group> existing, Integer nameLenght){
Set<String> existingNames=new HashSet<>();
int maxId=0;
for(Group g:existing){
existingNames.add(g.getName());
if(maxId<g.getId())maxId=g.getId();
}
return new Group(StringUtils.generateNewRandom(existingNames, nameLenght), "generated group", "no.mail@nothing.org", maxId+1);
}
public static Group getByName(Set<Group> toLookInto,String toLookFor){
for(Group g:toLookInto)
if(g.getName().equals(toLookFor)) return g;
return null;
}
}

@ -0,0 +1,88 @@
package org.gcube.spatial.data.sdi.engine.impl.gn.utils;
import java.io.StringReader;
import java.util.HashSet;
import java.util.Set;
import org.gcube.spatial.data.sdi.model.gn.User;
import org.gcube.spatial.data.sdi.model.gn.User.Profile;
import org.gcube.spatial.data.sdi.utils.StringUtils;
import org.jdom.input.SAXBuilder;
import org.json.JSONArray;
import org.json.JSONObject;
import it.geosolutions.geonetwork.exception.GNLibException;
public class UserUtils {
public static Set<User> parseUserXMLResponse(String toParse) throws GNLibException{
try{
HashSet<User> toReturn=new HashSet<>();
SAXBuilder builder = new SAXBuilder();
org.jdom.Element responseEl= builder.build(new StringReader(toParse)).detachRootElement();
for(Object recordObj:responseEl.getChildren("record")){
org.jdom.Element record=(org.jdom.Element) recordObj;
Integer id=Integer.parseInt(record.getChildText("id"));
String username=record.getChildText("username");
String password=record.getChildText("password");
Profile profile=Profile.valueOf(record.getChildText("profile"));
toReturn.add(new User(id,username, password, profile));
}
return toReturn;
}catch(Exception e){
throw new GNLibException("Unable to parse users XML response", e);
}
}
public static Set<User> parseUserJSONResponse(String toParse)throws GNLibException{
try{
HashSet<User> toReturn=new HashSet<>();
JSONArray array=new JSONArray(toParse);
for(int i=0;i<array.length();i++){
JSONObject userObj=array.getJSONObject(i);
Integer id=userObj.getInt("id");
String username=userObj.getString("username");
String password=null; // password is not returned anymore by service responses
Profile profile=Profile.valueOf(userObj.getString("profile"));
toReturn.add(new User(id, username, password, profile));
}
return toReturn;
}catch(Exception e){
throw new GNLibException("Unable to parse users JSON response ",e);
}
}
public static User generateRandomUser(Set<User> existing, Integer nameLenght, Integer passwordLength){
Set<String> existingNames=new HashSet<>();
for(User g:existing)existingNames.add(g.getUsername());
return new User(0,StringUtils.generateNewRandom(existingNames, nameLenght),StringUtils.generateRandomString(passwordLength),Profile.RegisteredUser);
}
public static Set<Integer> parseGroupsByUserResponse(String toParse) throws GNLibException{
try{
HashSet<Integer> toReturn=new HashSet<>();
SAXBuilder builder = new SAXBuilder();
org.jdom.Element responseEl= builder.build(new StringReader(toParse)).detachRootElement();
for(Object recordObj:responseEl.getChildren("group")){
org.jdom.Element record=(org.jdom.Element) recordObj;
Integer id=Integer.parseInt(record.getChildText("id"));
toReturn.add(id);
}
return toReturn;
}catch(Exception e){
throw new GNLibException("Unable to Groups By User XML response", e);
}
}
public static User getByName(Set<User> toLookInto,String toLookFor){
for(User g:toLookInto)
if(g.getUsername().equals(toLookFor)) return g;
return null;
}
}

@ -9,7 +9,7 @@ import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Profile;
import org.gcube.common.resources.gcore.common.Platform;
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import org.gcube.spatial.data.sdi.utils.ScopeUtils;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.engine.impl.faults.InvalidServiceDefinitionException;
@ -232,10 +232,11 @@ public abstract class AbstractISModule implements ISModule {
protected ServiceEndpoint prepareEndpoint(ServiceDefinition definition) throws ServiceRegistrationException {
try{
ServiceEndpoint toCreate=new ServiceEndpoint();
ServiceEndpoint toCreate=new ServiceEndpoint();
Profile profile=toCreate.newProfile();
profile.category(getServiceEndpointCategory());
profile.description(definition.getDescription());
profile.name(definition.getName());
Platform platform=profile.newPlatform();
platform.name(getServiceEndpointPlatformName()).
version(definition.getMajorVersion()).

@ -1,32 +1,20 @@
package org.gcube.spatial.data.sdi.engine.impl.is;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import org.gcube.common.resources.gcore.GCoreEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
import org.gcube.common.resources.gcore.ServiceEndpoint.Profile;
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
import org.gcube.common.resources.gcore.common.Platform;
import org.gcube.spatial.data.geonetwork.GeoNetworkAdministration;
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
import org.gcube.spatial.data.geonetwork.extension.ServerAccess;
import org.gcube.spatial.data.geonetwork.model.Account;
import org.gcube.spatial.data.geonetwork.model.ScopeConfiguration;
import org.gcube.spatial.data.gis.GISInterface;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.impl.faults.ConfigurationNotFoundException;
import org.gcube.spatial.data.sdi.engine.impl.faults.InvalidServiceDefinitionException;
import org.gcube.spatial.data.sdi.engine.impl.faults.ServiceRegistrationException;
import org.gcube.spatial.data.sdi.model.credentials.AccessType;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
import org.gcube.spatial.data.sdi.model.gn.Account;
import org.gcube.spatial.data.sdi.model.health.Status;
import org.gcube.spatial.data.sdi.model.service.GeoNetworkDescriptor;
import org.gcube.spatial.data.sdi.model.service.Version;
import org.gcube.spatial.data.sdi.model.services.GeoNetworkServiceDefinition;
import org.gcube.spatial.data.sdi.model.services.ServiceDefinition;
import org.gcube.spatial.data.sdi.model.services.ServiceDefinition.Type;
@ -202,7 +190,7 @@ public class GeoNetworkRetriever extends AbstractISModule{
AccessPoint point=new AccessPoint();
point.address("http://"+definition.getHostname()+"/geonetwork");
point.credentials(definition.getAdminPassword(), "admin");
point.credentials(ISUtils.encryptString(definition.getAdminPassword()), "admin");
point.description("Main Access point");
point.name(getServiceEndpointAccessPointName());
@ -212,7 +200,7 @@ public class GeoNetworkRetriever extends AbstractISModule{
point.properties().add(priorityProperty);
// Suffixes property
Property suffixesProperty=new Property();
suffixesProperty.nameAndValue("suffixes", " ");
suffixesProperty.nameAndValue("suffixes", "");
point.properties().add(suffixesProperty);
toReturn.profile().accessPoints().add(point);

@ -4,14 +4,9 @@ import java.util.Collections;
import java.util.List;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.spatial.data.gis.is.AbstractGeoServerDescriptor;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.impl.faults.InvalidServiceDefinitionException;
import org.gcube.spatial.data.sdi.model.credentials.AccessType;
import org.gcube.spatial.data.sdi.model.credentials.Credentials;
import org.gcube.spatial.data.sdi.model.health.Status;
import org.gcube.spatial.data.sdi.model.service.GeoServerDescriptor;
import org.gcube.spatial.data.sdi.model.service.Version;
import org.gcube.spatial.data.sdi.model.services.GeoServerDefinition;
import org.gcube.spatial.data.sdi.model.services.ServiceDefinition;
import org.gcube.spatial.data.sdi.model.services.ServiceDefinition.Type;
@ -67,16 +62,16 @@ public class GeoServerClusterRetriever extends AbstractISModule{
private static final GeoServerDescriptor translate(AbstractGeoServerDescriptor desc){
Version version=new Version(2,1,2);
String baseEndpoint=desc.getUrl();
List<Credentials> accessibleCredentials=Collections.singletonList(new Credentials(desc.getUser(), desc.getPassword(), AccessType.ADMIN));
String confidentialWorkspace=null;
String contextVisibilityWorkspace=null;
String sharedWorkspace=null;
String publicWorkspace=null;
return new GeoServerDescriptor(version, baseEndpoint, accessibleCredentials, confidentialWorkspace, contextVisibilityWorkspace, sharedWorkspace, publicWorkspace);
}
// private static final GeoServerDescriptor translate(AbstractGeoServerDescriptor desc){
// Version version=new Version(2,1,2);
// String baseEndpoint=desc.getUrl();
// List<Credentials> accessibleCredentials=Collections.singletonList(new Credentials(desc.getUser(), desc.getPassword(), AccessType.ADMIN));
// String confidentialWorkspace=null;
// String contextVisibilityWorkspace=null;
// String sharedWorkspace=null;
// String publicWorkspace=null;
// return new GeoServerDescriptor(version, baseEndpoint, accessibleCredentials, confidentialWorkspace, contextVisibilityWorkspace, sharedWorkspace, publicWorkspace);
// }
@Override
protected String getGCoreEndpointServiceClass() {

@ -5,6 +5,7 @@ import static org.gcube.resources.discovery.icclient.ICFactory.clientFor;
import static org.gcube.resources.discovery.icclient.ICFactory.queryFor;
import java.io.ByteArrayOutputStream;
import java.lang.reflect.InvocationTargetException;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collection;
@ -23,7 +24,7 @@ import org.gcube.resources.discovery.client.queries.api.SimpleQuery;
import org.gcube.resources.discovery.client.queries.impl.QueryBox;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.NetUtils;
import org.gcube.spatial.data.sdi.ScopeUtils;
import org.gcube.spatial.data.sdi.utils.ScopeUtils;
import org.gcube.vremanagement.resourcemanager.client.RMBinderLibrary;
import org.gcube.vremanagement.resourcemanager.client.exceptions.InvalidScopeException;
import org.gcube.vremanagement.resourcemanager.client.exceptions.ResourcesCreationException;
@ -118,7 +119,9 @@ public class ISUtils {
}
public static String registerService(ServiceEndpoint toRegister) {
RegistryPublisher rp=RegistryPublisherFactory.create();
RegistryPublisher rp=RegistryPublisherFactory.create();
if(log.isDebugEnabled())
Resources.print(toRegister);
Resource r=rp.create(toRegister);
return r.id();
}
@ -166,10 +169,24 @@ public class ISUtils {
}
}
public static String encryptString(String toEncrypt){
try{
return StringEncrypter.getEncrypter().encrypt(toEncrypt);
}catch(Exception e) {
throw new RuntimeException("Unable to encrypt : "+toEncrypt,e);
}
}
public static ServiceEndpoint update(ServiceEndpoint toUpdate) {
RegistryPublisher rp=RegistryPublisherFactory.create();
return rp.update(toUpdate);
try{
return rp.update(toUpdate);
}catch(RuntimeException t) {
log.warn("Unable to update resource {} ",toUpdate.id());
log.debug("Updated resource is {} ",marshal(toUpdate));
throw t;
}
}
public static ServiceEndpoint updateAndWait(ServiceEndpoint toUpdate) {
@ -185,10 +202,10 @@ public class ISUtils {
try {
Thread.sleep(500);
} catch (InterruptedException e) {}
updatedString=queryById(toUpdate.id()).get(0);
updatedString=marshal(querySEById(toUpdate.id()));
equals=toUpdateString.equals(updatedString);
timeoutReached=(System.currentTimeMillis()-updateTime)>timeout;
}while(equals&&(!timeoutReached));
}while(!equals&&(!timeoutReached));
if(timeoutReached) log.warn("Timeout reached. Check if {} is updated ",toUpdate.id());
return querySEById(toUpdate.id());
}
@ -206,7 +223,10 @@ public class ISUtils {
String parent=ScopeUtils.getParentScope(scope);
if (parent!=null)
for(String resourceScope:res.scopes().asCollection())
if(ScopeUtils.getParentScope(resourceScope).equals(parent)) toReturn.add(resourceScope);
if(!resourceScope.equals(scope)) {
String resourceScopeParent=ScopeUtils.getParentScope(resourceScope);
if((resourceScopeParent!=null)&&(resourceScopeParent.equals(parent))) toReturn.add(resourceScope);
}
return toReturn;
}

@ -17,7 +17,7 @@ import org.gcube.common.resources.gcore.utils.XPathHelper;
import org.gcube.portlets.user.uriresolvermanager.UriResolverManager;
import org.gcube.portlets.user.uriresolvermanager.exception.IllegalArgumentException;
import org.gcube.portlets.user.uriresolvermanager.exception.UriResolverMapException;
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import org.gcube.spatial.data.sdi.utils.ScopeUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
@ -78,7 +78,7 @@ public class MetadataUtils {
return new String(encoded);
}
public static String getGisLinkByUUID(String uuid) throws UriResolverMapException, IllegalArgumentException{
public static String getGisLinkByUUID(String uuid) throws UriResolverMapException, IllegalArgumentException {
Map<String,String> params=new HashMap();
params.put("scope", ScopeUtils.getCurrentScope());
params.put("gis-UUID", uuid);

@ -1,10 +0,0 @@
package org.gcube.spatial.data.sdi.model.credentials;
public enum AccessType {
ADMIN,
CONTEXT_MANAGER,
CONTEXT_USER,
CKAN;
}

@ -1,35 +0,0 @@
package org.gcube.spatial.data.sdi.model.credentials;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
@Getter
@Setter
@NoArgsConstructor
@RequiredArgsConstructor
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Credentials {
@NonNull
private String username;
@NonNull
private String password;
@NonNull
private AccessType accessType;
@Override
public String toString() {
return "Credentials [username=" + username + ", password=****, accessType=" + accessType + "]";
}
}

@ -58,8 +58,10 @@ public class GeoNetwork {
return sdi.getGeoNetworkManager().getDescriptorByHostname(host);
}catch(WebApplicationException e){
log.warn("Unable to serve request",e);
throw e;
}catch(Exception e){
log.warn("Unable to serve request",e);
throw new WebApplicationException("Unable to serve request", e);
}
}
@ -76,8 +78,10 @@ public class GeoNetwork {
return roleManager.getMostAccessible(sdi.getGeoNetworkManager().getDescriptorByHostname(host).getAccessibleCredentials(), false);
// return .get(0);
}catch(WebApplicationException e){
log.warn("Unable to serve request",e);
throw e;
}catch(Exception e){
log.warn("Unable to serve request",e);
throw new WebApplicationException("Unable to serve request", e);
}
}
@ -89,8 +93,10 @@ public class GeoNetwork {
try {
return sdi.registerService(toRegister);
}catch(WebApplicationException e) {
log.warn("Unable to serve request",e);
throw e;
}catch(Exception e) {
log.warn("Unable to serve request",e);
throw new WebApplicationException("Unable to serve request",e);
}
}
@ -103,8 +109,10 @@ public class GeoNetwork {
try {
return sdi.importService(sourceToken, host, Type.GEONETWORK);
}catch(WebApplicationException e) {
log.warn("Unable to serve request",e);
throw e;
}catch(Exception e) {
log.warn("Unable to serve request",e);
throw new WebApplicationException("Unable to serve request",e);
}
}

@ -51,8 +51,10 @@ public class GeoServer {
return sdi.getGeoServerManager().getDescriptorByHostname(host);
}catch(WebApplicationException e){
log.warn("Unable to serve request",e);
throw e;
}catch(Exception e){
log.warn("Unable to serve request",e);
throw new WebApplicationException("Unable to serve request", e);
}
}
@ -68,8 +70,10 @@ public class GeoServer {
host=NetUtils.getHost(host);
return sdi.getGeoServerManager().getDescriptorByHostname(host).getAccessibleCredentials().get(0);
}catch(WebApplicationException e){
log.warn("Unable to serve request",e);
throw e;
}catch(Exception e){
log.warn("Unable to serve request",e);
throw new WebApplicationException("Unable to serve request", e);
}
}
@ -81,8 +85,10 @@ public class GeoServer {
try {
return sdi.registerService(toRegister);
}catch(WebApplicationException e) {
log.warn("Unable to serve request",e);
throw e;
}catch(Exception e) {
log.warn("Unable to serve request",e);
throw new WebApplicationException("Unable to serve request",e);
}
}
@ -95,8 +101,10 @@ public class GeoServer {
try {
return sdi.importService(sourceToken, host, Type.GEOSERVER);
}catch(WebApplicationException e) {
log.warn("Unable to serve request",e);
throw e;
}catch(Exception e) {
log.warn("Unable to serve request",e);
throw new WebApplicationException("Unable to serve request",e);
}
}

@ -137,10 +137,10 @@ public class Metadata {
toReturn.setPublishedUUID(uuid);
return toReturn;
} catch (FileNotFoundException e) {
log.debug("Unable to get uploaded with ID {}. Cause : ",uploadedId,e);
log.warn("Unable to get uploaded with ID {}. Cause : ",uploadedId,e);
throw new WebApplicationException("Invalid upload id "+uploadedId);
}catch(Throwable e ){
log.debug("Unexpected error while publishing {} . Cause : ",uploadedId,e);
log.warn("Unexpected error while publishing {} . Cause : ",uploadedId,e);
throw new WebApplicationException("Unabel to publish metadata. Cause "+e.getMessage(),Status.INTERNAL_SERVER_ERROR);
}
}

@ -12,8 +12,8 @@ import javax.ws.rs.core.MediaType;
import org.gcube.data.transfer.model.plugins.thredds.ThreddsCatalog;
import org.gcube.smartgears.annotations.ManagedBy;
import org.gcube.spatial.data.sdi.SDIServiceManager;
import org.gcube.spatial.data.sdi.ScopeUtils;
import org.gcube.spatial.data.sdi.engine.ThreddsManager;
import org.gcube.spatial.data.sdi.utils.ScopeUtils;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
@ -70,7 +70,7 @@ public class Thredds {
return threddsManager.createCatalogFromTemplate(authority,path,datasetScanId,datasetScanName,folder,catalogReference);
}catch(Throwable t) {
log.debug("Unable to create catalog",t);
log.warn("Unable to create catalog",t);
throw new WebApplicationException("Unable to serve request", t);
}
}

@ -18,6 +18,8 @@ gn.se.confidential.group.prefix=confidential
gn.se.context.group.prefix=private
gn.groups.all=1
gn.groups.max_length=32
gn.ge.serviceClass=SDI
gn.ge.serviceName=GeoNetwork

@ -1,6 +1,8 @@
package org.gcube.spatial.data.sdi.test;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Paths;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.impl.GISManagerImpl;
@ -8,19 +10,20 @@ import org.gcube.spatial.data.sdi.engine.impl.GeoNetworkManagerImpl;
import org.gcube.spatial.data.sdi.engine.impl.RoleManagerImpl;
import org.gcube.spatial.data.sdi.engine.impl.SDIManagerImpl;
import org.gcube.spatial.data.sdi.engine.impl.ThreddsManagerImpl;
import org.gcube.spatial.data.sdi.test.factories.ThreddsManagerFactory;
public class ConfigurationTest {
public static void main(String[] args) {
TokenSetter.set("/gcube/devNext");
public static void main(String[] args) throws MalformedURLException {
TokenSetter.set("/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab");
URL propertiesURL=ConfigurationTest.class.getResource("/WEB-INF/config.properties");
// TokenSetter.set("/gcube/devNext/NextNext");
LocalConfiguration.init(Paths.get("src/main/webapp/WEB-INF/config.properties").toUri().toURL());
LocalConfiguration.init(propertiesURL);
SDIManagerImpl sdi=new SDIManagerImpl(new GeoNetworkManagerImpl(new RoleManagerImpl()), new ThreddsManagerImpl(), new GISManagerImpl());
SDIManagerImpl sdi=new SDIManagerImpl(new GeoNetworkManagerImpl(new RoleManagerImpl()), new ThreddsManagerFactory().provide(), new GISManagerImpl());
System.out.println(sdi.getContextConfiguration());
System.out.println(sdi.getContextConfiguration().getGeonetworkConfiguration().get(0).getAccessibleCredentials());
}
}

@ -16,12 +16,12 @@ public class MetadataApplicationTest {
@Test
public void apply() throws IOException, TransformerException{
TokenSetter.set("/gcube/devsec/devVRE");
TokenSetter.set("/gcube/devNext/NextNext");
MetadataTemplateManagerImpl manager=new MetadataTemplateManagerImpl();
// LocalConfiguration.init(Paths.get("src/main/webapp/WEB-INF/config.properties").toUri().toURL())
// .setTemplateConfigurationObject(Paths.get("src/main/webapp/WEB-INF/metadataTemplates").toFile());
manager.init(Paths.get("src/main/webapp/WEB-INF/metadataTemplates").toFile());
manager.init(Paths.get("src/main/webapp/WEB-INF/xmlTemplates").toFile());
System.out.println(manager.getAvailableMetadataTemplates());
@ -31,6 +31,9 @@ public class MetadataApplicationTest {
builder.threddsOnlineResources("localhost", "someFileName.sc", "newCatalog");
TemplateApplicationReport report=manager.applyMetadataTemplates(Paths.get("src/test/resources/xml/toEnrichMetadata.xml").toFile(), builder.get());
System.out.println(report);
}

@ -0,0 +1,80 @@
package org.gcube.spatial.data.sdi.test;
import java.net.MalformedURLException;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.impl.GISManagerImpl;
import org.gcube.spatial.data.sdi.engine.impl.GeoNetworkManagerImpl;
import org.gcube.spatial.data.sdi.engine.impl.RoleManagerImpl;
import org.gcube.spatial.data.sdi.engine.impl.SDIManagerImpl;
import org.gcube.spatial.data.sdi.engine.impl.ThreddsManagerImpl;
import org.gcube.spatial.data.sdi.engine.impl.faults.ServiceRegistrationException;
import org.gcube.spatial.data.sdi.model.ParameterType;
import org.gcube.spatial.data.sdi.model.services.GeoNetworkServiceDefinition;
import org.gcube.spatial.data.sdi.test.factories.ThreddsManagerFactory;
import ch.qos.logback.core.util.SystemInfo;
public class RegisterServiceTest {
public static void main(String[] args) throws MalformedURLException, ServiceRegistrationException {
TokenSetter.set("/d4science.research-infrastructures.eu/gCubeApps/AlienAndInvasiveSpecies");
LocalConfiguration.init(Paths.get("src/main/webapp/WEB-INF/config.properties").toUri().toURL());
SDIManagerImpl sdi=new SDIManagerImpl(new GeoNetworkManagerImpl(new RoleManagerImpl()), new ThreddsManagerFactory().provide(), new GISManagerImpl());
System.out.println(sdi.registerService(getGNDefinition()));
}
private static GeoNetworkServiceDefinition getGNDefinition() {
GeoNetworkServiceDefinition def=new GeoNetworkServiceDefinition();
def.setAdminPassword("gCube@Gn321_sdi");
def.setDescription("GeoNetwork v3 Serving Demo VREs");
def.setHostname("geonetwork-spatialdata.d4science.org");
def.setMajorVersion((short)3);
def.setMinorVersion((short)2);
def.setReleaseVersion((short)1);
def.setName("GeoNetwork 3 Alien");
def.setPriority(10);
ParameterType[] params=new ParameterType[] {
new ParameterType("suffixes",""),
//devNext Manually configured
// new ParameterType("scope1","devNext"),
// new ParameterType("scopeUser1","devNext_context"),
// new ParameterType("scopePwd1","123456"),
// new ParameterType("ckanUser1","devNext_ckan"),
// new ParameterType("scopePwd1","987456"),
// new ParameterType("mngUser1","devNext_manager"),
// new ParameterType("mngPwd1","741852"),
// new ParameterType("default1","1"),
// new ParameterType("public1","1"),
// new ParameterType("confidential1","1"),
// new ParameterType("private1","1"),
//NextNext
// new ParameterType("scope2","NextNext"),
// new ParameterType("scopeUser2","nextNext_context"),
// new ParameterType("scopePwd2","456789"),
// new ParameterType("ckanUser2","nextNext_ckan"),
// new ParameterType("scopePwd2","123789"),
// new ParameterType("mngUser2","nextNext_manager"),
// new ParameterType("mngPwd2","963852"),
// new ParameterType("default2","1"),
// new ParameterType("public2","1"),
// new ParameterType("confidential2","1"),
// new ParameterType("private2","1"),
};
def.setProperties(new ArrayList<ParameterType>(Arrays.asList(params)));
return def;
}
}

@ -0,0 +1,85 @@
package org.gcube.spatial.data.sdi.test;
import java.net.MalformedURLException;
import java.nio.file.Paths;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.engine.ThreddsManager;
import org.gcube.spatial.data.sdi.engine.impl.ThreddsManagerImpl;
import org.gcube.spatial.data.sdi.test.factories.ThreddsManagerFactory;
public class TestCreateCatalog {
public static void main(String[] args) throws MalformedURLException {
// TokenSetter.set("/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab");
TokenSetter.set("/gcube/devNext");
LocalConfiguration.init(Paths.get("src/main/webapp/WEB-INF/config.properties").toUri().toURL());
ThreddsManager mng=new ThreddsManagerFactory().provide();
/*
* "PUT /sdi-service/gcube/service/Thredds?
* name=Thredds+Root+Catalog&
* path=public/netcdf/syncfolderfrancesco&
* folder=public/netcdf/syncfolderfrancesco HTTP/1.1" 1057 Jersey/2.13 (HttpUrlConnection 1.8.0_131)
*/
String baseName="ThreddsRootCatalog";
String authority="www.d4science.org";
String path="public/netcdf/syncfolderfrancesco";
String folder="public/netcdf/Anothersyncfolderfrancesco";
/*
*
@QueryParam(Constants.AUTHORITY_PARAMETER) @DefaultValue("www.d4science.org") String authority,
@QueryParam(Constants.BASE_NAME_PARAMETER) String baseName,
@QueryParam(Constants.PATH_PARAMETER) String path,
@QueryParam(Constants.FOLDER_PARAMETER) String folder)
try {
String scopeName=ScopeUtils.getCurrentScopeName();
log.info("Received register catalog request under scope {} ",scopeName);
if(baseName==null) {
log.debug("Base name not provided, using VRE {} ",scopeName);
baseName=scopeName+"_VRE";
}
if(folder==null) {
log.debug("Folder not provided, using base name {} ",baseName);
folder=baseName+"_folder";
}
if(path==null) {
log.debug("Path not provided, using baseName {} ",baseName);
path=baseName;
}
*/
String datasetScanName=(baseName+" Catalog").replace("_", " ");
String datasetScanId=baseName+"_in_"+folder;
String catalogReference=(baseName).replaceAll("_", " ");
try {
mng.createCatalogFromTemplate(authority,path,datasetScanId,datasetScanName,folder,catalogReference);
}catch(Exception e) {
e.printStackTrace();
}
}
}

@ -5,15 +5,21 @@ import java.nio.file.Paths;
import org.gcube.common.resources.gcore.ServiceEndpoint;
import org.gcube.spatial.data.sdi.LocalConfiguration;
import org.gcube.spatial.data.sdi.ScopeUtils;
import org.gcube.spatial.data.sdi.engine.impl.is.ISUtils;
import org.gcube.spatial.data.sdi.utils.ScopeUtils;
public class TestIS {
public static void main(String[] args) throws MalformedURLException {
TokenSetter.set("/gcube/devNext");
TokenSetter.set("/gcube/devNext/NextNext");
LocalConfiguration.init(Paths.get("src/main/webapp/WEB-INF/config.properties").toUri().toURL());
ServiceEndpoint e=ISUtils.querySEById("c8afa8c0-c781-11e2-8f67-be3b57c971ee");
ServiceEndpoint e=ISUtils.querySEById("8e1962e9-05a7-40d4-a56f-574431f4c907");
e.profile().description(e.profile().description()+"_modified");
System.out.println("Identity : "+ISUtils.marshal(e).equals(ISUtils.marshal(e)));
System.out.println(ISUtils.updateAndWait(e));
System.out.println("PARENTS");

@ -18,7 +18,7 @@ public class ThreddsManagerFactory implements Factory<ThreddsManager>{
public ThreddsManagerFactory() {
manager=new ThreddsManagerImpl(){
manager=new ThreddsManagerImpl(new MetadataTemplateManagerFactory().provide()){
@Override
protected AbstractCluster<ThreddsDescriptor, ThreddsController> getCluster() {
TokenSetter.set(TestCommon.TEST_SCOPE);

Loading…
Cancel
Save