X509RoleCertRequest extends X509CertRequest { public Map<String, String[]> getRequestedRoleList() { if (uris == null || uris.isEmpty()) { return null; } Map<String, List<String>> domainRoles = new HashMap<>(); for (String uri : uris) { if (!uri.toLowerCase().startsWith(ZTSConsts.ZTS_CERT_ROLE_URI)) { continue; } final String roleUri = uri.substring(ZTSConsts.ZTS_CERT_ROLE_URI.length()); int idx = roleUri.indexOf('/'); if (idx == -1) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("Invalid role name '{}' in CSR", uri); } return null; } final String domainName = roleUri.substring(0, idx); List<String> rolesForDomain = domainRoles.get(domainName); if (rolesForDomain == null) { rolesForDomain = new ArrayList<>(); domainRoles.put(domainName, rolesForDomain); } rolesForDomain.add(roleUri.substring(idx + 1)); } if (domainRoles.isEmpty()) { return null; } Map<String, String[]> roles = new HashMap<>(); for (String domainName : domainRoles.keySet()) { roles.put(domainName, domainRoles.get(domainName).toArray(new String[0])); } return roles; } X509RoleCertRequest(String csr); Map<String, String[]> getRequestedRoleList(); boolean validate(Set<String> roles, final String domainName, final String principal,
            final String proxyUser, Set<String> validCertSubjectOrgValues); boolean validate(final String principal, final String proxyUser,
            Set<String> validCertSubjectOrgValues); boolean validateIPAddress(X509Certificate cert, final String ip);  }
@Test public void testGetRequestedRoleListNoURI() throws IOException { Path path = Paths.get("src/test/resources/role_multiple_ip.csr"); String csr = new String(Files.readAllBytes(path)); X509RoleCertRequest certReq = new X509RoleCertRequest(csr); assertNull(certReq.getRequestedRoleList()); }
@Test public void testGetRequestedRoleListNoRolesURI() throws IOException { Path path = Paths.get("src/test/resources/spiffe_role.csr"); String csr = new String(Files.readAllBytes(path)); X509RoleCertRequest certReq = new X509RoleCertRequest(csr); assertNull(certReq.getRequestedRoleList()); }
@Test public void testGetRequestedRoleListInvalidRole() throws IOException { Path path = Paths.get("src/test/resources/athenz_role_uri_invalid.csr"); String csr = new String(Files.readAllBytes(path)); X509RoleCertRequest certReq = new X509RoleCertRequest(csr); assertNull(certReq.getRequestedRoleList()); }
@Test public void testGetRequestedRoleList() throws IOException { Path path = Paths.get("src/test/resources/athenz_role_uri.csr"); String csr = new String(Files.readAllBytes(path)); X509RoleCertRequest certReq = new X509RoleCertRequest(csr); Map<String, String[]> roles = certReq.getRequestedRoleList(); assertEquals(roles.size(), 2); String[] list1 = roles.get("sports"); assertEquals(list1.length, 1); assertEquals(list1[0], "readers"); String[] list2 = roles.get("weather"); assertEquals(list2.length, 2); assertEquals(list2[0], "readers"); assertEquals(list2[1], "writers"); }