How to determine if a userid is a member of a group

Simplest possible example



/* Simple test if an id is a member of a group */


public class MembershipTest {

   private static String baseUrl;

   public MembershipTest(String base) {
       baseUrl = base;

   // do the test
   public boolean isMember(String group, String user) {

      String urltext = baseUrl + "/group/" + group + "/member/" + user;
      try {
         URL url = new URL(urltext);
         HttpsURLConnection gwsConnection = (HttpsURLConnection) url.openConnection();
         int resp = gwsConnection.getResponseCode();
         if (resp==200) return true;
         if (resp==404) return false;
         System.err.println("Got an unexpected return: " + resp);
      } catch (Exception e) {
         System.err.println("got error: " + e);
      return (false);

   /* Set keystore and truststore.
      These are often specified on the java command line or in a config file.
      instead of in the code.  */

   private static void setKeys() {

      String keyStore = "your_keystore.jks";
      String keyStorePW = "your_keystore_password";
      String trustStore = "your_truststore.jks";
      String trustStorePW = "your_truststore_password";

      // Set the security credential properties
      System.setProperty("", keyStore);
      System.setProperty("", "JKS");
      System.setProperty("", keyStorePW);

      System.setProperty("", trustStore);
      System.setProperty("", "JKS");
      System.setProperty("", trustStorePW);

   public static void main (String[] args) throws Exception {
      String gwsUrl = "";
      MembershipTest tester = new MembershipTest(gwsUrl);
      boolean result = tester.isMember("group_to_test", "uwnetid_to_test");
      if (result) System.out.println("is a member");
      else System.out.println("not a member");