Membership Service Tutorial 2 - Adding Members to a Group
In order to add members to a Membership Group we must first get a proxy to the Membership Service and try to find the resource and get a proxy to it. If you allready have a proxy to the Membership Group then you can skip that part.
private static String MEMBERSHIP_SERVICE_ENDPOINT = "https://hostname:8443/gria-client-mgt/services/MembershipService"; private static String MEMBERSHIP_RESOURCE_ENDPOINT = "https://hostname:8443/gria-client-mgt/services/MembershipGroup"; // Change this to the id of your group private static String MEMBERSHIP_GROUP_ID = "40894e36-15faf09a-0115-fb07f5dd-0008";
As in Membership Service Tutorial 1 we create a state repository and create a proxy to the Membership Group Resource.
StateRepository repository = new MemoryStateRepository(); RemoteMembershipService membershipService = repository.getOrCreateObject(RemoteMembershipService.class, ConversationID.getEPR(MEMBERSHIP_SERVICE_ENDPOINT)); EndpointReferenceType epr = ConversationID.getEPR(MEMBERSHIP_RESOURCE_ENDPOINT+"#"+MEMBERSHIP_GROUP_ID); MembershipGroupConversation group = repository.getOrCreateObject(MembershipGroupConversation.class,epr);
Now we have the group, we define a rule to match the subject we wish to add to the group. We also need to tell the Membership Group what the issuer certificate of the subject is. We define that the subject gets 'member' role on the group and the last parameter 'false' define whether this is a deny rule or not.
We then call 'addPolicyRule' on the Membership Group.
try {
MatchRule rule = new MatchRule("EMAILADDRESS=Email, CN=CommonName, OU=OrganisationUnit, "
+ "O=Organisation, L=Locality, ST=State, C=Country",
membershipService.getServiceProviderIssuer().getX509Certificate(),
"member",false);
group.addPolicyRule(new PolicyRule(rule));
System.out.println("Added Rule to '"+ConversationID.getLabel(group.getEndpointRef())+"' ("+MEMBERSHIP_GROUP_ID+")");
} catch (RemoteException e) {
throw new RuntimeException(e);
}
Full Java code
package workflow;
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.StateRepository;
import uk.ac.soton.itinnovation.grid.client.membership.MembershipGroupConversation;
import uk.ac.soton.itinnovation.grid.client.membership.RemoteMembershipService;
import uk.ac.soton.itinnovation.grid.types.ConversationID;
import uk.ac.soton.itinnovation.grid.types.MatchRule;
import uk.ac.soton.itinnovation.grid.types.PolicyRule;
public class MembershipGroupTutorial2 {
private static String MEMBERSHIP_SERVICE_ENDPOINT
= "https://hostname:8443/gria-client-mgt/services/MembershipService";
private static String MEMBERSHIP_RESOURCE_ENDPOINT
= "https://hostname:8443/gria-client-mgt/services/MembershipGroup";
// Change this to the id of your group
private static String MEMBERSHIP_GROUP_ID
= "40894e36-15faf09a-0115-fb07f5dd-0008";
public static void main(String[] args) {
StateRepository repository = new MemoryStateRepository();
RemoteMembershipService membershipService =
repository.getOrCreateObject(RemoteMembershipService.class,
ConversationID.getEPR(MEMBERSHIP_SERVICE_ENDPOINT));
EndpointReferenceType epr = ConversationID.getEPR(MEMBERSHIP_RESOURCE_ENDPOINT+"#"+MEMBERSHIP_GROUP_ID);
MembershipGroupConversation group = repository.getOrCreateObject(MembershipGroupConversation.class,epr);
try {
MatchRule rule = new MatchRule("EMAILADDRESS=Email, CN=CommonName, OU=OrganisationUnit, " +
"O=Organisation, L=Locality, ST=State, C=Country",
membershipService.getServiceProviderIssuer().getX509Certificate(),
"member",false);
group.addPolicyRule(new PolicyRule(rule));
System.out.println("Added Rule to '"+ConversationID.getLabel(group.getEndpointRef())
+"' ("+MEMBERSHIP_GROUP_ID+")");
} catch (RemoteException e) {
throw new RuntimeException(e);
}
}
}
