@Test public void testToPrincipalWithEmptyString() { X500Principal principal = CertificateUtil.toPrincipal(""); assertThat(principal, is(new X500Principal(""))); }
public static X500Principal toPrincipal(String globusID) { if (globusID == null) { return null; } String id = globusID.trim(); StringBuilder buf = new StringBuilder(id.length()); if (!id.isEmpty()) { final int IDLE = 0; final int VALUE = 1; final int KEY = 2; int state = IDLE; int cEnd = 0; char[] asChars = id.toCharArray(); for (int i = asChars.length - 1; i >= 0; i--) { char c = asChars[i]; switch (state) { case KEY: if (c == '/' || c == ' ') { String s = id.substring(i + 1, cEnd + 1); int commaIndex = s.indexOf(','); if (commaIndex != -1) { s = s.substring(0, commaIndex) + "\\" + s.substring(commaIndex); } buf.append(s).append(','); state = IDLE; } break; case VALUE: if (c == '=') { state = KEY; } break; case IDLE: default: if (c == '/' || c == ' ') { continue; } else { cEnd = i; state = VALUE; } } } buf.deleteCharAt(buf.length() - 1); } String dn = buf.toString(); return new X500Principal(dn, KEYWORD_MAP); }
CertificateUtil { public static X500Principal toPrincipal(String globusID) { if (globusID == null) { return null; } String id = globusID.trim(); StringBuilder buf = new StringBuilder(id.length()); if (!id.isEmpty()) { final int IDLE = 0; final int VALUE = 1; final int KEY = 2; int state = IDLE; int cEnd = 0; char[] asChars = id.toCharArray(); for (int i = asChars.length - 1; i >= 0; i--) { char c = asChars[i]; switch (state) { case KEY: if (c == '/' || c == ' ') { String s = id.substring(i + 1, cEnd + 1); int commaIndex = s.indexOf(','); if (commaIndex != -1) { s = s.substring(0, commaIndex) + "\\" + s.substring(commaIndex); } buf.append(s).append(','); state = IDLE; } break; case VALUE: if (c == '=') { state = KEY; } break; case IDLE: default: if (c == '/' || c == ' ') { continue; } else { cEnd = i; state = VALUE; } } } buf.deleteCharAt(buf.length() - 1); } String dn = buf.toString(); return new X500Principal(dn, KEYWORD_MAP); } }
CertificateUtil { public static X500Principal toPrincipal(String globusID) { if (globusID == null) { return null; } String id = globusID.trim(); StringBuilder buf = new StringBuilder(id.length()); if (!id.isEmpty()) { final int IDLE = 0; final int VALUE = 1; final int KEY = 2; int state = IDLE; int cEnd = 0; char[] asChars = id.toCharArray(); for (int i = asChars.length - 1; i >= 0; i--) { char c = asChars[i]; switch (state) { case KEY: if (c == '/' || c == ' ') { String s = id.substring(i + 1, cEnd + 1); int commaIndex = s.indexOf(','); if (commaIndex != -1) { s = s.substring(0, commaIndex) + "\\" + s.substring(commaIndex); } buf.append(s).append(','); state = IDLE; } break; case VALUE: if (c == '=') { state = KEY; } break; case IDLE: default: if (c == '/' || c == ' ') { continue; } else { cEnd = i; state = VALUE; } } } buf.deleteCharAt(buf.length() - 1); } String dn = buf.toString(); return new X500Principal(dn, KEYWORD_MAP); } private  CertificateUtil(); }
CertificateUtil { public static X500Principal toPrincipal(String globusID) { if (globusID == null) { return null; } String id = globusID.trim(); StringBuilder buf = new StringBuilder(id.length()); if (!id.isEmpty()) { final int IDLE = 0; final int VALUE = 1; final int KEY = 2; int state = IDLE; int cEnd = 0; char[] asChars = id.toCharArray(); for (int i = asChars.length - 1; i >= 0; i--) { char c = asChars[i]; switch (state) { case KEY: if (c == '/' || c == ' ') { String s = id.substring(i + 1, cEnd + 1); int commaIndex = s.indexOf(','); if (commaIndex != -1) { s = s.substring(0, commaIndex) + "\\" + s.substring(commaIndex); } buf.append(s).append(','); state = IDLE; } break; case VALUE: if (c == '=') { state = KEY; } break; case IDLE: default: if (c == '/' || c == ' ') { continue; } else { cEnd = i; state = VALUE; } } } buf.deleteCharAt(buf.length() - 1); } String dn = buf.toString(); return new X500Principal(dn, KEYWORD_MAP); } private  CertificateUtil(); static void init(); static void setProvider(String providerName); static void installSecureRandomProvider(); static int getCAPathConstraint(TBSCertificateStructure crt); static KeyPair generateKeyPair(String algorithm, int bits); static GSIConstants.CertificateType getCertificateType(
            TBSCertificateStructure crt); static BasicConstraints getBasicConstraints(X509Extension ext); static ASN1Primitive toASN1Primitive(byte[] data); static TBSCertificateStructure getTBSCertificateStructure(
            X509Certificate cert); static EnumSet<KeyUsage> getKeyUsage(TBSCertificateStructure crt); static EnumSet<KeyUsage> getKeyUsage(X509Extension ext); static ASN1Primitive getExtensionObject(X509Extension ext); static String toGlobusID(String dn); static String toGlobusID(String dn, boolean noreverse); static String toGlobusID(Principal name); static String toGlobusID(X500Principal principal); static X500Principal toPrincipal(String globusID); static CertPath getCertPath(X509Certificate[] certs); }
CertificateUtil { public static X500Principal toPrincipal(String globusID) { if (globusID == null) { return null; } String id = globusID.trim(); StringBuilder buf = new StringBuilder(id.length()); if (!id.isEmpty()) { final int IDLE = 0; final int VALUE = 1; final int KEY = 2; int state = IDLE; int cEnd = 0; char[] asChars = id.toCharArray(); for (int i = asChars.length - 1; i >= 0; i--) { char c = asChars[i]; switch (state) { case KEY: if (c == '/' || c == ' ') { String s = id.substring(i + 1, cEnd + 1); int commaIndex = s.indexOf(','); if (commaIndex != -1) { s = s.substring(0, commaIndex) + "\\" + s.substring(commaIndex); } buf.append(s).append(','); state = IDLE; } break; case VALUE: if (c == '=') { state = KEY; } break; case IDLE: default: if (c == '/' || c == ' ') { continue; } else { cEnd = i; state = VALUE; } } } buf.deleteCharAt(buf.length() - 1); } String dn = buf.toString(); return new X500Principal(dn, KEYWORD_MAP); } private  CertificateUtil(); static void init(); static void setProvider(String providerName); static void installSecureRandomProvider(); static int getCAPathConstraint(TBSCertificateStructure crt); static KeyPair generateKeyPair(String algorithm, int bits); static GSIConstants.CertificateType getCertificateType(
            TBSCertificateStructure crt); static BasicConstraints getBasicConstraints(X509Extension ext); static ASN1Primitive toASN1Primitive(byte[] data); static TBSCertificateStructure getTBSCertificateStructure(
            X509Certificate cert); static EnumSet<KeyUsage> getKeyUsage(TBSCertificateStructure crt); static EnumSet<KeyUsage> getKeyUsage(X509Extension ext); static ASN1Primitive getExtensionObject(X509Extension ext); static String toGlobusID(String dn); static String toGlobusID(String dn, boolean noreverse); static String toGlobusID(Principal name); static String toGlobusID(X500Principal principal); static X500Principal toPrincipal(String globusID); static CertPath getCertPath(X509Certificate[] certs);  }