CXFPasswordCallbackHandler implements CallbackHandler { @Override public final void handle(final Callback[] callbacks) throws IOException, UnsupportedCallbackException { LOG.trace("Executing CXFPasswordCallbackHandler.handle() ... "); if (keystorePassword == null || keystorePassword.isEmpty()) { throw new IOException("keystore password was not provided. Please provide the system property: " + SYSTEM_PROPERTY_KEYSTORE_PASSWORD); } for (Callback callback : callbacks) { if (callback instanceof WSPasswordCallback) { WSPasswordCallback pc = (WSPasswordCallback) callback; pc.setPassword(keystorePassword); } } LOG.trace("end CXFPasswordCallbackHandler.handle() ... "); } CXFPasswordCallbackHandler();  CXFPasswordCallbackHandler(String keystorePassword); @Override final void handle(final Callback[] callbacks);  }
@Test public void testHandle() throws IOException, UnsupportedCallbackException { WSPasswordCallback wsPasswordCallback = new WSPasswordCallback(null, 0); Callback[] callbacks = new Callback[1]; callbacks[0] = wsPasswordCallback; String password = "password"; CXFPasswordCallbackHandler passwordHandler = new CXFPasswordCallbackHandler(password); passwordHandler.handle(callbacks); wsPasswordCallback = (WSPasswordCallback) callbacks[0]; String resultPassword = wsPasswordCallback.getPassword(); assertEquals(password, resultPassword); }
@Test(expected = IOException.class) public void testHandle_IOException() throws IOException, UnsupportedCallbackException { WSPasswordCallback wsPasswordCallback = new WSPasswordCallback(null, 0); Callback[] callbacks = new Callback[1]; callbacks[0] = wsPasswordCallback; String password = ""; CXFPasswordCallbackHandler passwordHandler = new CXFPasswordCallbackHandler(password); passwordHandler.handle(callbacks); }