gcube 4.1.0

git-svn-id: http://svn.research-infrastructures.eu/d4science/gcube/trunk/spatial-data/geonetwork@131175 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Fabio Sinibaldi 2016-09-07 13:23:07 +00:00
parent 97202d3eab
commit 32fd8b21c3
14 changed files with 9146 additions and 139 deletions

View File

@ -12,4 +12,7 @@
<Change>Gcube 4 SDI automatic configuration</Change>
<Change>Improved check on configuration constraints</Change>
</Changeset>
<Changeset component="geonetwork.3-1-0" date="2016-09-09">
<Change>Added Security token management</Change>
</Changeset>
</ReleaseNotes>

8745
log.txt

File diff suppressed because one or more lines are too long

110
pom.xml
View File

@ -8,7 +8,7 @@
</parent>
<groupId>org.gcube.spatial.data</groupId>
<artifactId>geonetwork</artifactId>
<version>3.0.0-SNAPSHOT</version>
<version>3.1.0-SNAPSHOT</version>
<name>geonetwork</name>
<properties>
@ -24,28 +24,51 @@
<url>http://svn.d4science.research-infrastructures.eu/gcube/trunk/spatial-data/${project.artifactId}</url>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- GCUBE -->
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.resources</groupId>
<artifactId>registry-publisher</artifactId>
</dependency>
<dependency>
<groupId>org.gcube.resources</groupId>
<artifactId>common-gcore-resources</artifactId>
</dependency>
<!-- EXTERNAL -->
<dependency>
<groupId>it.geosolutions</groupId>
<artifactId>geonetwork-manager</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>uri-resolver-manager</artifactId>
<scope>test</scope>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.geotoolkit</groupId>
@ -62,43 +85,42 @@
<artifactId>geotk-referencing</artifactId>
<version>3.20</version>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>0.11.6</version>
</dependency>
<!-- TEST -->
<dependency>
<groupId>org.gcube.resources</groupId>
<artifactId>registry-publisher</artifactId>
<version>[1.1.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.gcube.portlets.user</groupId>
<artifactId>uri-resolver-manager</artifactId>
<scope>test</scope>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.thoughtworks.xstream</groupId>
<artifactId>xstream</artifactId>
<version>1.4.4</version>
</dependency>
<dependency>
<groupId>org.gcube.resources</groupId>
<artifactId>common-gcore-resources</artifactId>
<version>[1.1.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
</dependency>
<!-- lombok -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>0.11.6</version>
</dependency>
</dependencies>
<repositories>
<repository>
@ -111,7 +133,7 @@
</repository>
</repositories>
<build>
<build>
<finalName>${artifactId}</finalName>
<plugins>
<plugin>
@ -121,7 +143,7 @@
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
@ -142,6 +164,6 @@
</plugin>
</plugins>
</build>
<description>Java library used to communicate with GeoNetwork instances.</description>
</project>

View File

@ -57,7 +57,7 @@ public class DefaultConfiguration implements Configuration {
geonetworkCategory=props.getProperty(RuntimeParameters.geonetworkCategory);
geonetworkPlatformName=props.getProperty(RuntimeParameters.geonetworkPlatformName);
endpointName=props.getProperty(RuntimeParameters.geonetworkEndpointName);
masterProperty=props.getProperty(RuntimeParameters.geonetworkMaster);
priorityProperty=props.getProperty(RuntimeParameters.priorityProperty);
}catch(Exception e){
log.error("Unable to load properties",e);
}
@ -78,8 +78,7 @@ public class DefaultConfiguration implements Configuration {
private static String geonetworkCategory;
private static String geonetworkPlatformName;
private static String endpointName;
private static String masterProperty;
private static String priorityProperty;
//***************************** INSTANCE VALUES
private String geonetworkUrl=null;
private String adminUserValue=null;
@ -127,7 +126,7 @@ public class DefaultConfiguration implements Configuration {
@Override
public ScopeConfiguration acquireConfiguration() throws MissingServiceEndpointException, MissingConfigurationException {
log.debug("Loading existing configurations");
Set<ScopeConfiguration> existing=loadExisting(getIsInformation());
Set<ScopeConfiguration> existing=getExistingConfigurations();
log.debug("Found "+existing.size()+" configurations, checking for availability");
ScopeConfiguration available=ScopeConfigurationUtils.getByScope(existing, ScopeConfiguration.NOT_ASSIGNED);
available.setAssignedScope(ScopeUtils.getCurrentScopeName());
@ -138,7 +137,7 @@ public class DefaultConfiguration implements Configuration {
@Override
public Set<ScopeConfiguration> getExistingConfigurations() throws MissingServiceEndpointException{
return loadExisting(getIsInformation());
return ScopeConfigurationUtils.fromMap(getIsAccessPoint().propertyMap(),props);
}
@Override
@ -148,7 +147,7 @@ public class DefaultConfiguration implements Configuration {
if(!parentScopes.isEmpty()) {// in order to avoid loading from IS
Set<ScopeConfiguration> existing=loadExisting(getIsInformation());
Set<ScopeConfiguration> existing=getExistingConfigurations();
for(String parent:parentScopes)
try{
toReturn.add(ScopeConfigurationUtils.getByScope(existing, parent));
@ -172,7 +171,7 @@ public class DefaultConfiguration implements Configuration {
protected void loadFromIs() throws MissingServiceEndpointException{
if(!loaded){
log.debug("IS Information not loaded, doing it now..");
AccessPoint point=getTheRightAccessPoint(getIsInformation());
AccessPoint point=getIsAccessPoint();
Map<String, Property> properties=point.propertyMap();
geonetworkUrl=point.address();
log.debug("Found master endpoint @ "+point.address()+", loading configuration map");
@ -196,45 +195,103 @@ public class DefaultConfiguration implements Configuration {
* @param toUseEndpoint
* @return
*/
protected Set<ScopeConfiguration> loadExisting(ServiceEndpoint toUseEndpoint) throws MissingServiceEndpointException{
AccessPoint point=getTheRightAccessPoint(toUseEndpoint);
return ScopeConfigurationUtils.fromMap(point.propertyMap(), props);
}
// protected Set<ScopeConfiguration> loadExisting(ServiceEndpoint toUseEndpoint) throws MissingServiceEndpointException{
// AccessPoint point=getTheRightAccessPoint(toUseEndpoint);
// return ScopeConfigurationUtils.fromMap(point.propertyMap(), props);
// }
protected ServiceEndpoint getIsInformation() throws MissingServiceEndpointException{
protected AccessPoint getIsAccessPoint() throws MissingServiceEndpointException{
log.debug("Querying IS for Geonetwork information..");
List<ServiceEndpoint> endpoints = doTheQuery(geonetworkCategory, geonetworkPlatformName);
log.debug("Found "+endpoints.size()+" ServiceEndpoints");
for (ServiceEndpoint endpoint : endpoints) {
AccessPoint point=getTheRightAccessPoint(endpoint);
if(point!=null) return endpoint;
}
AccessPoint point=getTheRightAccessPoint(endpoints.toArray(new ServiceEndpoint[endpoints.size()]));
if(point!=null) return point;
throw new MissingServiceEndpointException("No Resource found under current scope "+ScopeProvider.instance.get());
}
protected ServiceEndpoint getISServiceEndpoint() throws MissingServiceEndpointException{
log.debug("Querying IS for Geonetwork information..");
List<ServiceEndpoint> endpoints = doTheQuery(geonetworkCategory, geonetworkPlatformName);
log.debug("Found "+endpoints.size()+" ServiceEndpoints");
ServiceEndpoint se=getTheRightServiceEndpoint(endpoints.toArray(new ServiceEndpoint[endpoints.size()]));
if(se!=null) return se;
throw new MissingServiceEndpointException("No Resource found under current scope "+ScopeProvider.instance.get());
}
/**
* look for the access point compliant with configured endpointName and masterProperty = true
* look for the access point compliant with configured endpointName and maxPriority (1)
*
* @return null if not present
*/
protected static final AccessPoint getTheRightAccessPoint(ServiceEndpoint resource){
Iterator<AccessPoint> points=resource.profile().accessPoints().iterator();
while(points.hasNext()){
AccessPoint point= points.next();
System.out.println(point);
if(point.name().equals(endpointName)){
Map<String, Property> properties=point.propertyMap();
if(properties.containsKey(masterProperty)&&Boolean.parseBoolean(properties.get(masterProperty).value()))
return point;
protected static final AccessPoint getTheRightAccessPoint(ServiceEndpoint... resources){
AccessPoint toReturn=null;
int priority=1000;
for(ServiceEndpoint resource: resources){
Iterator<AccessPoint> points=resource.profile().accessPoints().iterator();
while(points.hasNext()){
AccessPoint point= points.next();
log.debug(point.toString());
if(point.name().equals(endpointName)){
Map<String, Property> properties=point.propertyMap();
if(properties.containsKey(priorityProperty)){
int currentPriority=Integer.parseInt(properties.get(priorityProperty).value());
if(toReturn==null||(currentPriority<priority)){
toReturn=point;
priority=currentPriority;
}
}
}
}
}
return null;
return toReturn;
}
/**
* look for the access point compliant with configured endpointName and maxPriority (1)
*
* @return null if not present
*/
protected static final ServiceEndpoint getTheRightServiceEndpoint(ServiceEndpoint... resources){
ServiceEndpoint toReturn=null;
int priority=1000;
for(ServiceEndpoint resource: resources){
Iterator<AccessPoint> points=resource.profile().accessPoints().iterator();
while(points.hasNext()){
AccessPoint point= points.next();
log.debug(point.toString());
if(point.name().equals(endpointName)){
Map<String, Property> properties=point.propertyMap();
if(properties.containsKey(priorityProperty)){
int currentPriority=Integer.parseInt(properties.get(priorityProperty).value());
if(toReturn==null||(currentPriority<priority)){
toReturn=resource;
priority=currentPriority;
}
}
}
}
}
return toReturn;
}
protected List<ServiceEndpoint> doTheQuery(String geonetworkCategory, String geonetworkPlatformName){
SimpleQuery query = queryFor(ServiceEndpoint.class);
@ -260,7 +317,7 @@ public class DefaultConfiguration implements Configuration {
*/
protected void storeAndReload(ScopeConfiguration toStore) throws MissingServiceEndpointException {
log.debug("Going to store : "+toStore);
ServiceEndpoint toUpdateResource=getIsInformation();
ServiceEndpoint toUpdateResource=getISServiceEndpoint();
Map<String,Property> accessPointConfiguration=getTheRightAccessPoint(toUpdateResource).propertyMap();
String toUseSuffix=null;
try{
@ -295,7 +352,7 @@ public class DefaultConfiguration implements Configuration {
Thread.sleep(wait);
} catch (InterruptedException e) {}
log.debug("loading IS information");
ServiceEndpoint toUpdateResource=getIsInformation();
ServiceEndpoint toUpdateResource=getISServiceEndpoint();
Map<String,Property> accessPointConfiguration=getTheRightAccessPoint(toUpdateResource).propertyMap();
// check if all values are updated

View File

@ -1,5 +1,6 @@
package org.gcube.spatial.data.geonetwork.configuration;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
@ -24,7 +25,7 @@ public class ScopeConfigurationUtils {
static Set<ScopeConfiguration> fromMap(Map<String,Property> theMap, Properties parameters) throws EncryptionException{
HashSet<ScopeConfiguration> toReturn=new HashSet<>();
String[] suffixes=getExistingSuffixes(theMap,parameters).split(",");
System.out.println("Suffixes to use are "+suffixes);
log.debug("Suffixes to use are "+Arrays.toString(suffixes));
for(String suff:suffixes)
try{
toReturn.add(getConfigurationBySuffix(theMap, suff,parameters));

View File

@ -18,4 +18,11 @@ public class Account {
private String user;
private String password;
private Type type;
@Override
public String toString() {
return "Account [user=" + user + ", password=" + "***" + ", type="
+ type + "]";
}
}

View File

@ -1,6 +1,7 @@
package org.gcube.spatial.data.geonetwork.model;
import java.util.Map;
import java.util.Set;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
@ -8,6 +9,8 @@ import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
@Getter
@Setter
@EqualsAndHashCode
@ -15,6 +18,7 @@ import lombok.ToString;
@ToString
public class ScopeConfiguration {
public static String NOT_ASSIGNED="N/A";
private String assignedScope;

View File

@ -10,7 +10,7 @@ public class RuntimeParameters {
public static final String geonetworkCategory="geonetworkCategory";
public static final String geonetworkPlatformName="geonetworkPlatformName";
public static final String geonetworkEndpointName="geonetworkEndpointName";
public static final String geonetworkMaster="geonetworkMaster";
public static final String priorityProperty="priorityProperty";
public static final String availableGroupSuffixList="availableGroupSuffixList";
public static final String assignedScopePrefix="assignedScopePrefix";

View File

@ -1,21 +1,37 @@
package org.gcube.spatial.data.geonetwork.utils;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.util.HashSet;
import java.util.Set;
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(){
return ScopeProvider.instance.get();
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();
}
}
public static String getCurrentScopeName(){
String current=getCurrentScope();
return current.substring(current.lastIndexOf('/')+1);
}
public static Set<String> getParentScopes(){
String currentScope=getCurrentScope();
String[] splitted=currentScope.substring(1).split("/");

View File

@ -2,7 +2,7 @@
geonetworkCategory=Gis
geonetworkPlatformName=geonetwork
geonetworkEndpointName=geonetwork
geonetworkMaster=master
priorityProperty=priority
availableGroupSuffixList=suffixes
# Per scope parameters
@ -30,4 +30,5 @@ GNUniqueNameLength=7
GNPasswordLength=10
#IS wait 10*60*1000
isMaxWaitTimeMillis=600000
isMaxWaitTimeMillis=600000

View File

@ -1,12 +1,10 @@
package org.gcube.spatial.data.geonetwork.test;
import it.geosolutions.geonetwork.util.GNSearchRequest;
import it.geosolutions.geonetwork.util.GNSearchResponse;
import it.geosolutions.geonetwork.util.GNSearchResponse.GNMetadata;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
@ -19,10 +17,14 @@ import org.gcube.spatial.data.geonetwork.model.Account.Type;
import org.gcube.spatial.data.geonetwork.model.ScopeConfiguration;
import org.gcube.spatial.data.geonetwork.utils.UserUtils;
import it.geosolutions.geonetwork.util.GNSearchRequest;
import it.geosolutions.geonetwork.util.GNSearchResponse;
import it.geosolutions.geonetwork.util.GNSearchResponse.GNMetadata;
public class AdministrationTests {
private static final String defaultScope="/gcube";
private static final String defaultScope="/d4science.research-infrastructures.eu";
// //******************** CONFIGURATION
// // per scope
@ -46,18 +48,19 @@ public class AdministrationTests {
* @throws Exception
*/
public static void main(String[] args) throws Exception {
ScopeProvider.instance.set(defaultScope);
GeoNetworkAdministration client=GeoNetwork.get();
ScopeConfiguration config=client.getConfiguration().getScopeConfiguration();
System.out.println("Configuration is : "+config);
client.login(LoginLevel.ADMIN);
// getting INFRA group and user
Integer groupId=config.getPrivateGroup();
Integer userId=UserUtils.getByName(client.getUsers(), config.getAccounts().get(Type.SCOPE).getUser()).getId();
// ScopeProvider.instance.set(defaultScope);
// GeoNetworkAdministration client=GeoNetwork.get();
// ScopeConfiguration config=client.getConfiguration().getScopeConfiguration();
// System.out.println("Configuration is : "+config);
// client.login(LoginLevel.ADMIN);
//
// // getting INFRA group and user
// Integer groupId=config.getPrivateGroup();
// Integer userId=UserUtils.getByName(client.getUsers(), config.getAccounts().get(Type.SCOPE).getUser()).getId();
//
// client.transferOwnership(null, groupId, userId);
// client.transferOwnership(1, 0, userId, groupId);
// System.out.println("DONE");
// client.transferOwnership(36, 46, 30, 40);
// System.out.println(client.getMetadataOwners());
@ -66,40 +69,125 @@ public class AdministrationTests {
// req.addParam(GNSearchRequest.Param.any,"");
// System.out.println(client.query(req));
//
//Set privileges from query
// String[] scopes=new String[]{
// "/d4science.research-infrastructures.eu",
// "/d4science.research-infrastructures.eu/gCubeApps",
// "/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab"
// };
// final GNSearchRequest req=new GNSearchRequest();
// req.addParam(GNSearchRequest.Param.any,"");
//
// //look for any accessible id through scopes
//
// HashSet<Long> accessibleIds=new HashSet<>();
// System.out.println("Loading accessible Ids..");
// for(String scope:scopes){
// ScopeProvider.instance.set(scope);
// GeoNetworkAdministration adminClient=GeoNetwork.get();
// adminClient.login(LoginLevel.SCOPE);
// GNSearchResponse resp=adminClient.query(req);
// Iterator<GNMetadata> it=resp.iterator();
// while(it.hasNext())accessibleIds.add(it.next().getId());
// System.out.println("Found "+resp.getCount()+" under "+scope);
// }
// System.out.println("Globally accessible count : "+accessibleIds.size());
//
// ScopeProvider.instance.set(scopes[0]);
// System.out.println("Loading ADMIN IDs");
// HashSet<Long> adminIds=new HashSet<>();
// GeoNetworkAdministration adminClient=GeoNetwork.get();
//
//
// adminClient.login(LoginLevel.ADMIN);
// Iterator<GNMetadata> it=adminClient.query(req).iterator();
// while(it.hasNext())adminIds.add(it.next().getId());
// System.out.println("Found "+adminIds.size());
// adminIds.removeAll(accessibleIds);
// System.out.println("Resulting hidden count : "+adminIds.size());
//
//// // getting INFRA group and user
// ScopeConfiguration config=adminClient.getConfiguration().getScopeConfiguration();
// Integer groupId=config.getPrivateGroup();
// Integer userId=UserUtils.getByName(adminClient.getUsers(), config.getAccounts().get(Type.SCOPE).getUser()).getId();
//
// System.out.println("Assignin ownership to root");
// HashSet<Long> errors=new HashSet<>();
// List<Long> ids=new ArrayList<Long>();
// for(Long toMoveId:adminIds){
// ids.add(toMoveId);
// if(ids.size()==4){
// try{
// adminClient.assignOwnership(ids,userId, groupId);
// System.out.print("*");
//
// }catch(Exception e){
// System.err.print("*");
// errors.addAll(ids);
// }finally{
// ids.clear();
// }
// }
// }
//
// System.out.println();
// System.out.println("Errros : "+errors.size());
//Set privileges on single id
ScopeProvider.instance.set(defaultScope);
GeoNetworkAdministration client=GeoNetwork.get();
ScopeConfiguration config=client.getConfiguration().getScopeConfiguration();
System.out.println("Configuration is : "+config);
client.login(LoginLevel.ADMIN);
//
// // getting INFRA group and user
Integer groupId=config.getPrivateGroup();
Integer userId=UserUtils.getByName(client.getUsers(), config.getAccounts().get(Type.SCOPE).getUser()).getId();
//
client.assignOwnership(Collections.singletonList(new Long(93778)), userId, groupId);
System.out.println("DONE");
//******************** Check different level accessibility
ScopeProvider.instance.set("/gcube");
client=GeoNetwork.get();
client.login(LoginLevel.SCOPE);
List<Long> foundIds=new ArrayList<Long>();
final GNSearchRequest req=new GNSearchRequest();
req.addParam(GNSearchRequest.Param.any,"");
GNSearchResponse resp=client.query(req);
Iterator<GNMetadata> iterator=resp.iterator();
while(iterator.hasNext()){
foundIds.add(iterator.next().getId());
}
System.out.println("Found "+foundIds.size()+", checking from second scope ");
ScopeProvider.instance.set("/gcube/devsec/devVRE");
client=GeoNetwork.get();
client.login(LoginLevel.SCOPE);
List<Long> unableToAccess=new ArrayList();
for(Long id:foundIds)
try{
client.getById(id);
}catch(Exception e){
unableToAccess.add(id);
}
printOut("noAccess.txt", unableToAccess);
System.out.println(unableToAccess.size()+" were not accessible");
// ScopeProvider.instance.set("/gcube");
// client=GeoNetwork.get();
// client.login(LoginLevel.SCOPE);
// List<Long> foundIds=new ArrayList<Long>();
//
// final GNSearchRequest req=new GNSearchRequest();
// req.addParam(GNSearchRequest.Param.any,"");
// GNSearchResponse resp=client.query(req);
//
// Iterator<GNMetadata> iterator=resp.iterator();
// while(iterator.hasNext()){
// foundIds.add(iterator.next().getId());
// }
//
// System.out.println("Found "+foundIds.size()+", checking from second scope ");
//
// ScopeProvider.instance.set("/gcube/devsec/devVRE");
// client=GeoNetwork.get();
// client.login(LoginLevel.SCOPE);
// List<Long> unableToAccess=new ArrayList();
// for(Long id:foundIds)
// try{
// client.getById(id);
// }catch(Exception e){
// unableToAccess.add(id);
// }
//
// printOut("noAccess.txt", unableToAccess);
// System.out.println(unableToAccess.size()+" were not accessible");
//
//
/// checking transfer by transfer

View File

@ -3,6 +3,7 @@ package org.gcube.spatial.data.geonetwork.test;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.spatial.data.geonetwork.GeoNetwork;
import org.gcube.spatial.data.geonetwork.GeoNetworkAdministration;
import org.gcube.spatial.data.geonetwork.GeoNetworkReader;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import org.gcube.spatial.data.geonetwork.configuration.Configuration;
import org.gcube.spatial.data.geonetwork.model.Account;
@ -12,10 +13,18 @@ import org.gcube.spatial.data.geonetwork.model.faults.MissingServiceEndpointExce
import org.gcube.spatial.data.geonetwork.utils.ScopeUtils;
import org.junit.Test;
import it.geosolutions.geonetwork.util.GNSearchRequest;
public class ScopeTests {
String[] scopes=new String[]{
"/gcube","/gcube/devsec","/gcube/devsec/devVRE"
// "/gcube",
// "/gcube/devsec",
"/gcube/devsec/devVRE"
// "/d4science.research-infrastructures.eu"
// "/d4science.research-infrastructures.eu"
};
@ -23,7 +32,7 @@ public class ScopeTests {
public void testUtils(){
for(String scope:scopes){
ScopeProvider.instance.set(scope);
TokenSetter.set(scope);
System.out.println("Setted scope "+scope);
System.out.println("Scope name : "+ScopeUtils.getCurrentScopeName());
System.out.println("Parents"+ScopeUtils.getParentScopes());
@ -33,7 +42,8 @@ public class ScopeTests {
@Test
public void testConfigs() throws MissingConfigurationException, MissingServiceEndpointException, Exception{
for(String scope:scopes){
ScopeProvider.instance.set(scope);
System.out.println("SCOPE : "+scope);
TokenSetter.set(scope);
Configuration config=GeoNetwork.get().getConfiguration();
System.out.println(config.getScopeConfiguration());
Account account=config.getScopeConfiguration().getAccounts().get(Type.CKAN);
@ -47,10 +57,28 @@ public class ScopeTests {
@Test
public void testGNUsersAndGroups() throws Exception{
ScopeProvider.instance.set(scopes[0]);
TokenSetter.set(scopes[0]);
GeoNetworkAdministration admin=GeoNetwork.get();
admin.login(LoginLevel.ADMIN);
System.out.println(admin.getGroups());
System.out.println(admin.getUsers());
}
@Test
public void getCount() throws Exception{
for(String scope:scopes){
TokenSetter.set(scope);
GeoNetworkReader reader=GeoNetwork.get();
final GNSearchRequest req=new GNSearchRequest();
req.addParam(GNSearchRequest.Param.any,"");
int publicCount=reader.query(req).getCount();
reader.login(LoginLevel.CKAN);
int totalCount=reader.query(req).getCount();
reader.login(LoginLevel.ADMIN);
int existingCount=reader.query(req).getCount();
System.out.println("SCOPE "+scope+" found "+totalCount+" (public access : "+publicCount+", local +"+(totalCount-publicCount)+", existing in instance : "+existingCount+")");
}
}
}

View File

@ -0,0 +1,30 @@
package org.gcube.spatial.data.geonetwork.test;
import java.util.Properties;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.scope.api.ScopeProvider;
public class TokenSetter {
private static Properties props=new Properties();
static{
try {
props.load(TokenSetter.class.getResourceAsStream("/tokens.properties"));
} catch (Exception e) {
throw new RuntimeException("YOU NEED TO SET TOKEN FILE IN CONFIGURATION");
}
}
public static void set(String scope){
if(!props.containsKey(scope)) throw new RuntimeException("No token found for scope : "+scope);
SecurityTokenProvider.instance.set(props.getProperty(scope));
ScopeProvider.instance.set(scope);
}
}

View File

@ -1,21 +1,26 @@
package org.gcube.spatial.data.geonetwork.test;
import org.gcube.common.scope.api.ScopeProvider;
import org.gcube.spatial.data.geonetwork.GeoNetwork;
import org.gcube.spatial.data.geonetwork.GeoNetworkReader;
import org.gcube.spatial.data.geonetwork.GeoNetworkAdministration;
import org.gcube.spatial.data.geonetwork.LoginLevel;
import org.gcube.spatial.data.geonetwork.configuration.ConfigurationManager;
import org.geotoolkit.xml.XML;
public class Wiki {
public static void main(String[] args) throws Exception{
ConfigurationManager.setConfiguration(MyConfiguration.class);
String uuid="86a7ac79-866a-49c6-b5d5-602fc2d87ddd";
GeoNetworkReader reader=GeoNetwork.get();
reader.login(LoginLevel.DEFAULT);
System.out.println(reader.getByIdAsRawString(uuid));
// ConfigurationManager.setConfiguration(MyConfiguration.class);
// String uuid="86a7ac79-866a-49c6-b5d5-602fc2d87ddd";
ScopeProvider.instance.set("/d4science.research-infrastructures.eu");
GeoNetworkAdministration reader=GeoNetwork.get();
long id=93778;
reader.login(LoginLevel.ADMIN);
System.out.println("\n\n*********************************************************************************\n\n");
System.out.println(XML.marshal(reader.getById(uuid)));
System.out.println(XML.marshal(reader.getById(id)));
}
}