Rena Tsantouli 2009-04-10 14:31:03 +00:00
parent 4660327219
commit d988669b89
1 changed files with 0 additions and 206 deletions

View File

@ -1,206 +0,0 @@
package org.gcube.application.framework.core.commons;
import java.rmi.RemoteException;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.axis.message.addressing.Address;
import org.apache.axis.message.addressing.EndpointReference;
import org.apache.axis.message.addressing.EndpointReferenceType;
import org.gcube.application.framework.core.cache.RIsManager;
import org.gcube.application.framework.core.security.ServiceContextManager;
import org.gcube.common.core.faults.GCUBEFault;
import org.gcube.common.core.scope.GCUBEScope;
import org.gcube.informationsystem.cache.SrvType;
import org.gcube.personalization.profileadministration.stubs.ProfileAdministrationPortType;
import org.gcube.personalization.profileadministration.stubs.service.ProfileAdministrationServiceAddressingLocator;
import org.gcube.personalization.userprofileaccess.stubs.UserProfileAccessFactoryPortType;
import org.gcube.personalization.userprofileaccess.stubs.UserProfileAccessPortType;
import org.gcube.personalization.userprofileaccess.stubs.service.UserProfileAccessFactoryServiceAddressingLocator;
import org.gcube.personalization.userprofileaccess.stubs.service.UserProfileAccessServiceAddressingLocator;
import org.gridforum.jgss.ExtendedGSSCredential;
import org.ietf.jgss.GSSCredential;
/**
* @author Valia Tsagkalidou (NKUA)
*
*/
public class ProfileService {
protected static AtomicInteger profileId = new AtomicInteger(0);
protected String username;
protected GCUBEScope scope;
/**
* The constructor
* @param username the user for each it will get the profile (Resource)
* @param scope the scope of the active VRE
*/
public ProfileService( String username, GCUBEScope scope) {
super();
this.username = username;
this.scope = scope;
}
/**
* @return UserProfileAccessFactoryPortType
*/
public UserProfileAccessFactoryPortType getUserProfileAccessFactory()
{
EndpointReference[] profileURIs;
try {
profileURIs = RIsManager.getInstance().getISCache(scope).getEPRsFor("Personalisation", "UserProfileAccess", SrvType.FACTORY.name()); //.getEndPointForPersonalizationUPAFactoryService();
} catch (Exception e1) {
e1.printStackTrace();
return null;
}
System.out.println("getUserProfileAccessFactory: " + profileURIs.length);
EndpointReferenceType serviceEPR = new EndpointReferenceType();
UserProfileAccessFactoryPortType upa = null;
try
{
serviceEPR.setAddress(new Address(profileURIs[profileId.getAndIncrement()%profileURIs.length].getAddress().toString()));
UserProfileAccessFactoryServiceAddressingLocator upalocator = new UserProfileAccessFactoryServiceAddressingLocator();
upa = upalocator.getUserProfileAccessFactoryPortTypePort(serviceEPR);
return upa;
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
/**
* @param cred the X509 credential
* @return UserProfileAccessPortType
*/
public UserProfileAccessPortType getUserProfileAccess(ExtendedGSSCredential cred)
{
UserProfileAccessFactoryPortType upa = getUserProfileAccessFactory();
try {
upa = (UserProfileAccessFactoryPortType) ServiceContextManager.applySecurity(upa, scope, cred);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
EndpointReferenceType epr = null;
try {
System.out.println("\n\n\n\n" + username + " scope= " + scope + "\n\n\n\n");
epr = upa.createResource(username);
} catch (GCUBEFault e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
if(epr != null)
{
try {
return getUserProfileAccessServicePortType(epr, scope, cred);
} catch (RemoteException e) {
e.printStackTrace();
}
}
return null;
}
/**
* @param upa UserProfileAccessFactoryPortType
* @param cred an X509 credential
* @return UserProfileAccessPortType
*/
public UserProfileAccessPortType getUserProfileAccess(UserProfileAccessFactoryPortType upa, ExtendedGSSCredential cred)
{
try {
upa = (UserProfileAccessFactoryPortType) ServiceContextManager.applySecurity(upa, scope, cred);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
EndpointReferenceType epr = null;
try {
epr = upa.createResource(username);
} catch (GCUBEFault e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
if(epr != null)
{
try {
return getUserProfileAccessServicePortType(epr, scope, cred);
} catch (RemoteException e) {
e.printStackTrace();
}
}
return null;
}
/**
* This method returns the port type of the service User Profile Access.
*
* @param epr the endpoint reference of a WS resource of this service
* @param scope the gCube scope
* @param cred a X509 credential
* @return port for UserProfileAccess service
* @throws RemoteException an exception
*/
private UserProfileAccessPortType getUserProfileAccessServicePortType(EndpointReferenceType epr,GCUBEScope scope, GSSCredential cred) throws RemoteException {
UserProfileAccessServiceAddressingLocator instanceLocator = new UserProfileAccessServiceAddressingLocator();
UserProfileAccessPortType port = null;
try {
port = instanceLocator.getUserProfileAccessPortTypePort(epr);
try {
port = (UserProfileAccessPortType) ServiceContextManager.applySecurity(port, scope, cred);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (Exception e) {
throw new RemoteException("A service exception was thrown. Failed to get the port type of the service user profile access");
}
return port;
}
/**
* @param cred the X509 credential
* @return a port type for profile admin service
*/
public ProfileAdministrationPortType getProfileAdministration(GSSCredential cred)
{
EndpointReference[] profileURIs;
try {
profileURIs = RIsManager.getInstance().getISCache(scope).getEPRsFor("Personalisation", "ProfileAdministration", SrvType.SIMPLE.name()); //.getEndPointForPersonalizationPAService();
} catch (Exception e1) {
e1.printStackTrace();
return null;
}
EndpointReferenceType serviceEPR = new EndpointReferenceType();
ProfileAdministrationPortType pa = null;
System.out.println("profile administration services: " + profileURIs.length);
try
{
serviceEPR.setAddress(new Address(profileURIs[profileId.getAndIncrement()%profileURIs.length].getAddress().toString()));
ProfileAdministrationServiceAddressingLocator palocator = new ProfileAdministrationServiceAddressingLocator();
pa = palocator.getProfileAdministrationPortTypePort(serviceEPR);
pa = (ProfileAdministrationPortType) ServiceContextManager.applySecurity(pa, scope, cred);
return pa;
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
}