AthenzUtils { public static boolean isRoleCertificate(X509Certificate x509Cert) { final String principal = Crypto.extractX509CertCommonName(x509Cert); if (principal == null) { return false; } return principal.contains(AuthorityConsts.ROLE_SEP); } 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 testIsRoleCertificateServiceCertificate() throws Exception { try (InputStream inStream = new FileInputStream("src/test/resources/x509_altnames_singleip.cert")) { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(inStream); assertFalse(AthenzUtils.isRoleCertificate(cert)); } }
@Test public void testIsRoleCertificateRoleCertificate() throws Exception { try (InputStream inStream = new FileInputStream("src/test/resources/valid_email_x509.cert")) { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(inStream); assertTrue(AthenzUtils.isRoleCertificate(cert)); } }
@Test public void testIsRoleCertificateNoCn() throws Exception { try (InputStream inStream = new FileInputStream("src/test/resources/no_cn_x509.cert")) { CertificateFactory cf = CertificateFactory.getInstance("X.509"); X509Certificate cert = (X509Certificate) cf.generateCertificate(inStream); assertFalse(AthenzUtils.isRoleCertificate(cert)); } }