CertificateLocalizationService extends AbstractService implements CertificateLocalization, CertificateLocalizationMBean { @Override public void removeX509Material(String username) throws InterruptedException { removeX509Material(username, null); } CertificateLocalizationService(ServiceType service); char[] readSupersuperPassword(); @Override String getSuperKeystoreLocation(); @Override String getSuperKeystorePass(); @Override String getSuperKeyPassword(); @Override String getSuperTruststoreLocation(); @Override String getSuperTruststorePass(); @Override String getSuperMaterialPasswordFile(); @VisibleForTesting Path getMaterializeDirectory(); @Override void materializeCertificates(String username, String user,
      ByteBuffer keyStore, String keyStorePassword,
      ByteBuffer trustStore, String trustStorePassword); @Override void materializeCertificates(String username, String applicationId, String user,
      ByteBuffer keyStore, String keyStorePassword,
      ByteBuffer trustStore, String trustStorePassword); @Override void updateX509(String username, String applicationId, ByteBuffer keyStore,
      String keyStorePassword, ByteBuffer trustStore, String trustStorePassword); @Override void updateJWT(String username, String applicationId, String jwt); @Override void materializeJWT(String username, String applicationId, String userFolder, String jwt); @Override void removeX509Material(String username); @Override void removeX509Material(String username, String applicationId); @Override void removeJWTMaterial(String username, String applicationId); @Override X509SecurityMaterial getX509MaterialLocation(String username); @Override X509SecurityMaterial getX509MaterialLocation(String username, String applicationId); @Override JWTSecurityMaterial getJWTMaterialLocation(String username, String applicationId); @Override String getState(); @Override boolean forceRemoveMaterial(String username); @Override boolean forceRemoveMaterial(String username, String applicationId); static final String JMX_MATERIALIZED_KEY; static final String JMX_FORCE_REMOVE_OP; }
@Test public void testMaterialization() throws Exception { byte[] randomK = "Some_random_keystore_stuff".getBytes(); byte[] randomT = "Some_random_truststore_stuff".getBytes(); ByteBuffer bfk = ByteBuffer.wrap(randomK); ByteBuffer bft = ByteBuffer.wrap(randomT); String username = "Dr.Who"; String userFolder = "userfolder"; String keyStorePass = "keyStorePass"; String trustStorePass = "trustStorePass"; materializeCertificateUtil(certLocSrv, username, userFolder, bfk, keyStorePass, bft, trustStorePass); verifyMaterialExistOrNot(certLocSrv, username, userFolder, keyStorePass, trustStorePass, true); certLocSrv.removeX509Material(username); TimeUnit.MILLISECONDS.sleep(10); verifyMaterialExistOrNot(certLocSrv, username, userFolder, keyStorePass, trustStorePass, false); }
@Test public void testMaterializationRemoval() throws Exception { ByteBuffer store = ByteBuffer.wrap("some_bytes".getBytes()); String username = "Dolores"; String userFolder = "userFolder"; String password = "password"; materializeCertificateUtil(certLocSrv, username, userFolder, store, password, store, password); certLocSrv.removeX509Material(username); verifyMaterialExistOrNot(certLocSrv, username, userFolder, password, password, false); }
@Test public void testMXBeanState() throws Exception { MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); ObjectName mxbean = new ObjectName("Hadoop:service=" + service.toString() +",name=CertificateLocalizer"); ObjectMapper objectMapper = new ObjectMapper(); String jmxReturn = (String) mbs.getAttribute(mxbean, "State"); Map<String, String> returnMap = parseCertificateLocalizerState(jmxReturn, objectMapper); assertTrue("Return Map should contain key " + CertificateLocalizationService.JMX_MATERIALIZED_KEY, returnMap.containsKey(CertificateLocalizationService.JMX_MATERIALIZED_KEY)); Map<String, Integer> materializedMap = getMaterializedStateOutOfString(returnMap, objectMapper); assertTrue(materializedMap.isEmpty()); byte[] someBytes = "some_bytes".getBytes(); ByteBuffer keyStore = ByteBuffer.wrap(someBytes); ByteBuffer trustStore = ByteBuffer.wrap(someBytes); String userA = "userA"; String userFolderA = "userFolderA"; String userAStateKey = userA + "/unknown/" + CertificateLocalizationService.STORAGE_KEY_TYPE.X509; materializeCertificateUtil(certLocSrv, userA, userFolderA, keyStore, "some_pass", trustStore, "some_pass"); TimeUnit.MILLISECONDS.sleep(300); jmxReturn = (String) mbs.getAttribute(mxbean, "State"); returnMap = parseCertificateLocalizerState(jmxReturn, objectMapper); materializedMap = getMaterializedStateOutOfString(returnMap, objectMapper); assertEquals(1, materializedMap.size()); assertTrue(materializedMap.containsKey(userAStateKey)); assertEquals(1, materializedMap.get(userAStateKey).intValue()); materializeCertificateUtil(certLocSrv, userA, userFolderA, keyStore, "some_pass", trustStore, "some_pass"); jmxReturn = (String) mbs.getAttribute(mxbean, "State"); returnMap = parseCertificateLocalizerState(jmxReturn, objectMapper); materializedMap = getMaterializedStateOutOfString(returnMap, objectMapper); assertEquals(2, materializedMap.get(userAStateKey).intValue()); String userB = "userB"; String userFolderB = "userFolderB"; String userBStateKey = userB + "/unknown/" + CertificateLocalizationService.STORAGE_KEY_TYPE.X509; materializeCertificateUtil(certLocSrv, userB, userFolderB, keyStore, "some_pass", trustStore, "some_pass"); TimeUnit.MILLISECONDS.sleep(300); jmxReturn = (String) mbs.getAttribute(mxbean, "State"); returnMap = parseCertificateLocalizerState(jmxReturn, objectMapper); materializedMap = getMaterializedStateOutOfString(returnMap, objectMapper); assertEquals(2, materializedMap.size()); assertTrue(materializedMap.containsKey(userAStateKey)); assertTrue(materializedMap.containsKey(userBStateKey)); assertEquals(2, materializedMap.get(userAStateKey).intValue()); assertEquals(1, materializedMap.get(userBStateKey).intValue()); certLocSrv.removeX509Material(userA); certLocSrv.removeX509Material(userA); TimeUnit.MILLISECONDS.sleep(300); jmxReturn = (String) mbs.getAttribute(mxbean, "State"); returnMap = parseCertificateLocalizerState(jmxReturn, objectMapper); materializedMap = getMaterializedStateOutOfString(returnMap, objectMapper); assertEquals(1, materializedMap.size()); assertFalse(materializedMap.containsKey(userAStateKey)); assertTrue(materializedMap.containsKey(userBStateKey)); assertEquals(1, materializedMap.get(userBStateKey).intValue()); certLocSrv.removeX509Material(userB); TimeUnit.MILLISECONDS.sleep(300); jmxReturn = (String) mbs.getAttribute(mxbean, "State"); returnMap = parseCertificateLocalizerState(jmxReturn, objectMapper); materializedMap = getMaterializedStateOutOfString(returnMap, objectMapper); assertTrue(materializedMap.isEmpty()); }