tusury / vt-middleware

Automatically exported from code.google.com/p/vt-middleware
0 stars 0 forks source link

vt-password: Some words of error messages are not customizable #232

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
The second parameter of INSUFFICIENT_CHARACTERS error message is an english 
word (digit, uppercase, non-alphanumeric, etc ...), witch doesn't allow us to 
use this feature for translation to other languages.

Original issue reported on code.google.com by pablo.le...@gmail.com on 8 Oct 2014 at 12:36

GoogleCodeExporter commented 8 years ago

Original comment by dfis...@gmail.com on 8 Oct 2014 at 2:16

GoogleCodeExporter commented 8 years ago
Internationalization is something we've looked at in the past, but haven't made 
much progress on.
Currently you have to code your own rule to produce non-english messages.

Original comment by dfis...@gmail.com on 8 Oct 2014 at 2:24

GoogleCodeExporter commented 8 years ago
I have been looking at the code, and I think the easiest way to do this is to 
replace INSUFFICIENT_CHARACTERS by INSUFFICIENT_UPPERCASE, 
INSUFFICIENT_LOWERCASE, INSUFFICIENT_DIGITS and INSUFFICIENT_NON_ALPHANUMERIC, 
by not implementing validate in AbstractCharacterRule but in its descendants. 
This way the second parameter is no longer necessary as is implicit in the 
property.

Original comment by pablo.le...@gmail.com on 8 Oct 2014 at 4:33

GoogleCodeExporter commented 8 years ago
I think other way to get this could be try to obtain values from the properties 
in MessageResolver, using the values as keys. Something like that:

/**
 * Resolves the message for the supplied rule result detail.
 * 
 * @param detail
 *            rule result detail
 * 
 * @return message for the detail error code in properties resource or
 *         detail error code if no message is found.
 */
public String resolve(final RuleResultDetail detail) {
  final String key = detail.getErrorCode();
  final String message = messageProperties.getProperty(key);
  String format;
  if (message != null) {
    Object[] tmpValues = new String[detail.getValues().length];
    for (int i = 0; i < tmpValues.length; i++) {
      final String value = messageProperties.getProperty((String) detail.getValues()[i]);
      if (value == null) {
    tmpValues[i] = detail.getValues()[i];
      } else {
    tmpValues[i] = value;
      }
    }
    format = String.format(message, tmpValues);
  } else {
    if (!detail.getParameters().isEmpty()) {
      format = String.format("%s:%s", key, detail.getParameters());
    } else {
      format = String.format("%s", key);
    }
  }
  return format;
}

Original comment by javi13sa...@gmail.com on 9 Oct 2014 at 9:11

GoogleCodeExporter commented 8 years ago
Issue 201 has been merged into this issue.

Original comment by dfis...@gmail.com on 9 Oct 2014 at 6:45

GoogleCodeExporter commented 8 years ago
I decided to go with the simpler solution of adding a distinct error code for 
each character rule.
See https://github.com/vt-middleware/passay/issues/6

Note that vt-password is in maintenance, and only receiving security patches.

Original comment by dfis...@gmail.com on 9 Oct 2014 at 7:03

GoogleCodeExporter commented 8 years ago
Many thanks for the quick fix!

Can you please deploy this new version to maven central?

Original comment by pablo.le...@gmail.com on 10 Oct 2014 at 12:15

GoogleCodeExporter commented 8 years ago
I expect we'll be pushing version 1.0 of passay before the end of the month.

Original comment by dfis...@gmail.com on 10 Oct 2014 at 2:10