AthenzUtils { public static String extractRoleDomainName(final String roleName) { int idx = roleName.indexOf(AuthorityConsts.ROLE_SEP); if (idx == -1 || idx == 0 || idx == roleName.length() - AuthorityConsts.ROLE_SEP.length()) { return null; } else { return roleName.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 testExtractRoleDomainName() { assertEquals(AthenzUtils.extractRoleDomainName("athenz:role.readers"), "athenz"); assertEquals(AthenzUtils.extractRoleDomainName("athenz.api:role.readers"), "athenz.api"); assertEquals(AthenzUtils.extractRoleDomainName("athenz.api.test:role.readers"), "athenz.api.test"); assertNull(AthenzUtils.extractRoleDomainName("athenz.role.readers")); assertNull(AthenzUtils.extractRoleDomainName("athenz:roles.readers")); assertNull(AthenzUtils.extractRoleDomainName("athenz:role.")); assertNull(AthenzUtils.extractRoleDomainName(":role.readers")); assertNull(AthenzUtils.extractRoleDomainName("athenz.readers")); }