SpringSecurityPasswordValidationCallbackHandler extends AbstractWsPasswordCallbackHandler implements InitializingBean { protected void handleUsernameToken(WSPasswordCallback callback) throws IOException, UnsupportedCallbackException { UserDetails user = loadUserDetails(callback.getIdentifier()); if (user != null) { SpringSecurityUtils.checkUserValidity(user); callback.setPassword(user.getPassword()); } }  void setUserCache(UserCache userCache); void setUserDetailsService(UserDetailsService userDetailsService); @Override void afterPropertiesSet();  }
@Test public void testHandleUsernameToken() throws Exception { UserDetailsService userDetailsService = createMock(UserDetailsService.class); callbackHandler.setUserDetailsService(userDetailsService); expect(userDetailsService.loadUserByUsername("Ernie")).andReturn(user).anyTimes(); replay(userDetailsService); callbackHandler.handleUsernameToken(passwordCallback); Assert.assertEquals("Bert", passwordCallback.getPassword()); verify(userDetailsService); }