Membership Service Tutorial 4 - Using a Group to access a Resource
First we declare the location of the Membership and Data Service, and the resource id's of the Data Stager and the Membership group
private static String MEMBERSHIP_SERVICE_ENDPOINT = "https://hostname:8443/gria-client-mgt/services/MembershipService"; private static String MEMBERSHIP_GROUP_ID = "40894e36-15a43ff0-0115-a445d0c0-0001"; private static String DATA_SERVICE_ENDPOINT = "https://hostname:8443/gria-basic-app-services/services/DataService"; private static String DATA_STAGER_ID = "40894e36-15f08ce0-0115-f0be917c-0009";
We need to setup a token cache which will store tokens from the membership group, and a InvocationListener which will add tokens from the cache to outgoing messages as a header.
private static TokenCache tokenCache = ImplementationFactory.getSingletonInstance(TokenCache.class); UserInputHandler inputHandler = ImplementationFactory.getSingletonInstance(UserInputHandler.class); inputHandler.addInvocationListener(new MembershipInvocationListener(tokenCache));
Find the Membership Group as before
StateRepository repository = new MemoryStateRepository();
RemoteMembershipService membershipService = (RemoteMembershipService)
repository.getOrCreateObject(RemoteMembershipService.class,
ConversationID.getEPR(MEMBERSHIP_SERVICE_ENDPOINT));
MembershipGroupConversation group = null;
try {
EndpointReferenceType eprs[] = membershipService.getResources();
for (EndpointReferenceType epr : eprs){
if(ConversationID.getConversationFromEPR(epr).equals(MEMBERSHIP_GROUP_ID)){
group = repository.getOrCreateObject(MembershipGroupConversation.class,epr);
}
}
if(group==null)
throw new RuntimeException("No Group found with ID:"+MEMBERSHIP_GROUP_ID);
else
System.out.println("Found Group '"+ConversationID.getLabel(group.getEndpointRef())+"'");
} catch (RemoteException e) {
throw new RuntimeException(e);
}
Set the Membership Group as the default group for this session, token will be added to messages from this group.
group.setMembershipGroup();
Now we access the Data Service with the Membership token attached to the message and should have access to the Data Stager.
RemoteDataService dataService = (RemoteDataService)
repository.getOrCreateObject(RemoteDataService.class,
ConversationID.getEPR(DATA_SERVICE_ENDPOINT));
DataConversation data = null;
try {
EndpointReferenceType eprs[] = dataService.getResources();
for (EndpointReferenceType epr : eprs){
if(ConversationID.getConversationFromEPR(epr).equals(DATA_STAGER_ID)){
data = repository.getOrCreateObject(DataConversation.class,epr);
}
}
if(data==null)
throw new RuntimeException("No Data found with ID:"+DATA_STAGER_ID);
else
System.out.println("Found Data '"+ConversationID.getLabel(data.getEndpointRef())+"'");
} catch (RemoteException e) {
throw new RuntimeException(e);
}
Full java Code
import java.rmi.RemoteException;
import org.apache.axis.message.addressing.EndpointReferenceType;
import uk.ac.soton.ecs.iam.grid.client.staterepos.MemoryStateRepository;
import uk.ac.soton.ecs.iam.grid.comms.client.DataConversation;
import uk.ac.soton.ecs.iam.grid.comms.client.RemoteDataService;
import uk.ac.soton.ecs.iam.grid.comms.client.StateRepository;
import uk.ac.soton.ecs.iam.grid.comms.client.helpers.UserInputHandler;
import uk.ac.soton.ecs.iam.grid.utils.ImplementationFactory;
import uk.ac.soton.itinnovation.grid.client.membership.MembershipGroupConversation;
import uk.ac.soton.itinnovation.grid.client.membership.MembershipInvocationListener;
import uk.ac.soton.itinnovation.grid.client.membership.RemoteMembershipService;
import uk.ac.soton.itinnovation.grid.comms.client.TokenCache;
import uk.ac.soton.itinnovation.grid.comms.wstrust.WSTrust;
import uk.ac.soton.itinnovation.grid.types.ConversationID;
public class MembershipGroupTutorial4 {
private static String MEMBERSHIP_SERVICE_ENDPOINT
= "https://hostname:8443/gria-client-mgt/services/MembershipService";
private static String MEMBERSHIP_GROUP_ID
= "40894e36-15a43ff0-0115-a445d0c0-0001";
private static String DATA_SERVICE_ENDPOINT
= "https://hostname:8443/gria-basic-app-services/services/DataService";
private static String DATA_STAGER_ID
= "40894e36-15f08ce0-0115-f0be917c-0009";
private static TokenCache tokenCache = ImplementationFactory.getSingletonInstance(TokenCache.class);
public static void main(String[] args) {
UserInputHandler inputHandler = ImplementationFactory.getSingletonInstance(UserInputHandler.class);
inputHandler.addInvocationListener(new MembershipInvocationListener(tokenCache));
StateRepository repository = new MemoryStateRepository();
RemoteMembershipService membershipService = (RemoteMembershipService)
repository.getOrCreateObject(RemoteMembershipService.class,
ConversationID.getEPR(MEMBERSHIP_SERVICE_ENDPOINT));
MembershipGroupConversation group = null;
try {
EndpointReferenceType eprs[] = membershipService.getResources();
for (EndpointReferenceType epr : eprs){
if(ConversationID.getConversationFromEPR(epr).equals(MEMBERSHIP_GROUP_ID)){
group = repository.getOrCreateObject(MembershipGroupConversation.class,epr);
}
}
if(group==null)
throw new RuntimeException("No Group found with ID:"+MEMBERSHIP_GROUP_ID);
else
System.out.println("Found Group '"+ConversationID.getLabel(group.getEndpointRef())+"'");
} catch (RemoteException e) {
throw new RuntimeException(e);
}
group.setMembershipGroup();
RemoteDataService dataService = (RemoteDataService)
repository.getOrCreateObject(RemoteDataService.class,
ConversationID.getEPR(DATA_SERVICE_ENDPOINT));
DataConversation data = null;
try {
EndpointReferenceType eprs[] = dataService.getResources();
for (EndpointReferenceType epr : eprs){
if(ConversationID.getConversationFromEPR(epr).equals(DATA_STAGER_ID)){
data = repository.getOrCreateObject(DataConversation.class,epr);
}
}
if(data==null)
throw new RuntimeException("No Data found with ID:"+DATA_STAGER_ID);
else
System.out.println("Found Data '"+ConversationID.getLabel(data.getEndpointRef())+"'");
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}
