2 * Copyright (C) 2021 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.cdm
.vaadin
.data
.validator
;
11 import java
.util
.List
;
12 import java
.util
.stream
.Collectors
;
14 import com
.vaadin
.data
.Validator
;
15 import com
.vaadin
.ui
.PasswordField
;
17 import eu
.etaxonomy
.cdm
.validation
.constraint
.ValidPasswordValidator
;
18 import eu
.etaxonomy
.cdm
.validation
.constraint
.ValidPasswordValidator
.PasswordRulesValidator
;
21 * Checks that the passwords entered in two password fields match.
22 * Intended to be added as validator to the second field of the
23 * {@link PasswordField} pair.
25 * @author a.kohlbecker
28 public class PasswordsPolicyValidator
implements Validator
{
30 private static final long serialVersionUID
= -9048318480638222817L;
32 private PasswordRulesValidator validator
= new ValidPasswordValidator
.PasswordRulesValidator();
35 public void validate(Object value
) throws InvalidValueException
{
36 String password
= (String
)value
;
37 if(password
!= null && !password
.isEmpty()) {
38 List
<String
> violationMessages
= validator
.validateUserPassword(password
);
39 if(!violationMessages
.isEmpty()) {
40 throw new InvalidValueException(violationMessages
.stream().collect(Collectors
.joining(" ")));