code: public static String toGlobusID(X500Principal principal) {
  
          if (principal == null) {
              return null;
          }
  
          String dn = principal.getName(X500Principal.RFC2253, OID_MAP);
  
          StringBuilder buf = new StringBuilder();
  
          final int IDLE = 0;
          final int VALUE = 1;
          final int KEY = 2;
  
          int state = IDLE;
  
          int cEnd = 0;
          char[] asChars = dn.toCharArray();
          /*
           * walk in reverse order and merge RDN
           */
          for (int i = asChars.length - 1; i >= 0; i--) {
  
              char c = asChars[i];
              switch (state) {
                  case KEY:
                      if (c == ',') {
                          String s = dn.substring(i + 1, cEnd + 1);
                          buf.append('/').append(s);
                          state = IDLE;
                      }
                      break;
                  case VALUE:
                      if (c == '=') {
                          state = KEY;
                      }
                      break;
                  case IDLE:
                  default:
                      cEnd = i;
                      state = VALUE;
              }
          }
  
          String s = dn.substring(0, cEnd + 1);
          buf.append('/').append(s);
  
          // remove comma escaping as some other components may use string comparison.
          return buf.toString().replace("\\,", ",");
      }
docs: Converts DN of the form "CN=A, OU=B, O=C" into Globus format
  "/O=C/OU=B/CN=A" <BR> This function might return incorrect
  Globus-formatted ID when one of the RDNs in the DN contains commas.
  
  @return the converted DN in Globus format.