0

I have created a custom string converter for spring webflow that trims spaces for every String property

public class StringTrimmerConverter implements Converter {

    public Object convertSourceToTargetClass(final Object object, final Class clazz) throws Exception {
        if ((object != null) && (object.getClass() == getSourceClass()) && (clazz == getTargetClass())) {
            return ((String) object).trim();
        }
        return object;
    }

    public Class<String> getSourceClass() { return String.class; }

    public Class<String> getTargetClass() { return String.class; }
}

It is added in conversion services

public class FlowConversationService extends DefaultConversionService {

    protected void addDefaultConverters() {
        super.addDefaultConverters();
        this.addConverter(new StringTrimmerConverter());
    }
}

Is there a way to disable this converter for password fields only?

I'm using spring webflow 2.3.2.RELEASE and spring 3.2.2.RELEASE.

Marko Vranjkovic
  • 6,481
  • 7
  • 49
  • 68

1 Answers1

1

You can force a specific converter with <binding> configuration.

Alternatively you can store password field in char[]. I had discussions with people which prefer this over String as char array will not get interned.

Pavel Horal
  • 17,782
  • 3
  • 65
  • 89
  • 1
    Thanks, char[] solution works perfectly for me. *[Here](http://stackoverflow.com/questions/8881291/why-is-char-preferred-over-string-for-passwords)* are more reasons why you should prefer char[] to String for password fields. – Marko Vranjkovic Nov 18 '13 at 19:32
  • That is what *"char will not get interned"* meant ;). – Pavel Horal Nov 18 '13 at 20:55