AthenzUtils { public static String extractPrincipalDomainName(final String principalName) { int idx = principalName.lastIndexOf(AuthorityConsts.ATHENZ_PRINCIPAL_DELIMITER_CHAR); if (idx == -1 || idx == 0 || idx == principalName.length() - 1) { return null; } else { return principalName.substring(0, idx); } } private  AthenzUtils(); static String extractServicePrincipal(X509Certificate x509Cert); static boolean isRoleCertificate(X509Certificate x509Cert); static String extractRoleName(final String roleName); static String extractRoleDomainName(final String roleName); static String extractPrincipalDomainName(final String principalName); static String extractPrincipalServiceName(final String principalName); static String[] splitPrincipalName(String name); static String getPrincipalName(String domain, String service); static List<String> splitCommaSeperatedSystemProperty(String property);  }
@Test public void testExtractPrincipalDomainName() { assertEquals(AthenzUtils.extractPrincipalDomainName("athenz.reader"), "athenz"); assertEquals(AthenzUtils.extractPrincipalDomainName("athenz.api.reader"), "athenz.api"); assertEquals(AthenzUtils.extractPrincipalDomainName("athenz.api.test.reader"), "athenz.api.test"); assertNull(AthenzUtils.extractPrincipalDomainName("athenz")); assertNull(AthenzUtils.extractPrincipalDomainName("athenz.")); assertNull(AthenzUtils.extractPrincipalDomainName(".athenz")); }