git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/application-support-layer/applicationSupportLayerCore@58201 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
b0abb823b8
commit
c7ddb2aa65
|
@ -0,0 +1,71 @@
|
|||
package org.gcube.application.framework.core;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Vector;
|
||||
|
||||
import org.gcube.application.framework.core.genericresources.model.ISGenericResource;
|
||||
import org.gcube.application.framework.core.util.Pair;
|
||||
|
||||
|
||||
/**
|
||||
* @author Valia Tsagkalidou (NKUA)
|
||||
*
|
||||
*/
|
||||
public interface GenericResourceInfoI {
|
||||
|
||||
/**
|
||||
* @param name the name of the generic resource
|
||||
* @return a list containing the generic resources that have as name the given
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public List<ISGenericResource> getGenericResourceByName(String name) throws RemoteException ;
|
||||
|
||||
/**
|
||||
* @param id the id of the generic resource
|
||||
* @return a list containing the corresponding generic resources
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public List<ISGenericResource> getGenericResourceByID(String id) throws RemoteException;
|
||||
|
||||
/**
|
||||
* @return a list containing the generic resources that describe which collections are part of the active VRE as well as their hierarchical structure (the name of this generic resource is "ScenarioCollectionInfo")
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public List<ISGenericResource> getGenericResourceForScenario() throws RemoteException ;
|
||||
|
||||
/**
|
||||
* Updates a generic resource based on it's ID
|
||||
* @param genericResource the generic resource to be updated
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public void updateGenericResourceByID(ISGenericResource genericResource) throws RemoteException;
|
||||
|
||||
/**
|
||||
* Creates a new generic resource
|
||||
* @param genericResource the new generic resource
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public String createGenericResource(ISGenericResource genericResource) throws RemoteException;
|
||||
|
||||
/**
|
||||
* Reomoves an existing generic resource
|
||||
* @param genericResource the generic resource to be removed
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public void removeGenericResource(ISGenericResource genericResource) throws RemoteException;
|
||||
|
||||
/**
|
||||
* @return a list containing pairs of (name, id) of the available generic resources
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public List<Pair> getAvailableGenericResourceNames() throws RemoteException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param xsltType Presentation or Metadata. The type of the xslt
|
||||
* @return A vector which contains all the generic resources, xslts of this type. The xslts are sorted by the schema.
|
||||
*/
|
||||
public HashMap<String,Vector<String[]>> getAllXslts(String xsltType);
|
||||
}
|
137
src/main/java/org/gcube/application/framework/core/cache/CachesManager.java
vendored
Normal file
137
src/main/java/org/gcube/application/framework/core/cache/CachesManager.java
vendored
Normal file
|
@ -0,0 +1,137 @@
|
|||
package org.gcube.application.framework.core.cache;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.gcube.application.framework.core.cache.factories.GenericResourceCacheEntryFactory;
|
||||
|
||||
import net.sf.ehcache.CacheManager;
|
||||
import net.sf.ehcache.Ehcache;
|
||||
import net.sf.ehcache.constructs.blocking.CacheEntryFactory;
|
||||
import net.sf.ehcache.constructs.blocking.SelfPopulatingCache;
|
||||
|
||||
/**
|
||||
* @author Valia Tsagkalidou (KNUA)
|
||||
*
|
||||
* This class is a singleton that manages the available caches
|
||||
*
|
||||
*/
|
||||
public class CachesManager {
|
||||
protected static CachesManager cacheManager = new CachesManager();
|
||||
protected CacheManager manager;
|
||||
// protected Ehcache profileCache;
|
||||
// protected Ehcache genericResourceCache;
|
||||
// protected Ehcache searchConfigCache;
|
||||
// protected Ehcache collectionCache;
|
||||
// protected Ehcache contentCache;
|
||||
// protected Ehcache thumbnailCache;
|
||||
// protected Ehcache schemataCache;
|
||||
// protected Ehcache metadataCache;
|
||||
|
||||
protected HashMap<String, Ehcache> caches;
|
||||
|
||||
/**
|
||||
* The constructor
|
||||
*/
|
||||
protected CachesManager() {
|
||||
|
||||
manager = CacheManager.create(CachesManager.class.getResource("/etc/ehcache.xml"));
|
||||
|
||||
caches = new HashMap<String, Ehcache>();
|
||||
|
||||
// profileCache = manager.getEhcache("profiles");
|
||||
Ehcache genericResourceCache = manager.getEhcache("genericResources");
|
||||
// searchConfigCache = manager.getEhcache("searchConfiguration");
|
||||
// collectionCache = manager.getEhcache("collections");
|
||||
// contentCache = manager.getEhcache("content");
|
||||
// thumbnailCache = manager.getEhcache("thumbnail");
|
||||
// schemataCache = manager.getEhcache("schemata");
|
||||
// metadataCache = manager.getEhcache("metadata");
|
||||
|
||||
// profileCache = new SelfPopulatingCache(profileCache, new ProfileCacheEntryFactory());
|
||||
genericResourceCache = new SelfPopulatingCache(genericResourceCache, new GenericResourceCacheEntryFactory());
|
||||
caches.put("genericResourceCache", genericResourceCache);
|
||||
// searchConfigCache = new SelfPopulatingCache(searchConfigCache, new SearchConfigCacheEntryFactory());
|
||||
// collectionCache = new SelfPopulatingCache(collectionCache, new CollectionCacheEntryFactory());
|
||||
// contentCache = new SelfPopulatingCache(contentCache, new ContentInfoCacheEntryFactory());
|
||||
// thumbnailCache = new SelfPopulatingCache(thumbnailCache, new ThumbnailCacheEntryFactory());
|
||||
// schemataCache = new SelfPopulatingCache(schemataCache, new SchemaInfoCacheEntryFactory());
|
||||
// metadataCache = new SelfPopulatingCache(metadataCache, new MetadataCacheEntryFactory());
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sigleton of CachesManager
|
||||
*/
|
||||
public static CachesManager getInstance() {
|
||||
return cacheManager;
|
||||
}
|
||||
|
||||
public Ehcache getEhcache (String cacheName, CacheEntryFactory cacheFactory) {
|
||||
if (caches.get(cacheName) == null) {
|
||||
Ehcache newCache = manager.getEhcache(cacheName);
|
||||
newCache = new SelfPopulatingCache(newCache, cacheFactory);
|
||||
caches.put(cacheName, newCache);
|
||||
}
|
||||
|
||||
return caches.get(cacheName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the cache that contains the user profiles
|
||||
*/
|
||||
// public Ehcache getProfileCache() {
|
||||
// return profileCache;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return the cache that contains the generic resources
|
||||
*/
|
||||
public Ehcache getGenericResourceCache() {
|
||||
return caches.get("genericResourceCache");
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the cache that contains the search configurations
|
||||
*/
|
||||
// public Ehcache getSearchConfigCache() {
|
||||
// return searchConfigCache;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return the cache that contains the collections per VRE
|
||||
*/
|
||||
// public Ehcache getCollectionCache() {
|
||||
// return collectionCache;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return the cache that contains information about digital objects
|
||||
*/
|
||||
// public Ehcache getContentCache() {
|
||||
// return contentCache;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return the cache that contains thumbnails
|
||||
*/
|
||||
// public Ehcache getThumbnailCache() {
|
||||
// return thumbnailCache;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return the cache that contains the searchable fields for each metadata schema
|
||||
*/
|
||||
// public Ehcache getSchemataCache() {
|
||||
// return schemataCache;
|
||||
// }
|
||||
|
||||
/**
|
||||
* @return the cache that contains the metadata objects
|
||||
*/
|
||||
// public Ehcache getMetadataCache() {
|
||||
// return metadataCache;
|
||||
// }
|
||||
|
||||
}
|
|
@ -0,0 +1,77 @@
|
|||
package org.gcube.application.framework.core.cache;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.informationsystem.cache.ISCache;
|
||||
import org.gcube.informationsystem.cache.ISCacheManager;
|
||||
|
||||
|
||||
/**
|
||||
* This class manages the running harvester threads.
|
||||
*
|
||||
* @author Valia Tsagkalidou (KNUA)
|
||||
*
|
||||
*/
|
||||
|
||||
public class RIsManager {
|
||||
|
||||
|
||||
/**
|
||||
* Defines the manager's instance
|
||||
*/
|
||||
private static RIsManager instance = null;
|
||||
|
||||
/**
|
||||
* keeps the ISCache per scope
|
||||
*/
|
||||
protected HashMap<GCUBEScope, ISCache> isCaches;
|
||||
|
||||
/** Object logger. */
|
||||
protected final GCUBELog logger = new GCUBELog(this);
|
||||
|
||||
/**
|
||||
* Initializes RIsManager
|
||||
*/
|
||||
private RIsManager() {
|
||||
isCaches = new HashMap<GCUBEScope, ISCache>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the singleton
|
||||
* @return the only instance of RIsManager
|
||||
*/
|
||||
synchronized public static RIsManager getInstance() {
|
||||
if (instance == null)
|
||||
instance = new RIsManager();
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param scope the GGUBEScope for which the RIs are requested
|
||||
* @return the ISCache for this specific scope
|
||||
*/
|
||||
public synchronized ISCache getISCache(GCUBEScope scope)
|
||||
{
|
||||
ISCache isInfo = isCaches.get(scope);
|
||||
if(isInfo == null)
|
||||
{
|
||||
// If the ISCache in not already created, then it creates a new instance and adds it to the HashMap
|
||||
try {
|
||||
ISCacheManager.addManager(scope);
|
||||
isInfo = ISCacheManager.getManager(scope).getCache();
|
||||
isCaches.put(scope, isInfo);
|
||||
try {
|
||||
Thread.sleep(5000);
|
||||
} catch (InterruptedException e1) {
|
||||
logger.error("", e1);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("", e);
|
||||
}
|
||||
}
|
||||
return isInfo;
|
||||
}
|
||||
|
||||
}
|
113
src/main/java/org/gcube/application/framework/core/cache/factories/ApplicationCredentials.java
vendored
Normal file
113
src/main/java/org/gcube/application/framework/core/cache/factories/ApplicationCredentials.java
vendored
Normal file
|
@ -0,0 +1,113 @@
|
|||
package org.gcube.application.framework.core.cache.factories;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.gcube.application.framework.core.security.PortalSecurityManager;
|
||||
import org.gcube.application.framework.core.security.VOMSAdminManager;
|
||||
import org.gcube.application.framework.core.util.UserCredential;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.security.utils.VOMSAttributesReader;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.gcube.vomanagement.vomsapi.VOMSAdmin;
|
||||
import org.gcube.vomanagement.vomsapi.impl.VOMSAPIFactory;
|
||||
import org.glite.wsdl.services.org_glite_security_voms.User;
|
||||
import org.gridforum.jgss.ExtendedGSSCredential;
|
||||
|
||||
/**
|
||||
* This class is used for retrieving and updating the portal credential that is needed by the caches in order to retrieve information form gCube services
|
||||
* @author Valia Tsagkalidou (NKUA)
|
||||
*
|
||||
*/
|
||||
public class ApplicationCredentials {
|
||||
private static ApplicationCredentials applCredentials = new ApplicationCredentials();
|
||||
private HashMap<String, ExtendedGSSCredential> creds;
|
||||
protected static String userDN = "/O=Grid/OU=GlobusTest/OU=simpleCA-gauss.eng.it/OU=eng.it/CN=";
|
||||
protected static String userCA = "/O=Grid/OU=GlobusTest/OU=simpleCA-gauss.eng.it/CN=Globus Simple CA";
|
||||
|
||||
|
||||
/** Object logger. */
|
||||
protected final GCUBELog logger = new GCUBELog(this);
|
||||
|
||||
/**
|
||||
* The basic constructor
|
||||
*/
|
||||
protected ApplicationCredentials()
|
||||
{
|
||||
creds = new HashMap<String, ExtendedGSSCredential>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sigleton of ApplicationCredentials
|
||||
*/
|
||||
public static ApplicationCredentials getInstance()
|
||||
{
|
||||
return applCredentials;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param VREname the of the VRE for which you want to get the "portal" credential
|
||||
* @return the grid credential
|
||||
*/
|
||||
public ExtendedGSSCredential getCredential(String VREname)
|
||||
{
|
||||
PortalSecurityManager secMan = new PortalSecurityManager(GCUBEScope.getScope(VREname));
|
||||
if(!secMan.isSecurityEnabled())
|
||||
return null;
|
||||
ExtendedGSSCredential cred = creds.get(VREname);
|
||||
if(cred == null)
|
||||
{
|
||||
// If the credential is not available, it retrieves it from myProxy
|
||||
cred = UserCredential.getCredential("application", VREname);
|
||||
if(cred == null)
|
||||
{
|
||||
//user "application" does not exist on this VRE, so we add him and try to get credential again
|
||||
VOMSAdmin vomsA;
|
||||
VOMSAPIFactory factory;
|
||||
try {
|
||||
factory = VOMSAdminManager.getVOMSFactory();
|
||||
vomsA = factory.getVOMSAdmin();
|
||||
// String[] roles = vomsA.listRoles();
|
||||
// vomsA.createUser("application", userDN+"application", userCA, "application@gcube.org");
|
||||
// vomsA.addMember(VREname, userDN+"application", userCA);
|
||||
// vomsA.assignRole(VREname, roles[0], userDN+"application", userCA);
|
||||
// vomsA = new VOMSAdminImpl();
|
||||
String[] roles = vomsA.listRoles();
|
||||
User myUser = new User();
|
||||
myUser.setCN("application");
|
||||
myUser.setDN(userDN+"application");
|
||||
myUser.setCA(userCA);
|
||||
myUser.setMail("application@gcube.org");
|
||||
//vomsA.getExtendedPortType().createUser("application", userDN+"application", userCA, "application@gcube.org");
|
||||
vomsA.createUser(myUser);
|
||||
//vomsA.getExtendedPortType().addOnlineCAMember(VREname, userDN+"application");
|
||||
//vomsA.getExtendedPortType().assignOnlineCARole(VREname, roles[0], userDN+"application");
|
||||
vomsA.addMember(VREname, userDN + "application", userCA);
|
||||
vomsA.assignRole(VREname, roles[0], userDN + "application", userCA);
|
||||
}
|
||||
catch (Exception e) {
|
||||
vomsA = null;
|
||||
logger.error("", e);
|
||||
}
|
||||
cred = UserCredential.getCredential("application", VREname);
|
||||
}
|
||||
creds.put(VREname, cred);
|
||||
}
|
||||
else
|
||||
{
|
||||
// credential already available
|
||||
VOMSAttributesReader vomsReader = null;
|
||||
try {
|
||||
vomsReader = new VOMSAttributesReader(cred);
|
||||
//Check if it's gonna expire in the next minute, and refresh it
|
||||
if(vomsReader.getRefreshPeriod() < 60000)
|
||||
{
|
||||
cred = UserCredential.getCredential("application", VREname);
|
||||
creds.put(VREname, cred);
|
||||
}
|
||||
} catch (Exception e1) {
|
||||
logger.error("", e1);
|
||||
}
|
||||
}
|
||||
return cred;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,137 @@
|
|||
|
||||
package org.gcube.application.framework.core.cache.factories;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.application.framework.core.genericresources.model.ISGenericResource;
|
||||
import org.gcube.application.framework.core.util.CacheEntryConstants;
|
||||
import org.gcube.application.framework.core.util.QueryString;
|
||||
import org.gcube.application.framework.core.util.SessionConstants;
|
||||
import org.gcube.common.core.contexts.GCUBEContext;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.informationsystem.client.AtomicCondition;
|
||||
import org.gcube.common.core.informationsystem.client.ISClient;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericResourceQuery;
|
||||
import org.gcube.common.core.resources.GCUBEGenericResource;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.scope.GCUBEScope.Type;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
|
||||
import net.sf.ehcache.constructs.blocking.CacheEntryFactory;
|
||||
|
||||
/**
|
||||
* @author Valia Tsagkalidou
|
||||
*
|
||||
*/
|
||||
public class GenericResourceCacheEntryFactory implements CacheEntryFactory {
|
||||
|
||||
static ISClient client = null;
|
||||
|
||||
|
||||
/** Object logger. */
|
||||
protected final GCUBELog logger = new GCUBELog(this);
|
||||
|
||||
/**
|
||||
* Constructor to initialize the ISClient
|
||||
*/
|
||||
public GenericResourceCacheEntryFactory() {
|
||||
super();
|
||||
if(client == null)
|
||||
{
|
||||
try {
|
||||
client = GHNContext.getImplementation(ISClient.class);
|
||||
} catch (Exception e) {
|
||||
logger.error("",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param key a QueryString representing pairs of keys and values: needed keys are "vre" and one of "id" or "name"
|
||||
* @return a list containing the Generic Resources that correspond to the query
|
||||
*/
|
||||
public List<ISGenericResource> createEntry(Object key) throws Exception {
|
||||
QueryString querySt = (QueryString) key;
|
||||
logger.info("query: " + querySt.toString());
|
||||
GCUBEScope scope = GCUBEScope.getScope(querySt.get(CacheEntryConstants.vre));
|
||||
GCUBEGenericResourceQuery query = client.getQuery(GCUBEGenericResourceQuery.class);
|
||||
|
||||
logger.info("In generic resources cache entry factory");
|
||||
|
||||
if(querySt.containsKey(CacheEntryConstants.id))
|
||||
{ //Retrieving generic resources based on their ID
|
||||
query.addAtomicConditions(new AtomicCondition("/ID", querySt.get(CacheEntryConstants.id)));
|
||||
|
||||
}
|
||||
// else if(querySt.containsKey(CacheEntryConstants.name) && querySt.get(CacheEntryConstants.name).equals(SessionConstants.ScenarioSchemaInfo))
|
||||
// { //Retrieving the generic resource that represents the static search configuration
|
||||
// query.addAtomicConditions(new AtomicCondition("/Profile/Name", querySt.get(CacheEntryConstants.name)));
|
||||
// query.addAtomicConditions(new AtomicCondition("/Profile/Body/DL/attribute::name", querySt.get(CacheEntryConstants.vre)));
|
||||
// }
|
||||
else if(querySt.containsKey(CacheEntryConstants.name))
|
||||
{ //Retrieving generic resources based on their name
|
||||
query.addAtomicConditions(new AtomicCondition("/Profile/Name", querySt.get(CacheEntryConstants.name)));
|
||||
}
|
||||
else if(querySt.containsKey(CacheEntryConstants.vreResource))
|
||||
{
|
||||
String secondaryType = new String();
|
||||
if (scope.getType() == Type.VRE)
|
||||
secondaryType = GCUBEGenericResource.SECONDARYTYPE_VRE;
|
||||
else if (scope.getType() == Type.VO)
|
||||
secondaryType = GCUBEGenericResource.SECONDARYTYPE_VO;
|
||||
else
|
||||
secondaryType = GCUBEGenericResource.SECONDARYTYPE_INFRASTRUCTURE;
|
||||
query.addAtomicConditions(new AtomicCondition("//SecondaryType", secondaryType), new AtomicCondition("//Body/Scope", scope.toString()));
|
||||
|
||||
}
|
||||
|
||||
try{
|
||||
List<GCUBEGenericResource> result = client.execute(query, scope);
|
||||
List<ISGenericResource> res = new ArrayList<ISGenericResource>();
|
||||
if (querySt.containsKey(CacheEntryConstants.name) && querySt.get(CacheEntryConstants.name).equals(SessionConstants.ScenarioSchemaInfo)) {
|
||||
System.out.println("The number of generic Resources for ScenarioSchemaInfo returned is: " + result.size());
|
||||
List<GCUBEGenericResource> newResult = new ArrayList<GCUBEGenericResource>();
|
||||
for (GCUBEGenericResource resource : result) {
|
||||
Map<String, GCUBEScope> scopes = resource.getScopes();
|
||||
System.out.println("Number of scopes for ScenarioSchemaInfo: " + scopes.values().size());
|
||||
System.out.println(scopes.values().toString());
|
||||
if (scopes.containsValue(scope)) {
|
||||
newResult.add(resource);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (newResult.size() > 1) {
|
||||
GCUBEGenericResource voResource = null;
|
||||
for (GCUBEGenericResource resource:newResult) {
|
||||
if (resource.getScopes().size() == 1) {
|
||||
voResource = resource;
|
||||
break;
|
||||
}
|
||||
}
|
||||
newResult.clear();
|
||||
newResult.add(voResource);
|
||||
}
|
||||
System.out.println("Number of genericResources for ScenarioSchemaInfo left after the pruning" + newResult.size());
|
||||
result = newResult;
|
||||
}
|
||||
logger.debug("size of results: " + result.size());
|
||||
for(GCUBEGenericResource resource : result)
|
||||
{
|
||||
ISGenericResource genResource = new ISGenericResource(resource.getID(), resource.getName(), resource.getDescription(), resource.getBody(), resource.getSecondaryType());
|
||||
res.add(genResource);
|
||||
}
|
||||
return res;
|
||||
}catch (Exception e) {
|
||||
logger.error("",e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
package org.gcube.application.framework.core.genericresources.model;
|
||||
|
||||
|
||||
/**
|
||||
* @author Valia Tsaqgkalidou (NKUA)
|
||||
*
|
||||
*/
|
||||
public class ISGenericResource {
|
||||
|
||||
protected String id;
|
||||
protected String name;
|
||||
protected String description;
|
||||
protected String body;
|
||||
protected String secondaryType;
|
||||
|
||||
|
||||
/**
|
||||
* @return the secondary type of the generic resource
|
||||
*/
|
||||
public String getSecondaryType() {
|
||||
return secondaryType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param secondaryType the secondary type of the generic resource to be set
|
||||
*/
|
||||
public void setSecondaryType(String secondaryType) {
|
||||
this.secondaryType = secondaryType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generic Constructor
|
||||
*/
|
||||
public ISGenericResource() {
|
||||
super();
|
||||
this.id = "";
|
||||
this.name = "";
|
||||
this.description = "";
|
||||
this.body = "";
|
||||
this.secondaryType = "";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param id the generic resource ID
|
||||
* @param name the generic resource name
|
||||
* @param description the generic resource description
|
||||
* @param body the generic resource body
|
||||
* @param sType the generic resource secondary type
|
||||
*/
|
||||
public ISGenericResource(String id, String name, String description,
|
||||
String body, String sType) {
|
||||
super();
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.body = body;
|
||||
this.secondaryType = sType;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
/**
|
||||
* @param id the id to set
|
||||
*/
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
/**
|
||||
* @param description the description to set
|
||||
*/
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
/**
|
||||
* @return the body
|
||||
*/
|
||||
public String getBody() {
|
||||
return body;
|
||||
}
|
||||
/**
|
||||
* @param body the body to set
|
||||
*/
|
||||
public void setBody(String body) {
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package org.gcube.application.framework.core.security;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.security.auth.callback.Callback;
|
||||
import javax.security.auth.callback.CallbackHandler;
|
||||
import javax.security.auth.callback.NameCallback;
|
||||
import javax.security.auth.callback.PasswordCallback;
|
||||
import javax.security.auth.callback.UnsupportedCallbackException;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class JaasCallbackHandler implements CallbackHandler{
|
||||
|
||||
protected String username = null;
|
||||
protected String password = null;
|
||||
|
||||
private Log log = LogFactory.getLog(JaasCallbackHandler.class);
|
||||
|
||||
public JaasCallbackHandler(String username, String password) {
|
||||
super();
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public void handle(Callback callbacks[])
|
||||
throws IOException, UnsupportedCallbackException {
|
||||
for (int i = 0; i < callbacks.length; i++) {
|
||||
if (callbacks[i] instanceof NameCallback) {
|
||||
if (log.isDebugEnabled()) log.debug("responding to NameCallback");
|
||||
((NameCallback) callbacks[i]).setName(username);
|
||||
} else if (callbacks[i] instanceof PasswordCallback) {
|
||||
if (log.isDebugEnabled()) log.debug("responding to PasswordCallback");
|
||||
((PasswordCallback) callbacks[i]).setPassword(password != null ? password.toCharArray() : new char[0]);
|
||||
} else {
|
||||
if (log.isDebugEnabled()) log.debug("unsupported callback: " + callbacks[i].getClass());
|
||||
throw new UnsupportedCallbackException(callbacks[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,148 @@
|
|||
package org.gcube.application.framework.core.security;
|
||||
|
||||
|
||||
import javax.security.auth.login.AccountExpiredException;
|
||||
import javax.security.auth.login.CredentialExpiredException;
|
||||
import javax.security.auth.login.FailedLoginException;
|
||||
import javax.security.auth.login.LoginContext;
|
||||
import javax.security.auth.login.LoginException;
|
||||
|
||||
import org.gcube.application.framework.core.util.UserCredential;
|
||||
import org.gcube.vomanagement.vomsapi.ExtendedVOMSAdmin;
|
||||
import org.gcube.vomanagement.vomsapi.VOMSAdmin;
|
||||
import org.gridforum.jgss.ExtendedGSSCredential;
|
||||
|
||||
|
||||
|
||||
|
||||
public class LDAPAuthenticationModule {
|
||||
|
||||
public static String LDAP_HOST = "LDAP_HOST";
|
||||
public static String BASE_DN = "BASE_DN";
|
||||
|
||||
|
||||
private String contextName = "Gridsphere";
|
||||
//private String contextName = "AslLoginConf";
|
||||
|
||||
public LDAPAuthenticationModule () {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public boolean checkAuthentication(String username, String password) throws Exception {
|
||||
|
||||
System.out.println("beginning authentication for " + username);
|
||||
System.out.println("I am in ASL");
|
||||
|
||||
|
||||
LoginContext loginContext;
|
||||
|
||||
// Create the LoginContext
|
||||
try {
|
||||
loginContext = new LoginContext(contextName, new JaasCallbackHandler(username, password));
|
||||
} catch (SecurityException e) {
|
||||
e.printStackTrace();
|
||||
// Check user's credential
|
||||
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
|
||||
|
||||
System.out.println("Getting credential from VOMS");
|
||||
if (cred == null) {
|
||||
System.out.println("The credential does NOT exist");
|
||||
throw new Exception("key4", e);
|
||||
} else {
|
||||
System.out.println("The credential is OK!!!!!!!!!!!!");
|
||||
return true;
|
||||
}
|
||||
|
||||
} catch (LoginException e) {
|
||||
e.printStackTrace();
|
||||
// Check user's credential
|
||||
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
|
||||
|
||||
System.out.println("Getting credential from VOMS");
|
||||
if (cred == null) {
|
||||
System.out.println("The credential does NOT exist");
|
||||
throw new Exception("key4", e);
|
||||
} else {
|
||||
System.out.println("The credential is OK!!!!!!!!!!!!");
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Attempt login
|
||||
try {
|
||||
loginContext.login();
|
||||
} catch (FailedLoginException e) {
|
||||
// Check user's credential
|
||||
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
|
||||
|
||||
// throw new Exception("key4", e);
|
||||
if (cred == null) {
|
||||
e.printStackTrace();
|
||||
System.out.println("The credential is NULL!!!!!!!!!!!!");
|
||||
return false;
|
||||
} else {
|
||||
System.out.println("The credential is OK!!!!!!!!!!!!");
|
||||
return true;
|
||||
}
|
||||
} catch (AccountExpiredException e) {
|
||||
// Check user's credential
|
||||
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
|
||||
|
||||
// throw new Exception("key4", e);
|
||||
if (cred == null) {
|
||||
e.printStackTrace();
|
||||
System.out.println("The credential is NULL!!!!!!!!!!!!");
|
||||
return false;
|
||||
} else {
|
||||
System.out.println("The credential is OK!!!!!!!!!!!!");
|
||||
return true;
|
||||
}
|
||||
} catch (CredentialExpiredException e) {
|
||||
// Check user's credential
|
||||
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
|
||||
|
||||
// throw new Exception("key4", e);
|
||||
if (cred == null) {
|
||||
e.printStackTrace();
|
||||
System.out.println("The credential is NULL!!!!!!!!!!!!");
|
||||
return false;
|
||||
} else {
|
||||
System.out.println("The credential is OK!!!!!!!!!!!!");
|
||||
return true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Check user's credential
|
||||
ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
|
||||
|
||||
// throw new Exception("key4", e);
|
||||
if (cred == null) {
|
||||
e.printStackTrace();
|
||||
System.out.println("The credential is NULL!!!!!!!!!!!!");
|
||||
return false;
|
||||
} else {
|
||||
System.out.println("The credential is OK!!!!!!!!!!!!");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
System.out.println("ASL returning value true");
|
||||
return true;
|
||||
|
||||
// Check user's credential
|
||||
// ExtendedGSSCredential cred = UserCredential.getPlainCredential(username, password);
|
||||
//
|
||||
// System.out.println("Getting credential from VOMS");
|
||||
// if (cred == null) {
|
||||
// System.out.println("The credential does NOT exist");
|
||||
// return false;
|
||||
// } else {
|
||||
// System.out.println("The credential is OK!!!!!!!!!!!!");
|
||||
// return true;
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,89 @@
|
|||
package org.gcube.application.framework.core.security;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.StringReader;
|
||||
import java.util.List;
|
||||
|
||||
import org.gcube.application.framework.core.cache.CachesManager;
|
||||
import org.gcube.application.framework.core.genericresources.model.ISGenericResource;
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.application.framework.core.util.CacheEntryConstants;
|
||||
import org.gcube.application.framework.core.util.QueryString;
|
||||
import org.gcube.application.framework.core.util.SessionConstants;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.security.GCUBESecurityManagerImpl;
|
||||
import org.gcube.common.core.utils.logging.GCUBELog;
|
||||
import org.kxml2.io.KXmlParser;
|
||||
|
||||
/**
|
||||
* @author Valia Tsagkalidou (KNUA)
|
||||
*
|
||||
*/
|
||||
public class PortalSecurityManager extends GCUBESecurityManagerImpl {
|
||||
|
||||
/** Object logger. */
|
||||
protected final GCUBELog logger = new GCUBELog(this);
|
||||
|
||||
public PortalSecurityManager(GCUBEScope scope) {
|
||||
super();
|
||||
this.scope = scope;
|
||||
}
|
||||
|
||||
public PortalSecurityManager(ASLSession session) {
|
||||
super();
|
||||
this.scope = session.getScope();
|
||||
}
|
||||
|
||||
GCUBEScope scope;
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isSecurityEnabled() {
|
||||
QueryString query = new QueryString();
|
||||
query.put(CacheEntryConstants.vreResource, "true");
|
||||
query.put(CacheEntryConstants.vre, scope.toString());
|
||||
List<ISGenericResource> res = (List<ISGenericResource>)CachesManager.getInstance().getGenericResourceCache().get(query).getValue();
|
||||
if(res == null || res.size() == 0)
|
||||
return false;
|
||||
else
|
||||
{
|
||||
try {
|
||||
return parseBody(res.get(0).getBody());
|
||||
} catch (Exception e) {
|
||||
logger.error("",e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads from the <em>Body</em> element the resource information
|
||||
* @param body the <em>Body</em> of the generic resource
|
||||
* @throws Exception if the element is not valid or well formed
|
||||
*/
|
||||
private boolean parseBody(String body) throws Exception {
|
||||
KXmlParser parser = new KXmlParser();
|
||||
parser.setInput(new BufferedReader(new StringReader(body)));
|
||||
loop: while (true) {
|
||||
try {
|
||||
switch (parser.next()) {
|
||||
case KXmlParser.START_TAG:
|
||||
if (parser.getName().equals("SecurityEnabled"))
|
||||
{
|
||||
boolean res = Boolean.valueOf(parser.nextText()).booleanValue();
|
||||
logger.debug("Found value:" + res);
|
||||
return res;
|
||||
}
|
||||
else parser.nextText();//just skip the text
|
||||
break;
|
||||
case KXmlParser.END_DOCUMENT: break loop;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.error("",e);
|
||||
throw new Exception ("Unable to parse the ScopeResource body");
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package org.gcube.application.framework.core.security;
|
||||
|
||||
import java.rmi.Remote;
|
||||
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.common.core.contexts.GCUBERemotePortTypeContext;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gcube.common.core.scope.GCUBEScope.MalformedScopeExpressionException;
|
||||
import org.gcube.common.core.security.GCUBESecurityManager;
|
||||
import org.ietf.jgss.GSSCredential;
|
||||
|
||||
public class ServiceContextManager<PORTTYPE extends Remote> {
|
||||
|
||||
public static <PORTTYPE extends Remote> PORTTYPE applySecurity(PORTTYPE stub, ASLSession session) throws MalformedScopeExpressionException, Exception
|
||||
{
|
||||
GCUBESecurityManager secManager = new PortalSecurityManager(session);
|
||||
if(secManager.isSecurityEnabled())
|
||||
{
|
||||
secManager.useCredentials(session.getCredential());
|
||||
}
|
||||
return GCUBERemotePortTypeContext.getProxy(stub , session.getScope(), secManager);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static <PORTTYPE extends Remote> PORTTYPE applySecurity(PORTTYPE stub, GCUBEScope scope, GSSCredential cred) throws MalformedScopeExpressionException, Exception
|
||||
{
|
||||
GCUBESecurityManager secManager = new PortalSecurityManager(scope);
|
||||
if(secManager.isSecurityEnabled())
|
||||
{
|
||||
secManager.useCredentials(cred);
|
||||
}
|
||||
return GCUBERemotePortTypeContext.getProxy(stub , scope, secManager);
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,432 @@
|
|||
package org.gcube.application.framework.core.security;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.rpc.ServiceException;
|
||||
|
||||
import org.apache.axis.message.addressing.AttributedURI;
|
||||
import org.apache.axis.message.addressing.EndpointReferenceType;
|
||||
import org.apache.axis.types.URI.MalformedURIException;
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.application.framework.core.util.ASLGroupModel;
|
||||
import org.gcube.application.framework.core.util.Settings;
|
||||
import org.gcube.application.framework.core.util.UsersManagementServiceConstants;
|
||||
import org.gcube.vomanagement.usermanagement.ws.GetGroupParentId;
|
||||
import org.gcube.vomanagement.usermanagement.ws.GetRootVO;
|
||||
import org.gcube.vomanagement.usermanagement.ws.GetScope;
|
||||
import org.gcube.vomanagement.usermanagement.ws.GetUserId;
|
||||
import org.gcube.vomanagement.usermanagement.ws.GroupModel;
|
||||
import org.gcube.vomanagement.usermanagement.ws.GroupRetrievalFault;
|
||||
import org.gcube.vomanagement.usermanagement.ws.IsRootVO;
|
||||
import org.gcube.vomanagement.usermanagement.ws.IsVO;
|
||||
import org.gcube.vomanagement.usermanagement.ws.LiferaySOAPGroupManagerPortType;
|
||||
import org.gcube.vomanagement.usermanagement.ws.LiferaySOAPUserManagerPortType;
|
||||
import org.gcube.vomanagement.usermanagement.ws.ListGroups;
|
||||
import org.gcube.vomanagement.usermanagement.ws.ListGroupsByUser;
|
||||
import org.gcube.vomanagement.usermanagement.ws.ListGroupsResponse;
|
||||
import org.gcube.vomanagement.usermanagement.ws.UserManagementSystemException;
|
||||
import org.gcube.vomanagement.usermanagement.ws.service.LiferaySOAPGroupManagerServiceAddressingLocator;
|
||||
import org.gcube.vomanagement.usermanagement.ws.service.LiferaySOAPUserManagerServiceAddressingLocator;
|
||||
|
||||
public class UsersManagementUtils {
|
||||
|
||||
String umServiceLocation = new String();
|
||||
|
||||
public UsersManagementUtils() {
|
||||
StringBuffer fileData = new StringBuffer(1000);
|
||||
BufferedReader reader = null;
|
||||
try {
|
||||
reader = new BufferedReader(new FileReader(Settings.getInstance().getProperty("sharedDir")+ File.separator + "UMServiceLocation.config"));
|
||||
} catch (FileNotFoundException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
int numRead = 0;
|
||||
char[] buf = new char[1024];
|
||||
try {
|
||||
while((numRead=reader.read(buf)) != -1){
|
||||
String readData = String.valueOf(buf, 0, numRead);
|
||||
fileData.append(readData);
|
||||
buf = new char[1024];
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
reader.close();
|
||||
} catch (IOException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
umServiceLocation = fileData.toString().trim();
|
||||
}
|
||||
|
||||
public ArrayList<String> getAllScopes(ASLSession session) {
|
||||
EndpointReferenceType endpointUser = new EndpointReferenceType();
|
||||
ArrayList<String> groupsNames = new ArrayList<String>();
|
||||
try {
|
||||
//endpointUser.setAddress(new AttributedURI("http://dl10.di.uoa.gr:8181/usermanagement-ws/LiferaySOAPGroupManager"));
|
||||
endpointUser.setAddress(new AttributedURI(umServiceLocation + UsersManagementServiceConstants.LiferaySOAPGroupManager));
|
||||
} catch (MalformedURIException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
LiferaySOAPGroupManagerServiceAddressingLocator loc = new LiferaySOAPGroupManagerServiceAddressingLocator();
|
||||
try {
|
||||
LiferaySOAPGroupManagerPortType groupStub = loc.getLiferaySOAPGroupManagerPortTypePort(endpointUser);
|
||||
ListGroups groups = new ListGroups();
|
||||
|
||||
ListGroupsResponse resGroup = groupStub.listGroups(groups);
|
||||
|
||||
GroupModel[] groupList = resGroup.get_return();
|
||||
|
||||
for (GroupModel groupModel : groupList) {
|
||||
System.out.println("Group NAME " + groupModel.getGroupName());
|
||||
|
||||
GetRootVO rootVO = new GetRootVO();
|
||||
if (!groupStub.getRootVO(rootVO).get_return().getGroupId().equals(groupModel.getGroupId())) {
|
||||
String scope = null;
|
||||
|
||||
GetScope getScope = new GetScope();
|
||||
getScope.setArg0(groupModel.getGroupId());
|
||||
scope = groupStub.getScope(getScope).get_return();
|
||||
|
||||
if (scope.startsWith("/"))
|
||||
groupsNames.add(scope);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (ServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (UserManagementSystemException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return groupsNames;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public String getRootVO() {
|
||||
|
||||
EndpointReferenceType endpointUser = new EndpointReferenceType();
|
||||
ArrayList<String> groupsNames = new ArrayList<String>();
|
||||
try {
|
||||
//endpointUser.setAddress(new AttributedURI("http://dl10.di.uoa.gr:8181/usermanagement-ws/LiferaySOAPGroupManager"));
|
||||
endpointUser.setAddress(new AttributedURI(umServiceLocation + UsersManagementServiceConstants.LiferaySOAPGroupManager));
|
||||
} catch (MalformedURIException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
LiferaySOAPGroupManagerServiceAddressingLocator loc = new LiferaySOAPGroupManagerServiceAddressingLocator();
|
||||
LiferaySOAPGroupManagerPortType groupStub = null;
|
||||
try {
|
||||
groupStub = loc.getLiferaySOAPGroupManagerPortTypePort(endpointUser);
|
||||
} catch (ServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
ListGroups groups = new ListGroups();
|
||||
|
||||
try {
|
||||
ListGroupsResponse resGroup = groupStub.listGroups(groups);
|
||||
} catch (UserManagementSystemException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
GetRootVO rootVO = new GetRootVO();
|
||||
try {
|
||||
String rootVo = groupStub.getRootVO(rootVO).get_return().getGroupId();
|
||||
String rootVoName = getScope(rootVo);
|
||||
System.out.println("RootVo returning: " + rootVoName);
|
||||
return rootVoName;
|
||||
} catch (GroupRetrievalFault e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (UserManagementSystemException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String getUserId(String username) {
|
||||
EndpointReferenceType endpointUser = new EndpointReferenceType();
|
||||
String userId = null;
|
||||
try {
|
||||
//endpointUser.setAddress(new AttributedURI("http://dl10.di.uoa.gr:8181/usermanagement-ws/LiferaySOAPUserManager"));
|
||||
endpointUser.setAddress(new AttributedURI(umServiceLocation + UsersManagementServiceConstants.LiferaySOAPUserManager));
|
||||
|
||||
try {
|
||||
LiferaySOAPUserManagerPortType userManagerStub = new LiferaySOAPUserManagerServiceAddressingLocator().getLiferaySOAPUserManagerPortTypePort(endpointUser);
|
||||
GetUserId getUserId = new GetUserId();
|
||||
getUserId.setArg0(username);
|
||||
userId = userManagerStub.getUserId(getUserId).get_return();
|
||||
} catch (ServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (UserManagementSystemException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
} catch (MalformedURIException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
return userId;
|
||||
}
|
||||
|
||||
|
||||
public List<ASLGroupModel> listGroupsByUser(String userId) {
|
||||
EndpointReferenceType endpointUser = new EndpointReferenceType();
|
||||
List<ASLGroupModel> groupsByUser = new ArrayList<ASLGroupModel>();
|
||||
try {
|
||||
//endpointUser.setAddress(new AttributedURI("http://dl10.di.uoa.gr:8181/usermanagement-ws/LiferaySOAPGroupManager"));
|
||||
endpointUser.setAddress(new AttributedURI(umServiceLocation + UsersManagementServiceConstants.LiferaySOAPGroupManager));
|
||||
} catch (MalformedURIException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
LiferaySOAPGroupManagerServiceAddressingLocator loc = new LiferaySOAPGroupManagerServiceAddressingLocator();
|
||||
try {
|
||||
LiferaySOAPGroupManagerPortType groupStub = loc.getLiferaySOAPGroupManagerPortTypePort(endpointUser);
|
||||
ListGroupsByUser listGroupsByUser = new ListGroupsByUser();
|
||||
listGroupsByUser.setArg0(userId);
|
||||
GroupModel[] groups = groupStub.listGroupsByUser(listGroupsByUser).get_return();
|
||||
for (int i = 0; i < groups.length; i++) {
|
||||
ASLGroupModel grm = new ASLGroupModel();
|
||||
grm.setGroupId(new Long(groups[i].getGroupId()));
|
||||
grm.setGroupName(groups[i].getGroupName());
|
||||
grm.setDescription(groups[i].getDescription());
|
||||
groupsByUser.add(grm);
|
||||
}
|
||||
|
||||
} catch (ServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (UserManagementSystemException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return groupsByUser;
|
||||
}
|
||||
|
||||
|
||||
public List<ASLGroupModel> listGroups() {
|
||||
EndpointReferenceType endpointUser = new EndpointReferenceType();
|
||||
List<ASLGroupModel> groups = new ArrayList<ASLGroupModel>();
|
||||
try {
|
||||
//endpointUser.setAddress(new AttributedURI("http://dl10.di.uoa.gr:8181/usermanagement-ws/LiferaySOAPGroupManager"));
|
||||
endpointUser.setAddress(new AttributedURI(umServiceLocation + UsersManagementServiceConstants.LiferaySOAPGroupManager));
|
||||
} catch (MalformedURIException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
LiferaySOAPGroupManagerServiceAddressingLocator loc = new LiferaySOAPGroupManagerServiceAddressingLocator();
|
||||
try {
|
||||
LiferaySOAPGroupManagerPortType groupStub = loc.getLiferaySOAPGroupManagerPortTypePort(endpointUser);
|
||||
ListGroups listGroups = new ListGroups();
|
||||
GroupModel[] groupsArray = groupStub.listGroups(listGroups).get_return();
|
||||
for (int i = 0; i < groupsArray.length; i++) {
|
||||
ASLGroupModel gm = new ASLGroupModel();
|
||||
gm.setGroupId(new Long(groupsArray[i].getGroupId()));
|
||||
gm.setGroupName(groupsArray[i].getGroupName());
|
||||
gm.setDescription(groupsArray[i].getDescription());
|
||||
groups.add(gm);
|
||||
}
|
||||
|
||||
} catch (ServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (UserManagementSystemException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return groups;
|
||||
}
|
||||
|
||||
|
||||
public boolean isVO(String groupId) {
|
||||
EndpointReferenceType endpointUser = new EndpointReferenceType();
|
||||
List<GroupModel> groups = new ArrayList<GroupModel>();
|
||||
boolean isVO = false;
|
||||
try {
|
||||
//endpointUser.setAddress(new AttributedURI("http://dl10.di.uoa.gr:8181/usermanagement-ws/LiferaySOAPGroupManager"));
|
||||
endpointUser.setAddress(new AttributedURI(umServiceLocation + UsersManagementServiceConstants.LiferaySOAPGroupManager));
|
||||
} catch (MalformedURIException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
LiferaySOAPGroupManagerServiceAddressingLocator loc = new LiferaySOAPGroupManagerServiceAddressingLocator();
|
||||
|
||||
try {
|
||||
LiferaySOAPGroupManagerPortType groupStub = loc.getLiferaySOAPGroupManagerPortTypePort(endpointUser);
|
||||
|
||||
IsVO isVo = new IsVO();
|
||||
isVo.setArg0(groupId);
|
||||
isVO = groupStub.isVO(isVo).get_return();
|
||||
return isVO;
|
||||
} catch (ServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (GroupRetrievalFault e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (UserManagementSystemException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public boolean isRootVO(String groupId) {
|
||||
EndpointReferenceType endpointUser = new EndpointReferenceType();
|
||||
boolean isVO = false;
|
||||
try {
|
||||
//endpointUser.setAddress(new AttributedURI("http://dl10.di.uoa.gr:8181/usermanagement-ws/LiferaySOAPGroupManager"));
|
||||
endpointUser.setAddress(new AttributedURI(umServiceLocation + UsersManagementServiceConstants.LiferaySOAPGroupManager));
|
||||
} catch (MalformedURIException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
LiferaySOAPGroupManagerServiceAddressingLocator loc = new LiferaySOAPGroupManagerServiceAddressingLocator();
|
||||
|
||||
try {
|
||||
LiferaySOAPGroupManagerPortType groupStub = loc.getLiferaySOAPGroupManagerPortTypePort(endpointUser);
|
||||
|
||||
IsRootVO isRootVo = new IsRootVO();
|
||||
isRootVo.setArg0(groupId);
|
||||
isVO = groupStub.isRootVO(isRootVo).get_return();
|
||||
return isVO;
|
||||
} catch (ServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (GroupRetrievalFault e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (UserManagementSystemException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public String getScope(String groupId) {
|
||||
EndpointReferenceType endpointUser = new EndpointReferenceType();
|
||||
try {
|
||||
//endpointUser.setAddress(new AttributedURI("http://dl10.di.uoa.gr:8181/usermanagement-ws/LiferaySOAPGroupManager"));
|
||||
endpointUser.setAddress(new AttributedURI(umServiceLocation + UsersManagementServiceConstants.LiferaySOAPGroupManager));
|
||||
} catch (MalformedURIException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
LiferaySOAPGroupManagerServiceAddressingLocator loc = new LiferaySOAPGroupManagerServiceAddressingLocator();
|
||||
try {
|
||||
LiferaySOAPGroupManagerPortType groupStub = loc.getLiferaySOAPGroupManagerPortTypePort(endpointUser);
|
||||
|
||||
GetScope getScope = new GetScope();
|
||||
getScope.setArg0(groupId);
|
||||
String scope = groupStub.getScope(getScope).get_return();
|
||||
return scope;
|
||||
} catch (ServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (GroupRetrievalFault e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (UserManagementSystemException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public String getGroupParentId(String groupId) {
|
||||
EndpointReferenceType endpointUser = new EndpointReferenceType();
|
||||
try {
|
||||
//endpointUser.setAddress(new AttributedURI("http://dl10.di.uoa.gr:8181/usermanagement-ws/LiferaySOAPGroupManager"));
|
||||
endpointUser.setAddress(new AttributedURI(umServiceLocation + UsersManagementServiceConstants.LiferaySOAPGroupManager));
|
||||
} catch (MalformedURIException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
LiferaySOAPGroupManagerServiceAddressingLocator loc = new LiferaySOAPGroupManagerServiceAddressingLocator();
|
||||
try {
|
||||
LiferaySOAPGroupManagerPortType groupStub = loc.getLiferaySOAPGroupManagerPortTypePort(endpointUser);
|
||||
|
||||
GetGroupParentId getGroupParentId = new GetGroupParentId();
|
||||
getGroupParentId.setArg0(groupId);
|
||||
long parentId = groupStub.getGroupParentId(getGroupParentId).get_return();
|
||||
return Long.toString(parentId);
|
||||
} catch (ServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (GroupRetrievalFault e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (UserManagementSystemException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (RemoteException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,114 @@
|
|||
package org.gcube.application.framework.core.security;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.xml.rpc.ServiceException;
|
||||
|
||||
import org.gcube.application.framework.core.util.Settings;
|
||||
import org.gcube.vomanagement.vomsapi.ExtendedVOMSAdmin;
|
||||
import org.gcube.vomanagement.vomsapi.VOMSAdmin;
|
||||
import org.gcube.vomanagement.vomsapi.impl.VOMSAPIConfiguration;
|
||||
import org.gcube.vomanagement.vomsapi.impl.VOMSAPIConfigurationException;
|
||||
import org.gcube.vomanagement.vomsapi.impl.VOMSAPIFactory;
|
||||
|
||||
/**
|
||||
* @author Valia Tsagkalidou (NKUA)
|
||||
*
|
||||
*/
|
||||
public class VOMSAdminManager {
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
protected static VOMSAPIFactory factory = null;
|
||||
protected static VOMSAdmin vomsAdmin = null;
|
||||
protected static ExtendedVOMSAdmin extendedVomsAdmin = null;
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public static VOMSAPIFactory getVOMSFactory()
|
||||
{
|
||||
if(factory == null)
|
||||
{
|
||||
try {
|
||||
System.out.println("I am in ASL and I am creating vomsAdmin - location should be printed");
|
||||
System.out.println("The location is: " + Settings.getInstance().getProperty("sharedDir") + File.separator + "vomsAPI.properties");
|
||||
// must be uncomented!!!!!
|
||||
//vomsAdmin = new VOMSAdminImpl(Settings.getInstance().getProperty("sharedDir")+ File.separator + "vomsAPI.properties");
|
||||
factory = new VOMSAPIFactory(new VOMSAPIConfiguration(new File(Settings.getInstance().getProperty("sharedDir")+ File.separator + "vomsAPI.properties")));
|
||||
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return factory;
|
||||
}
|
||||
|
||||
|
||||
public static VOMSAdmin getVOMSAdmin() {
|
||||
if (vomsAdmin == null) {
|
||||
if (factory == null) {
|
||||
try {
|
||||
System.out.println("I am in ASL and I am creating vomsAdmin - location should be printed");
|
||||
System.out.println("The location is: " + Settings.getInstance().getProperty("sharedDir") + File.separator + "vomsAPI.properties");
|
||||
// must be uncomented!!!!!
|
||||
//vomsAdmin = new VOMSAdminImpl(Settings.getInstance().getProperty("sharedDir")+ File.separator + "vomsAPI.properties");
|
||||
factory = new VOMSAPIFactory(new VOMSAPIConfiguration(new File(Settings.getInstance().getProperty("sharedDir")+ File.separator + "vomsAPI.properties")));
|
||||
|
||||
vomsAdmin = factory.getVOMSAdmin();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
vomsAdmin = factory.getVOMSAdmin();
|
||||
} catch (VOMSAPIConfigurationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (ServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return vomsAdmin;
|
||||
}
|
||||
|
||||
|
||||
public static ExtendedVOMSAdmin getExtendedVomsAdmin() {
|
||||
if (extendedVomsAdmin == null) {
|
||||
if (factory == null) {
|
||||
try {
|
||||
System.out.println("I am in ASL and I am creating vomsAdmin - location should be printed");
|
||||
System.out.println("The location is: " + Settings.getInstance().getProperty("sharedDir") + File.separator + "vomsAPI.properties");
|
||||
// must be uncomented!!!!!
|
||||
//vomsAdmin = new VOMSAdminImpl(Settings.getInstance().getProperty("sharedDir")+ File.separator + "vomsAPI.properties");
|
||||
factory = new VOMSAPIFactory(new VOMSAPIConfiguration(new File(Settings.getInstance().getProperty("sharedDir")+ File.separator + "vomsAPI.properties")));
|
||||
|
||||
extendedVomsAdmin = factory.getExtendedVOMSAdmin();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
else {
|
||||
try {
|
||||
extendedVomsAdmin = factory.getExtendedVOMSAdmin();
|
||||
} catch (VOMSAPIConfigurationException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
} catch (ServiceException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return extendedVomsAdmin;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,303 @@
|
|||
package org.gcube.application.framework.core.session;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import org.gcube.application.framework.accesslogger.library.impl.AccessLogger;
|
||||
import org.gcube.application.framework.accesslogger.model.LoginToVreAccessLogEntry;
|
||||
import org.gcube.application.framework.core.cache.CachesManager;
|
||||
import org.gcube.application.framework.core.security.PortalSecurityManager;
|
||||
import org.gcube.application.framework.core.util.ASLGroupModel;
|
||||
import org.gcube.application.framework.core.util.SessionConstants;
|
||||
import org.gcube.application.framework.core.util.UserCredential;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.gridforum.jgss.ExtendedGSSCredential;
|
||||
|
||||
/**
|
||||
* @author Valia Tsagkalidou (NKUA)
|
||||
*
|
||||
*/
|
||||
public class ASLSession{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
private HashMap<String, Object> innerSession;
|
||||
private long lastUsedTime;
|
||||
private String externalSessionID;
|
||||
private String username;
|
||||
private ExtendedGSSCredential credential;
|
||||
private GCUBEScope scope;
|
||||
private HashMap<String, Notifier> notifiers;
|
||||
String scopeName;
|
||||
private ASLGroupModel groupModel;
|
||||
private boolean loggedIn = false;
|
||||
|
||||
|
||||
// ACCESS LOGGER
|
||||
AccessLogger accessLogger = AccessLogger.getAccessLogger();
|
||||
|
||||
/**
|
||||
* A constructor based on the user and an external ID
|
||||
* @param externalSessionId the external id
|
||||
* @param user the username
|
||||
*/
|
||||
ASLSession(String externalSessionId, String user)
|
||||
{
|
||||
innerSession = new HashMap<String, Object>();
|
||||
notifiers = new HashMap<String, Notifier>();
|
||||
lastUsedTime = System.currentTimeMillis();
|
||||
username = user;
|
||||
externalSessionID = externalSessionId;
|
||||
groupModel = new ASLGroupModel();
|
||||
}
|
||||
|
||||
private void initializeAttributes() {
|
||||
for (String key:innerSession.keySet()) {
|
||||
if (key.equals("collectionsPresentableFields") || key.equals(SessionConstants.collectionsHierarchy)) {
|
||||
innerSession.remove(key);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the session is still valid or not
|
||||
*/
|
||||
public boolean isValid()
|
||||
{
|
||||
if((System.currentTimeMillis() - lastUsedTime) > 1800000) // 30 minutes
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether the session is empty or not
|
||||
*/
|
||||
public boolean isEmpty()
|
||||
{
|
||||
lastUsedTime = System.currentTimeMillis();
|
||||
return innerSession.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name of the attribute
|
||||
* @return whether the name attribute exists in the session
|
||||
*/
|
||||
public boolean hasAttribute(String name)
|
||||
{
|
||||
lastUsedTime = System.currentTimeMillis();
|
||||
return innerSession.containsKey(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return a set of all the attributes in the session
|
||||
*/
|
||||
public Set<String> getAttributeNames()
|
||||
{
|
||||
lastUsedTime = System.currentTimeMillis();
|
||||
return innerSession.keySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name of the attribute
|
||||
* @return the value of the named attribute
|
||||
*/
|
||||
public Object getAttribute(String name)
|
||||
{
|
||||
lastUsedTime = System.currentTimeMillis();
|
||||
return innerSession.get(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name of the attribute
|
||||
* @param value the value of the attribute
|
||||
*/
|
||||
public void setAttribute(String name, Object value)
|
||||
{
|
||||
lastUsedTime = System.currentTimeMillis();
|
||||
innerSession.put(name, value);
|
||||
}
|
||||
|
||||
public String getOriginalScopeName() {
|
||||
return scopeName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the named attribute from the session
|
||||
* @param name the name of the attribute
|
||||
* @return the removed object
|
||||
*/
|
||||
public Object removeAttribute(String name)
|
||||
{
|
||||
lastUsedTime = System.currentTimeMillis();
|
||||
return innerSession.remove(name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes all the attributes from the session
|
||||
*/
|
||||
public void removeAll()
|
||||
{
|
||||
lastUsedTime = System.currentTimeMillis();
|
||||
innerSession.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* invalidates the session
|
||||
*/
|
||||
public void invalidate()
|
||||
{
|
||||
lastUsedTime = System.currentTimeMillis() - 2000000; //more than 30 minutes
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the credential
|
||||
*/
|
||||
public ExtendedGSSCredential getCredential() {
|
||||
return credential;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the external session id (passed to the constructor)
|
||||
*/
|
||||
public String getExternalSessionID() {
|
||||
return externalSessionID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the username
|
||||
*/
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the scope
|
||||
*/
|
||||
public GCUBEScope getScope() {
|
||||
System.out.println("The scope is being returned - username: " + username + " scope: " + scope.getName());
|
||||
return scope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the scope (VRE)
|
||||
*/
|
||||
public String getScopeName()
|
||||
{
|
||||
System.out.println("The scope is name: " + scope);
|
||||
System.out.println("the username is: " + username);
|
||||
if (scope != null)
|
||||
return scope.toString();
|
||||
else
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param scope the scope name (VRE)
|
||||
*/
|
||||
public void setScope(String scope) {
|
||||
System.out.println("The scope about to set is: " + scope);
|
||||
lastUsedTime = System.currentTimeMillis();
|
||||
String test = scope.trim();
|
||||
if (test == null)
|
||||
System.out.println("1");
|
||||
test = scope.trim().substring(1);
|
||||
if (test == null)
|
||||
System.out.println("2");
|
||||
String[] split = scope.trim().substring(1).split("/",2);
|
||||
// Uncomment this and comment the line bellow for devsec
|
||||
// String vo = "/" + split[0].toLowerCase();
|
||||
String vo = "/" + split[0];
|
||||
if(split.length > 1)
|
||||
vo += "/" + split[1];
|
||||
System.out.println("*** VRE to be set:" + vo + " ***");
|
||||
System.out.println("GCube scope returns: " + GCUBEScope.getScope(vo));
|
||||
this.scope = GCUBEScope.getScope(vo);
|
||||
String previousScopeName = scopeName;
|
||||
scopeName = vo;
|
||||
System.out.println("la" + scope);
|
||||
if(new PortalSecurityManager(this.scope).isSecurityEnabled())
|
||||
this.credential = UserCredential.getCredential(username, scope);
|
||||
|
||||
// get the attribute that indicates of log in has been done from the login portlet - or if the user logs in from a bookmark
|
||||
if (loggedIn == true) {
|
||||
// don't log
|
||||
initializeAttributes();
|
||||
// clear the attribute
|
||||
loggedIn = false;
|
||||
System.out.println("Passing the logging because the variable was set");
|
||||
return;
|
||||
}
|
||||
if ((previousScopeName != null && !previousScopeName.equals(scopeName)) || previousScopeName == null) {
|
||||
System.out.println("Logging the entrance");
|
||||
innerSession.clear();
|
||||
// ACCESS LOGGER
|
||||
LoginToVreAccessLogEntry loginEntry = new LoginToVreAccessLogEntry();
|
||||
accessLogger.logEntry(username, scope, loginEntry);
|
||||
} else
|
||||
System.out.println("Passing the logging because the scope was the same");
|
||||
initializeAttributes();
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void logUserLogin(String scope) {
|
||||
System.out.println("LogUserLogin method called");
|
||||
innerSession.clear();
|
||||
loggedIn = true;
|
||||
// ACCESS LOGGER
|
||||
LoginToVreAccessLogEntry loginEntry = new LoginToVreAccessLogEntry();
|
||||
accessLogger.logEntry(username, scope, loginEntry);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param notification the name of the notification to wait for
|
||||
* @throws InterruptedException when the thread is interrupted
|
||||
*/
|
||||
public void waitNotification(String notification) throws InterruptedException
|
||||
{
|
||||
Notifier notifier = notifiers.get(notification);
|
||||
if(notifier == null)
|
||||
{
|
||||
notifier = new Notifier();
|
||||
notifiers.put(notification, notifier);
|
||||
}
|
||||
|
||||
lastUsedTime = System.currentTimeMillis();
|
||||
notifier.waitNotification();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param notification the name of the notification to send notification
|
||||
* @throws InterruptedException when the thread is interrupted
|
||||
*/
|
||||
public void notifyAllWaiting(String notification) throws InterruptedException
|
||||
{
|
||||
Notifier notifier = notifiers.get(notification);
|
||||
if(notifier == null)
|
||||
{
|
||||
notifier = new Notifier();
|
||||
notifiers.put(notification, notifier);
|
||||
}
|
||||
|
||||
lastUsedTime = System.currentTimeMillis();
|
||||
notifier.notifyAllWaiting();
|
||||
}
|
||||
|
||||
public void setGroupModelInfos(String groupName, long groupId) {
|
||||
groupModel.setGroupName(groupName);
|
||||
groupModel.setGroupId(groupId);
|
||||
}
|
||||
|
||||
public long getGroupId() {
|
||||
return groupModel.getGroupId();
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return groupModel.getGroupName();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
package org.gcube.application.framework.core.session;
|
||||
|
||||
import java.util.concurrent.Semaphore;
|
||||
|
||||
class Notifier {
|
||||
|
||||
Semaphore sem;
|
||||
|
||||
Notifier() {
|
||||
sem = new Semaphore(0, true);
|
||||
}
|
||||
|
||||
|
||||
public void waitNotification() throws InterruptedException
|
||||
{
|
||||
sem.acquire();
|
||||
System.out.println("\n\njust woke up!!!\n\n");
|
||||
}
|
||||
|
||||
public void notifyAllWaiting() throws InterruptedException
|
||||
{
|
||||
System.out.println("Sending wake up signal to " + sem.getQueueLength() + " receivers...");
|
||||
sem.release(sem.getQueueLength());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,75 @@
|
|||
package org.gcube.application.framework.core.session;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
|
||||
public class SessionManager {
|
||||
|
||||
protected static Thread thread = new CleanSessionThread();
|
||||
protected static SessionManager sessionManager = new SessionManager();
|
||||
protected HashMap<String, ASLSession> sessions;
|
||||
|
||||
protected SessionManager() {
|
||||
sessions = new HashMap<String, ASLSession>();
|
||||
thread.setDaemon(true);
|
||||
thread.start();
|
||||
}
|
||||
|
||||
public static SessionManager getInstance() {
|
||||
return sessionManager;
|
||||
}
|
||||
|
||||
public ASLSession getASLSession(String externalSessionID, String username)
|
||||
{
|
||||
ASLSession session = sessions.get(externalSessionID + "_" + username);
|
||||
if(session == null || !session.isValid() || !session.getUsername().equals(username))
|
||||
{
|
||||
session = new ASLSession(externalSessionID, username);
|
||||
sessions.put(externalSessionID + "_" + username, session);
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
thread.interrupt();
|
||||
System.out.println(new Date(System.currentTimeMillis()) + " clean thread was interrupted");
|
||||
thread.join();
|
||||
System.out.println(new Date(System.currentTimeMillis()) + " clean thread was joint");
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
|
||||
protected static class CleanSessionThread extends Thread
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
while(true)
|
||||
{
|
||||
try {
|
||||
Thread.sleep(300000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
System.out.println(new Date(System.currentTimeMillis()) + " clean thread was interrupted (in clean thread)");
|
||||
break;
|
||||
}
|
||||
//TODO: cleanup invalid sessions: add locks...
|
||||
Set<String> keys = sessionManager.sessions.keySet();
|
||||
Iterator<String> iter = keys.iterator();
|
||||
while(iter.hasNext())
|
||||
{
|
||||
String extSessionID = iter.next();
|
||||
if(!sessionManager.sessions.get(extSessionID).isValid())
|
||||
{
|
||||
sessionManager.sessions.remove(extSessionID);
|
||||
}
|
||||
}
|
||||
}
|
||||
System.out.println(new Date(System.currentTimeMillis()) + " clean thread was terminated");
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,37 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
public class ASLGroupModel {
|
||||
|
||||
long groupId;
|
||||
String name;
|
||||
String description;
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public void setDescription(String description) {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public ASLGroupModel() {
|
||||
|
||||
}
|
||||
|
||||
public void setGroupId(long groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
|
||||
public void setGroupName(String groupName) {
|
||||
this.name = groupName;
|
||||
}
|
||||
|
||||
public long getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
|
||||
public String getGroupName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
/**
|
||||
* @author Valia Tsagkalidou (KNUA)
|
||||
*
|
||||
*/
|
||||
public class CacheEntryConstants {
|
||||
|
||||
/**
|
||||
* Cache constant for VRE
|
||||
*/
|
||||
public static final String vre = "vre";
|
||||
|
||||
/**
|
||||
* Cache constant for oid
|
||||
*/
|
||||
public static final String oid = "oid";
|
||||
|
||||
/**
|
||||
* Cache constant for metadataColID
|
||||
*/
|
||||
public static final String metadataColID = "metadataColID";
|
||||
|
||||
/**
|
||||
* Cache constant for name
|
||||
*/
|
||||
public static final String name = "name";
|
||||
|
||||
/**
|
||||
* Cache constant for id
|
||||
*/
|
||||
public static final String id = "id";
|
||||
|
||||
/**
|
||||
* Cache constant for username
|
||||
*/
|
||||
public static final String username = "username";
|
||||
|
||||
/**
|
||||
* Cache constant for width
|
||||
*/
|
||||
public static final String width = "width";
|
||||
|
||||
/**
|
||||
* Cache constant for height
|
||||
*/
|
||||
public static final String height = "height";
|
||||
|
||||
/**
|
||||
* thumbOptions
|
||||
*/
|
||||
public static final String thumbOptions = "thumbOptions";
|
||||
|
||||
/**
|
||||
* vreResource
|
||||
*/
|
||||
public static final String vreResource = "vreResource";
|
||||
|
||||
}
|
|
@ -0,0 +1,472 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Vector;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
import org.gcube.application.framework.core.GenericResourceInfoI;
|
||||
import org.gcube.application.framework.core.cache.CachesManager;
|
||||
import org.gcube.application.framework.core.genericresources.model.ISGenericResource;
|
||||
import org.gcube.application.framework.core.security.PortalSecurityManager;
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.application.framework.core.session.SessionManager;
|
||||
import org.gcube.application.framework.core.util.CacheEntryConstants;
|
||||
import org.gcube.application.framework.core.util.QueryString;
|
||||
import org.gcube.application.framework.core.util.SessionConstants;
|
||||
import org.gcube.common.core.contexts.GHNContext;
|
||||
import org.gcube.common.core.informationsystem.client.AtomicCondition;
|
||||
import org.gcube.common.core.informationsystem.client.ISClient;
|
||||
import org.gcube.common.core.informationsystem.client.QueryParameter;
|
||||
import org.gcube.common.core.informationsystem.client.XMLResult;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericQuery;
|
||||
import org.gcube.common.core.informationsystem.client.queries.GCUBEGenericResourceQuery;
|
||||
import org.gcube.common.core.informationsystem.publisher.ISPublisher;
|
||||
import org.gcube.common.core.informationsystem.publisher.ISPublisherException;
|
||||
import org.gcube.common.core.resources.GCUBEGenericResource;
|
||||
import org.gcube.common.core.scope.GCUBEScope;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
/**
|
||||
* @author Valia Tsaqgkalidou (NKUA)
|
||||
*/
|
||||
public class GenericResource implements GenericResourceInfoI{
|
||||
|
||||
/**
|
||||
* A static IS publisher in order to communicate with IS
|
||||
*/
|
||||
protected static ISPublisher publisher = null;
|
||||
protected static ISClient client = null;
|
||||
|
||||
/**
|
||||
* The D4Science session to be used
|
||||
*/
|
||||
ASLSession session;
|
||||
|
||||
/**
|
||||
* Constructs a GenericReosurce object
|
||||
* @param extrenalSessionID the external session id which is used for the D4ScienceSession (usually the session.getId() of the HttpSession or PortletSession)
|
||||
* @param username the username of the user that called this constructor
|
||||
*/
|
||||
public GenericResource(String extrenalSessionID, String username)
|
||||
{
|
||||
session = SessionManager.getInstance().getASLSession(extrenalSessionID, username);
|
||||
try {
|
||||
publisher = GHNContext.getImplementation(ISPublisher.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(client == null)
|
||||
{
|
||||
try {
|
||||
client = GHNContext.getImplementation(ISClient.class);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
client = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Constructs a GenericReosurce object
|
||||
* @param session the D4Science session to be used for retrieving information needed
|
||||
*/
|
||||
public GenericResource(ASLSession session) {
|
||||
super();
|
||||
this.session = session;
|
||||
try {
|
||||
publisher = GHNContext.getImplementation(ISPublisher.class);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(client == null)
|
||||
{
|
||||
try {
|
||||
client = GHNContext.getImplementation(ISClient.class);
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
client = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the name of the active VRE
|
||||
*/
|
||||
protected String getDLName()
|
||||
{
|
||||
//SOS
|
||||
//return session.getOriginalScopeName();
|
||||
return session.getOriginalScopeName();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param query the query to retrieve generic resources from cache
|
||||
* @return a list of generic resources
|
||||
*/
|
||||
protected List<ISGenericResource> getGenericResource(QueryString query)
|
||||
{
|
||||
return (List<ISGenericResource>) (CachesManager.getInstance().getGenericResourceCache().get(query).getValue());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new generic resource
|
||||
* @param genericResource the new generic resource
|
||||
* @return the ID of the newly created resource
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public String createGenericResource(ISGenericResource genericResource)
|
||||
throws RemoteException {
|
||||
try {
|
||||
GCUBEGenericResource gCubeRes = GHNContext.getImplementation(GCUBEGenericResource.class);
|
||||
gCubeRes.setID("");
|
||||
gCubeRes.setName(genericResource.getName());
|
||||
gCubeRes.setDescription(genericResource.getDescription());
|
||||
gCubeRes.setBody(genericResource.getBody());
|
||||
gCubeRes.setSecondaryType(genericResource.getSecondaryType());
|
||||
gCubeRes.addScope(session.getScope());
|
||||
|
||||
String Gr = publisher.registerGCUBEResource(gCubeRes, session.getScope(), new PortalSecurityManager(session));
|
||||
Document doc = parseXMLFileToDOM(Gr);
|
||||
XPath xpath = XPathFactory.newInstance().newXPath();
|
||||
try {
|
||||
return (String) xpath.evaluate("/Resource/ID/text()", doc, XPathConstants.STRING);
|
||||
} catch (XPathExpressionException e) {
|
||||
e.printStackTrace();
|
||||
throw new RemoteException();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RemoteException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates a generic resource based on it's ID
|
||||
* @param genericResource the generic resource to be updated
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public void updateGenericResourceByID(ISGenericResource genericResource)
|
||||
throws RemoteException {
|
||||
try {
|
||||
|
||||
//GCUBEGenericResource gCubeRes = GHNContext.getImplementation(GCUBEGenericResource.class);
|
||||
|
||||
System.out.println("In updateGenericResourceByID!");
|
||||
GCUBEGenericResourceQuery query = client.getQuery(GCUBEGenericResourceQuery.class);
|
||||
query.addAtomicConditions(new AtomicCondition("/ID", genericResource.getId()));
|
||||
List<GCUBEGenericResource> result = client.execute(query, session.getScope());
|
||||
|
||||
if (result == null || result.size() == 0) {
|
||||
System.out.println("Error in updateGenericResourceByID: The generic resources list is null");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
GCUBEGenericResource gCubeRes = result.get(0);
|
||||
|
||||
|
||||
// gCubeRes.setID(genericResource.getId());
|
||||
gCubeRes.setName(genericResource.getName());
|
||||
gCubeRes.setDescription(genericResource.getDescription());
|
||||
gCubeRes.setBody(genericResource.getBody());
|
||||
gCubeRes.setSecondaryType(genericResource.getSecondaryType());
|
||||
// gCubeRes.addScope(session.getScope());
|
||||
|
||||
try {
|
||||
//SOS!!!! uncomment this and erase the two lines bellow
|
||||
//publisher.updateGCUBEResource(gCubeRes, session.getScope(), new PortalSecurityManager(session));
|
||||
|
||||
String resultIS = publisher.registerGCUBEResource(gCubeRes, session.getScope(), new PortalSecurityManager(session));
|
||||
System.out.println ("ISPublisher returned: " + resultIS);
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
|
||||
List<ISGenericResource> genRes = new ArrayList<ISGenericResource>();
|
||||
genRes.add(genericResource);
|
||||
QueryString query1 = new QueryString();
|
||||
query1.addParameter(CacheEntryConstants.id, genericResource.getId());
|
||||
query1.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
||||
CachesManager.getInstance().getGenericResourceCache().put(new net.sf.ehcache.Element(query1, genRes));
|
||||
|
||||
query1.clear();
|
||||
query1.put(CacheEntryConstants.name, genericResource.getName().trim());
|
||||
query1.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
||||
if(CachesManager.getInstance().getGenericResourceCache().isElementInMemory(query1) || CachesManager.getInstance().getGenericResourceCache().isElementOnDisk(query1))
|
||||
{
|
||||
CachesManager.getInstance().getGenericResourceCache().get(query1).setTimeToLive(-1);
|
||||
}
|
||||
else {
|
||||
System.out.println("The generic resource was not found");
|
||||
}
|
||||
|
||||
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RemoteException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return a list containing pairs of (name, id) of the available generic resources
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public List<Pair> getAvailableGenericResourceNames() throws RemoteException {
|
||||
List<Pair> pairs = new ArrayList<Pair>();
|
||||
String xquery = "for $query in collection(\"/db/Profiles/GenericResource\")//Document/Data/child::*[local-name()='Profile']/Resource return <Result>{$query/ID}{$query/Profile/Name}</Result>"; // order by $query/Profile/Name
|
||||
GCUBEGenericQuery queryMan;
|
||||
try {
|
||||
queryMan = client.getQuery(GCUBEGenericQuery.class);
|
||||
queryMan.setExpression(xquery);
|
||||
List<XMLResult> res = client.execute(queryMan, session.getScope());
|
||||
String id, name;
|
||||
for(XMLResult xml : res)
|
||||
{
|
||||
try
|
||||
{
|
||||
id = xml.evaluate("//ID/text()").get(0);
|
||||
List<String> var = xml.evaluate("//Name/text()");
|
||||
if(var.size() > 0)
|
||||
name = var.get(0);
|
||||
else
|
||||
name = "";
|
||||
System.out.println(id + " " + name);
|
||||
pairs.add(new Pair(name, id));
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
return pairs;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RemoteException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param id the id of the generic resource
|
||||
* @return a list containing the corresponding generic resources
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public List<ISGenericResource> getGenericResourceByID(String id)
|
||||
throws RemoteException {
|
||||
QueryString query = new QueryString();
|
||||
query.put(CacheEntryConstants.id, id);
|
||||
query.put(CacheEntryConstants.vre, getDLName());
|
||||
return getGenericResource(query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param name the name of the generic resource
|
||||
* @return a list containing the generic resources that have as name the given
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public List<ISGenericResource> getGenericResourceByName(String name)
|
||||
throws RemoteException {
|
||||
QueryString query = new QueryString();
|
||||
query.put(CacheEntryConstants.name, name);
|
||||
query.put(CacheEntryConstants.vre, getDLName());
|
||||
return getGenericResource(query);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return a list containing the generic resources that describe which collections are part of the active VRE as well as their hierarchical structure (the name of this generic resource is "ScenarioCollectionInfo")
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public List<ISGenericResource> getGenericResourceForScenario()
|
||||
throws RemoteException {
|
||||
QueryString query = new QueryString();
|
||||
query.put(CacheEntryConstants.name, SessionConstants.ScenarioSchemaInfo);
|
||||
query.put(CacheEntryConstants.vre, getDLName());
|
||||
return getGenericResource(query);
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes an existing generic resource
|
||||
* @param genericResource the generic resource to be removed
|
||||
* @throws RemoteException when an error has occurred while communicating with IS
|
||||
*/
|
||||
public void removeGenericResource(ISGenericResource genericResource)
|
||||
throws RemoteException {
|
||||
try {
|
||||
publisher.removeGCUBEResource(genericResource.getId(), GCUBEGenericResource.TYPE, session.getScope(), new PortalSecurityManager(session));
|
||||
|
||||
QueryString query = new QueryString();
|
||||
query.addParameter(CacheEntryConstants.id, genericResource.getId());
|
||||
query.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
||||
if(CachesManager.getInstance().getGenericResourceCache().isElementInMemory(query) || CachesManager.getInstance().getGenericResourceCache().isElementOnDisk(query))
|
||||
{
|
||||
genericResource = ((List<ISGenericResource>)CachesManager.getInstance().getGenericResourceCache().get(query).getValue()).get(0);
|
||||
CachesManager.getInstance().getGenericResourceCache().get(query).setTimeToLive(0);
|
||||
}
|
||||
|
||||
query.clear();
|
||||
query.put(CacheEntryConstants.name, genericResource.getName());
|
||||
query.addParameter(CacheEntryConstants.vre, session.getOriginalScopeName());
|
||||
if(CachesManager.getInstance().getGenericResourceCache().isElementInMemory(query) || CachesManager.getInstance().getGenericResourceCache().isElementOnDisk(query))
|
||||
{
|
||||
CachesManager.getInstance().getGenericResourceCache().get(query).setTimeToLive(0);
|
||||
}
|
||||
} catch (ISPublisherException e) {
|
||||
e.printStackTrace();
|
||||
throw new RemoteException();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Parses the xml and returns it as DOM object
|
||||
* @param XMLdoc the xml as a string
|
||||
* @return xml parsed as a Document
|
||||
*/
|
||||
static Document parseXMLFileToDOM(String XMLdoc) {
|
||||
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder;
|
||||
try {
|
||||
builder = dbFactory.newDocumentBuilder();
|
||||
Document doc = builder.parse(new InputSource(new StringReader(XMLdoc)));
|
||||
return doc;
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param xsltType Presentation or Metadata. The type of the xslt
|
||||
* @return A vector which contains all the generic resources, xslts of this type. The xslts are sorted by the schema.
|
||||
*/
|
||||
public HashMap<String,Vector<String[]>> getAllXslts(String xsltType) {
|
||||
HashMap<String,Vector<String[]>> schemas_xslts = new HashMap<String,Vector<String[]>>();
|
||||
Vector<String[]> xslts = null;
|
||||
|
||||
|
||||
|
||||
List<String[]> result = null;
|
||||
try {
|
||||
result = retrieveGenericResourcesFromNameParts(xsltType, session.getScope());
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
/* if (xsltType.equals("MetadataXSLT")) {
|
||||
for (int i=0; i<result.size(); i++) {
|
||||
String fullName = result.get(i)[0];
|
||||
String id = result.get(i)[1];
|
||||
String tmp = fullName.substring(xsltType.length()+1,fullName.length());
|
||||
String parts[] = tmp.split("_");
|
||||
String schemaName = parts[0];
|
||||
String xsltName = parts[1];
|
||||
xslts = schemas_xslts.get(schemaName.replaceFirst("%5f", "_"));
|
||||
if (xslts == null) {
|
||||
xslts = new Vector<String[]>();
|
||||
schemas_xslts.put(schemaName.replaceFirst("%5f", "_"), xslts);
|
||||
}
|
||||
|
||||
// add the xslt name and id
|
||||
String s[] = new String[2];
|
||||
s[0] = xsltName;
|
||||
s[1] = id;
|
||||
xslts.add(s);
|
||||
}
|
||||
return schemas_xslts;
|
||||
}*/
|
||||
// else {
|
||||
// Presentation xslts
|
||||
System.out.println("Inside getAllXslts");
|
||||
System.out.println("The type is: " + xsltType);
|
||||
for (int i=0; i<result.size(); i++) {
|
||||
String fullName = result.get(i)[0];
|
||||
System.out.println("fullname: " + fullName);
|
||||
String id = result.get(i)[1];
|
||||
System.out.println("id: " + id);
|
||||
// String tmp = fullName.substring(xsltType.length()+1,fullName.length());
|
||||
String tmp = fullName.substring(xsltType.length()+3,fullName.length());
|
||||
System.out.println("tmp: " + tmp);
|
||||
String parts[] = tmp.split("-\\|-");
|
||||
String schemaName = parts[0];
|
||||
for (int k = 0; k < parts.length; k++) {
|
||||
System.out.println("part: " + parts[k]);
|
||||
}
|
||||
System.out.println("schemaName: " + schemaName);
|
||||
String xsltName = parts[1];
|
||||
System.out.println("xsltName: " + xsltName);
|
||||
xslts = schemas_xslts.get(schemaName);
|
||||
if (xslts == null) {
|
||||
xslts = new Vector<String[]>();
|
||||
schemas_xslts.put(schemaName, xslts);
|
||||
}
|
||||
|
||||
// add the xslt name and id
|
||||
String s[] = new String[2];
|
||||
s[0] = xsltName;
|
||||
s[1] = id;
|
||||
xslts.add(s);
|
||||
}
|
||||
return schemas_xslts;
|
||||
// }
|
||||
}
|
||||
|
||||
private static List<String[]> retrieveGenericResourcesFromNameParts(String nameParts, GCUBEScope scope) throws Exception {
|
||||
|
||||
String condition = "contains($result/Profile/Name/string(), '" + nameParts + "')";
|
||||
|
||||
GCUBEGenericQuery query = client.getQuery("GCUBEResourceQuery");
|
||||
query.addParameters(new QueryParameter("FILTER", condition),
|
||||
new QueryParameter("TYPE", GCUBEGenericResource.TYPE),
|
||||
new QueryParameter("RESULT", "<Result>{$result/ID}{$result/Profile/Name}</Result>"));
|
||||
|
||||
List<XMLResult> result = client.execute(query, scope);
|
||||
List<String[]> ret = new LinkedList<String[]>();
|
||||
if (result==null || result.size()==0)
|
||||
throw new Exception("No generic resources were found.");
|
||||
|
||||
for(XMLResult r : result){
|
||||
String[] nameAndID = { r.evaluate("//Name/text()").get(0), r.evaluate("//ID/text()").get(0) };
|
||||
System.out.println("Inside retrieveGenericResourcesFromNameParts name: " + nameAndID[0]);
|
||||
System.out.println("Inside retrieveGenericResourcesFromNameParts id: " + nameAndID[1]);
|
||||
ret.add(nameAndID);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,161 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import javax.xml.transform.OutputKeys;
|
||||
import javax.xml.transform.Templates;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerException;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.dom.DOMSource;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl;
|
||||
|
||||
public class LayoutPortlets {
|
||||
|
||||
protected static final String PORTLETS_XSL = "/etc/layoutPortlets.xsl";
|
||||
|
||||
|
||||
public static void addPortletsToSession(ASLSession session, Document layout) throws IOException, TransformerException, ParserConfigurationException, SAXException {
|
||||
String layoutString = getStringFromDocument(layout);
|
||||
String layoutXSL = getPortletsXSLT();
|
||||
String portlets = transform(layoutString, layoutXSL);
|
||||
|
||||
Document portletsDoc = getDocumentFromString(portlets);
|
||||
|
||||
ArrayList<String> availablePortlets = new ArrayList<String>();
|
||||
|
||||
Element root = portletsDoc.getDocumentElement();
|
||||
NodeList portletNodes = root.getChildNodes();
|
||||
|
||||
for (int i = 0; i < portletNodes.getLength(); i++) {
|
||||
String portletString = portletNodes.item(i).getTextContent();
|
||||
String[] split = portletString.split("#");
|
||||
String portletName = split[1];
|
||||
availablePortlets.add(portletName);
|
||||
System.out.println("Adding Portlet name to session: " + split[1]);
|
||||
}
|
||||
|
||||
session.setAttribute("availablePortlets", availablePortlets);
|
||||
}
|
||||
|
||||
private static String convertStreamToString(InputStream is) throws IOException {
|
||||
if (is != null) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String line;
|
||||
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line).append("\n");
|
||||
}
|
||||
} finally {
|
||||
is.close();
|
||||
}
|
||||
return sb.toString();
|
||||
} else
|
||||
return "";
|
||||
}
|
||||
|
||||
public static String getPortletsXSLT() throws IOException {
|
||||
InputStream is = LayoutPortlets.class.getResourceAsStream(PORTLETS_XSL); //??
|
||||
|
||||
if (is == null){
|
||||
|
||||
System.out.println("Default XSLT resource not found on "+PORTLETS_XSL);
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStreamReader isr = new InputStreamReader(is);
|
||||
|
||||
BufferedReader filebuf = null;
|
||||
String nextStr = null;
|
||||
String toReturn = new String();
|
||||
try {
|
||||
filebuf = new BufferedReader(isr);
|
||||
nextStr = filebuf.readLine();
|
||||
while (nextStr != null) {
|
||||
toReturn += nextStr ;
|
||||
nextStr = filebuf.readLine();
|
||||
}
|
||||
filebuf.close(); // chiude il file
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
|
||||
return toReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param xml the XML to convert.
|
||||
* @param xslt the XML used for the conversion.
|
||||
* @return the HTML.
|
||||
* @throws TransformerException if an error occurs.
|
||||
*/
|
||||
public static String transform(String xml, String xslt) throws TransformerException
|
||||
{
|
||||
|
||||
TransformerFactoryImpl factory = new TransformerFactoryImpl();
|
||||
StreamSource sourceInput = new StreamSource(new ByteArrayInputStream(xslt.getBytes()));
|
||||
Templates sheet = factory.newTemplates(sourceInput);
|
||||
|
||||
Transformer instance = sheet.newTransformer();
|
||||
instance.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "true");
|
||||
StringWriter w = new StringWriter();
|
||||
instance.transform(new StreamSource(new StringReader(xml)), new StreamResult(w));
|
||||
|
||||
return w.toString();
|
||||
}
|
||||
|
||||
//method to convert Document to String
|
||||
private static String getStringFromDocument(Document doc)
|
||||
{
|
||||
try
|
||||
{
|
||||
DOMSource domSource = new DOMSource(doc);
|
||||
StringWriter writer = new StringWriter();
|
||||
StreamResult result = new StreamResult(writer);
|
||||
TransformerFactory tf = TransformerFactory.newInstance();
|
||||
Transformer transformer = tf.newTransformer();
|
||||
transformer.transform(domSource, result);
|
||||
return writer.toString();
|
||||
}
|
||||
catch(TransformerException ex)
|
||||
{
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private static Document getDocumentFromString(String str) throws ParserConfigurationException, SAXException, IOException {
|
||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder builder = factory.newDocumentBuilder();
|
||||
Document document = builder.parse(new InputSource(new StringReader(str)));
|
||||
|
||||
return document;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
/**
|
||||
* @author Valia Tsagkalidou (KNUA)
|
||||
*
|
||||
*/
|
||||
public class NotificationConstants {
|
||||
|
||||
public static final String CollectionsStatusChange = "CollectionsStatusChange";
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
/**
|
||||
* @author Valia Tsaqgkalidou (NKUA)
|
||||
*/
|
||||
public class Pair {
|
||||
protected String name;
|
||||
protected String value;
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name to set
|
||||
*/
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the name
|
||||
* @param value the value
|
||||
*/
|
||||
public Pair(String name, String value) {
|
||||
super();
|
||||
this.name = name;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* @author Valia Tsagkalidou (KNUA)
|
||||
*
|
||||
*/
|
||||
public class QueryString extends HashMap<String, String>{
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
public QueryString() {
|
||||
super();
|
||||
}
|
||||
|
||||
public void addParameter(String name, String value)
|
||||
{
|
||||
this.put(name, value);
|
||||
}
|
||||
|
||||
public void removeParameter(String name)
|
||||
{
|
||||
this.remove(name);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class SchemaFieldPair implements Cloneable{
|
||||
|
||||
String schema;
|
||||
String fieldName;
|
||||
String sortValue;
|
||||
ArrayList<String> metadataCollectionIds;
|
||||
ArrayList<String> metadataCollectionLanguage;
|
||||
ArrayList<String> contentCollectionIds;
|
||||
|
||||
public ArrayList<String> getContentCollectionIds() {
|
||||
return contentCollectionIds;
|
||||
}
|
||||
|
||||
public ArrayList<String> getMetadataCollectionLanguage() {
|
||||
return metadataCollectionLanguage;
|
||||
}
|
||||
|
||||
|
||||
public String getSortValue() {
|
||||
return sortValue;
|
||||
}
|
||||
|
||||
|
||||
public void setSortValue(String sortValue) {
|
||||
this.sortValue = sortValue;
|
||||
}
|
||||
|
||||
|
||||
public SchemaFieldPair() {
|
||||
schema = new String();
|
||||
fieldName = new String();
|
||||
sortValue = new String();
|
||||
}
|
||||
|
||||
public SchemaFieldPair (String schemaName, String field, String sortValueName) {
|
||||
schema = schemaName;
|
||||
fieldName = field;
|
||||
sortValue = sortValueName;
|
||||
metadataCollectionIds = new ArrayList();
|
||||
metadataCollectionLanguage = new ArrayList();
|
||||
contentCollectionIds = new ArrayList();
|
||||
}
|
||||
|
||||
|
||||
public ArrayList<String> getMetadataCollectionIds() {
|
||||
return metadataCollectionIds;
|
||||
}
|
||||
|
||||
public void addMetadataColIdAndLanguage(String mid, String language) {
|
||||
metadataCollectionIds.add(mid);
|
||||
metadataCollectionLanguage.add(language);
|
||||
}
|
||||
|
||||
public void addContentCollectionId(String colId) {
|
||||
if (contentCollectionIds == null)
|
||||
contentCollectionIds = new ArrayList<String>();
|
||||
contentCollectionIds.add(colId);
|
||||
}
|
||||
|
||||
public SchemaFieldPair clone() {
|
||||
|
||||
SchemaFieldPair newSFP = new SchemaFieldPair();
|
||||
newSFP.setFieldName(new String(this.fieldName));
|
||||
newSFP.setSchema(new String(this.schema));
|
||||
newSFP.setSortValue(new String(this.sortValue));
|
||||
if (metadataCollectionIds != null) {
|
||||
for (int i = 0; i < metadataCollectionIds.size(); i++) {
|
||||
newSFP.addMetadataColIdAndLanguage(new String(this.metadataCollectionIds.get(i)), new String(this.metadataCollectionLanguage.get(i)));
|
||||
}
|
||||
}
|
||||
if (contentCollectionIds != null) {
|
||||
for (int i = 0; i < contentCollectionIds.size(); i++) {
|
||||
newSFP.addContentCollectionId(this.contentCollectionIds.get(i));
|
||||
}
|
||||
}
|
||||
|
||||
return newSFP;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param schemaName
|
||||
*/
|
||||
public void setSchema(String schemaName) {
|
||||
schema = schemaName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param field
|
||||
*/
|
||||
public void setFieldName (String field) {
|
||||
fieldName = field;
|
||||
}
|
||||
|
||||
public String getSchema() {
|
||||
return schema;
|
||||
}
|
||||
|
||||
public String getFieldName () {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,61 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Panagiota Koltsida (NKUA)
|
||||
* @author Valia Tsagkalidou (NKUA)
|
||||
*
|
||||
*/
|
||||
//TODO: Done!!!
|
||||
public class SearchField implements Serializable, Cloneable{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* Name of the criterion
|
||||
*/
|
||||
public String name;
|
||||
|
||||
/**
|
||||
* Value of the criterion
|
||||
*/
|
||||
public String value;
|
||||
|
||||
/**
|
||||
* Type of the criterion
|
||||
*/
|
||||
public String type;
|
||||
|
||||
/**
|
||||
* The x-path to apply for sorting the results
|
||||
*/
|
||||
public String sort;
|
||||
|
||||
public SearchField() {
|
||||
name = "";
|
||||
value = "";
|
||||
type = "";
|
||||
sort = "";
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#clone()
|
||||
*/
|
||||
@Override
|
||||
public SearchField clone() throws CloneNotSupportedException {
|
||||
// TODO Auto-generated method stub
|
||||
return (SearchField) super.clone();
|
||||
}
|
||||
|
||||
public boolean isEqual(SearchField sf) {
|
||||
if (sf.name.equals(this.name) && sf.value.equals(this.value))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,39 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.apache.axis.message.addressing.EndpointReference;
|
||||
import org.gcube.application.framework.core.cache.RIsManager;
|
||||
import org.gcube.application.framework.core.session.ASLSession;
|
||||
import org.gcube.informationsystem.cache.SrvType;
|
||||
|
||||
public class ServiceUtils {
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @param srvClass The service class
|
||||
* @param srvName The service name
|
||||
* @param srvType The service type (SIMPLE, FACTORY or STATEFULL)
|
||||
* @param session
|
||||
* @return the epr Address
|
||||
*/
|
||||
public static String getEprAddressOfService(String srvClass, String srvName, String srvType, ASLSession session) {
|
||||
EndpointReference[] eprs;
|
||||
try {
|
||||
|
||||
eprs = RIsManager.getInstance().getISCache(
|
||||
session.getScope()).getEPRsFor(srvClass, srvName,
|
||||
srvType);
|
||||
|
||||
Random rand = new Random();
|
||||
int random = rand.nextInt(eprs.length);
|
||||
|
||||
return eprs[random].getAddress().toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,135 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
/**
|
||||
* @author Valia Tsagkalidou (KNUA)
|
||||
*
|
||||
*/
|
||||
public class SessionConstants {
|
||||
|
||||
/**
|
||||
* Used for generic resource name which contains the static search configuration
|
||||
*/
|
||||
public static final String ScenarioSchemaInfo = "ScenarioCollectionInfo";
|
||||
|
||||
/**
|
||||
* Used for a variable in the session representing a HashMap<String, List<SearchField>>:
|
||||
* pairs: (schema, list of searchable fields for this schema)
|
||||
*/
|
||||
public static final String SchemataInfo = "SchemataInfo";
|
||||
|
||||
/**
|
||||
* Used for a variable in the session representing a HashMap<String, ArrayList<SchemaFieldPair>>:
|
||||
* pairs: (abstract field, list of mappable field for each schema)
|
||||
*/
|
||||
public static final String abstractFieldsInfo = "AbstractFieldsInfo";
|
||||
|
||||
/**
|
||||
* Used for generic resource name which contains info about searchable fields per schema...
|
||||
*/
|
||||
public static final String MetadataSchemaInfo = "MetadataSchemaInfo";
|
||||
|
||||
/**
|
||||
* Used for generic resource name which contains info about mappable fields per abstarct field and for every schema
|
||||
*/
|
||||
public static final String SearchFieldsMappingAbstraction = "SearchFieldsMappingAbstraction";
|
||||
|
||||
/**
|
||||
* Used for a variable in the session representing the available collections
|
||||
*/
|
||||
public static final String Collections = "Collections";
|
||||
|
||||
/**
|
||||
* Used for a variable in the session representing the available queries (queries that the user has created)
|
||||
*/
|
||||
public static final String Queries = "Queries";
|
||||
|
||||
/**
|
||||
* Used for a variable in the session that contains info for the geospatial search (boundinf box, time interval, etc)
|
||||
*/
|
||||
public static final String Geospatial = "Geospatial";
|
||||
|
||||
/**
|
||||
* Used for a variable in the session representing the number of the current page number in the results.
|
||||
*/
|
||||
public static final String page_no = "page_no";
|
||||
|
||||
/**
|
||||
* Used for a variable in the session representing how many results were actually read from resultset last time
|
||||
*/
|
||||
public static final String resNo = "resNo";
|
||||
|
||||
/**
|
||||
* Used for a variable in the session representing the total number of result pages...
|
||||
*/
|
||||
public static final String page_total = "page_total";
|
||||
|
||||
/**
|
||||
* Used for a variable in the session representing the index in the current resultset part (where we stopped reading results last time)
|
||||
*/
|
||||
public static final String lastRes = "lastRes";
|
||||
|
||||
/**
|
||||
* Used for a variable in the session representing whether we have reach the last page of results
|
||||
*/
|
||||
public static final String isLast = "isLast";
|
||||
|
||||
/**
|
||||
* Used for a variable in the session that contains info about whether we have go beyond the edges of results... (out of index)
|
||||
*/
|
||||
public static final String out_of_end = "out_of_end";
|
||||
|
||||
/**
|
||||
* the current resultset client
|
||||
*/
|
||||
public static final String rsClient = "rsClient";
|
||||
|
||||
/**
|
||||
* the results objects already processed from the resultset
|
||||
*/
|
||||
public static final String theResultObjects = "theResultObjects";
|
||||
|
||||
/**
|
||||
* the thumbnail urls for each result object (already processed from the resultset )
|
||||
*/
|
||||
public static final String theThumbnails = "theThumbnails";
|
||||
|
||||
/**
|
||||
* the index in the result objects from where we should start reading
|
||||
*/
|
||||
public static final String startingPoint = "startingPoint";
|
||||
|
||||
/**
|
||||
* what type search was applied (Simple, Advanced, Browse, Quick, Google, etc)
|
||||
*/
|
||||
public static final String sourcePortlet = "sourcePortlet";
|
||||
|
||||
/**
|
||||
* the resultset EPR (not used any more)
|
||||
*/
|
||||
public static final String rsEPR = "rsEPR"; /* the Result Set EPR */
|
||||
|
||||
/**
|
||||
* whether to show result rank or not
|
||||
*/
|
||||
public static final String showRank = "showRank";
|
||||
|
||||
/**
|
||||
* an exception occured during search: message to the users
|
||||
*/
|
||||
public static final String searchException = "searchException";
|
||||
|
||||
/**
|
||||
* the id of the active query
|
||||
*/
|
||||
public static final String activeQueryNo = "activeQueryNo";
|
||||
|
||||
/**
|
||||
* the id of the active query to be presented
|
||||
*/
|
||||
public static final String activePresentationQueryNo = "activePresentationQueryNo";
|
||||
|
||||
/**
|
||||
* the collections hierarchy (groups - collections)
|
||||
*/
|
||||
public static final String collectionsHierarchy = "collectionsHierarchy";
|
||||
}
|
|
@ -0,0 +1,58 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.*;
|
||||
import java.net.URISyntaxException;
|
||||
|
||||
public class Settings {
|
||||
|
||||
static Properties props = new Properties();
|
||||
static Settings settings = null;
|
||||
|
||||
Settings()
|
||||
{
|
||||
try
|
||||
{
|
||||
props.load(Settings.class.getResourceAsStream("/etc/settings.properties"));
|
||||
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static Settings getInstance()
|
||||
{
|
||||
if (settings == null)
|
||||
settings = new Settings();
|
||||
return settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the props
|
||||
*/
|
||||
public String getProperty(String key) {
|
||||
String value = props.getProperty(key);
|
||||
if(value.contains("${"))
|
||||
{
|
||||
int start = 0;
|
||||
int i;
|
||||
while((i= value.indexOf("${", start)) != -1)
|
||||
{
|
||||
start = value.indexOf("}", i) +1;
|
||||
String reg = value.substring(i, start);
|
||||
System.out.println(reg);
|
||||
System.out.println(reg.substring(2, reg.length() -1));
|
||||
value = value.replace(reg, (System.getProperty(reg.substring(2, reg.length() -1)) != null)?System.getProperty(reg.substring(2, reg.length() -1)):"");
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,120 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.Reader;
|
||||
import java.io.StringWriter;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.transform.Transformer;
|
||||
import javax.xml.transform.TransformerFactory;
|
||||
import javax.xml.transform.stream.StreamResult;
|
||||
import javax.xml.transform.stream.StreamSource;
|
||||
|
||||
import org.apache.xml.serialize.OutputFormat;
|
||||
import org.apache.xml.serialize.XMLSerializer;
|
||||
import org.w3c.dom.Document;
|
||||
|
||||
/**
|
||||
* @author Valia Tsagkalidou (KNUA)
|
||||
*
|
||||
*/
|
||||
public class TransformXSLT {
|
||||
/**
|
||||
* Transforms an xml document based on the given xslt
|
||||
* @param xslt the xslt for transforming the xml
|
||||
* @param xml the xml to be transformed
|
||||
* @return a string containing the transformed xml (output of the transformation)
|
||||
*/
|
||||
public static String transform(String xslt, String xml)
|
||||
{
|
||||
Transformer transformer;
|
||||
try
|
||||
{//Retrieve the XSLT from the DIS (generic resource), and create the transformer
|
||||
ByteArrayInputStream xsltStream = new ByteArrayInputStream(xslt.getBytes());
|
||||
TransformerFactory tFactory = TransformerFactory.newInstance();
|
||||
transformer = tFactory.newTransformer(new StreamSource(xsltStream));
|
||||
|
||||
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
|
||||
Document doc = null;
|
||||
|
||||
doc = dfactory.newDocumentBuilder().parse(xml);
|
||||
// Apply the transformation
|
||||
ByteArrayOutputStream ba_stream = new ByteArrayOutputStream();
|
||||
OutputFormat format = new OutputFormat(doc);
|
||||
format.setIndenting(false);
|
||||
format.setOmitDocumentType(true);
|
||||
format.setOmitXMLDeclaration(true);
|
||||
StringWriter writer = new StringWriter();
|
||||
XMLSerializer serial = new XMLSerializer(writer,format);
|
||||
serial.serialize(doc);
|
||||
transformer.transform(new StreamSource(new ByteArrayInputStream(writer.toString().getBytes())), new StreamResult(ba_stream));
|
||||
//Prepares the object to be returned
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
try {
|
||||
InputStreamReader isr = new InputStreamReader( new ByteArrayInputStream(ba_stream.toByteArray()),
|
||||
"UTF8");
|
||||
Reader in2 = new BufferedReader(isr);
|
||||
int ch;
|
||||
while ((ch = in2.read()) > -1) {
|
||||
buffer.append((char)ch);
|
||||
}
|
||||
in2.close();
|
||||
return buffer.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Transforms an xml document based on the given transformer
|
||||
* @param transformer the transformer based on which the transformation will be applied
|
||||
* @param xml the xml document to be transformed
|
||||
* @return a string containing the transformed xml (output of the transformation)
|
||||
*/
|
||||
public static String transform(Transformer transformer, String xml)
|
||||
{
|
||||
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
|
||||
Document doc = null;
|
||||
|
||||
try
|
||||
{
|
||||
doc = dfactory.newDocumentBuilder().parse(xml);
|
||||
ByteArrayOutputStream ba_stream = new ByteArrayOutputStream();
|
||||
OutputFormat format = new OutputFormat(doc);
|
||||
format.setIndenting(false);
|
||||
format.setOmitDocumentType(true);
|
||||
format.setOmitXMLDeclaration(true);
|
||||
StringWriter writer = new StringWriter();
|
||||
XMLSerializer serial = new XMLSerializer(writer,format);
|
||||
serial.serialize(doc);
|
||||
transformer.transform(new StreamSource(new ByteArrayInputStream(writer.toString().getBytes())), new StreamResult(ba_stream));
|
||||
//Prepares the object to be returned
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
try {
|
||||
InputStreamReader isr = new InputStreamReader( new ByteArrayInputStream(ba_stream.toByteArray()),
|
||||
"UTF8");
|
||||
Reader in2 = new BufferedReader(isr);
|
||||
int ch;
|
||||
while ((ch = in2.read()) > -1) {
|
||||
buffer.append((char)ch);
|
||||
}
|
||||
in2.close();
|
||||
return buffer.toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,73 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.gcube.vomanagement.vomsapi.CredentialsManager;
|
||||
import org.gcube.vomanagement.vomsapi.VOMSAdmin;
|
||||
import org.gcube.vomanagement.vomsapi.impl.VOMSAPIConfiguration;
|
||||
import org.gcube.vomanagement.vomsapi.impl.VOMSAPIFactory;
|
||||
import org.gridforum.jgss.ExtendedGSSCredential;
|
||||
|
||||
/**
|
||||
* @author Valia Tsagkalidou (NKUA)
|
||||
*
|
||||
*/
|
||||
public class UserCredential {
|
||||
/**
|
||||
* Retrieves credential for users
|
||||
* @param username the user name for which it will retrieve credential
|
||||
* @param DLname DLname
|
||||
* @return the GSS Credential
|
||||
*/
|
||||
public static ExtendedGSSCredential getCredential(String username, String DLname)
|
||||
{
|
||||
CredentialsManager man = null;
|
||||
try {
|
||||
String sharedDir = Settings.getInstance().getProperty("sharedDir");
|
||||
System.out.println("file " + sharedDir + "/vomsAPI.properties exists: "+ new File(sharedDir + "/vomsAPI.properties").exists());
|
||||
// man = new CredentialsManagerImpl(sharedDir + "/vomsAPI.properties");
|
||||
|
||||
VOMSAPIFactory factory = new VOMSAPIFactory(new VOMSAPIConfiguration(new File(sharedDir + "/vomsAPI.properties")));
|
||||
VOMSAdmin vomsAdm = factory.getVOMSAdmin();
|
||||
man = factory.getCredentialsManager();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
ExtendedGSSCredential cred = null;
|
||||
try {
|
||||
//TODO: put a real password there...
|
||||
cred = man.getAttributedCredentials(username, "", DLname);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return cred;
|
||||
}
|
||||
|
||||
public static ExtendedGSSCredential getPlainCredential(String username, String password)
|
||||
{
|
||||
CredentialsManager man = null;
|
||||
try {
|
||||
String sharedDir = Settings.getInstance().getProperty("sharedDir");
|
||||
System.out.println("file " + sharedDir + "/vomsAPI.properties exists: "+ new File(sharedDir + "/vomsAPI.properties").exists());
|
||||
// man = new CredentialsManagerImpl(sharedDir + "/vomsAPI.properties");
|
||||
|
||||
VOMSAPIFactory factory = new VOMSAPIFactory(new VOMSAPIConfiguration(new File(sharedDir + "/vomsAPI.properties")));
|
||||
VOMSAdmin vomsAdm = factory.getVOMSAdmin();
|
||||
man = factory.getCredentialsManager();
|
||||
} catch (Exception e1) {
|
||||
e1.printStackTrace();
|
||||
}
|
||||
ExtendedGSSCredential cred = null;
|
||||
try {
|
||||
//TODO: put a real password there...
|
||||
cred = man.getPlainCredentials(username, password);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return cred;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,8 @@
|
|||
package org.gcube.application.framework.core.util;
|
||||
|
||||
public class UsersManagementServiceConstants {
|
||||
|
||||
public static String LiferaySOAPGroupManager = "LiferaySOAPGroupManager";
|
||||
|
||||
public static String LiferaySOAPUserManager = "LiferaySOAPUserManager";
|
||||
}
|
Loading…
Reference in New Issue