class UserGenerator implements CredentialGenerator<UserCredentialValue> {

  @Override
  public UserCredentialValue generateCredential(final GenerationParameters p) {
    final StringGenerationParameters params = (StringGenerationParameters) p;
    String username = params.getUsername();
    if (username == null) {
      username = usernameGenerator.generateCredential().getStringCredential();
    }

    final String password = passwordGenerator.generateCredential(params).getStringCredential();

    return new UserCredentialValue(username, password,
      cryptSaltFactory.generateSalt(password));
  }

  @Autowired public  UserGenerator(
    final UsernameGenerator usernameGenerator,
    final PasswordCredentialGenerator passwordGenerator,
    final CryptSaltFactory cryptSaltFactory
  );

}