001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.security.pwd;
016    
017    import com.liferay.portal.kernel.exception.PortalException;
018    import com.liferay.portal.kernel.exception.SystemException;
019    import com.liferay.portal.model.PasswordPolicy;
020    
021    /**
022     * @author Brian Wing Shun Chan
023     */
024    public class ToolkitWrapper implements Toolkit {
025    
026            public ToolkitWrapper(Toolkit toolkit) {
027                    _originalToolkit = toolkit;
028                    _toolkit = toolkit;
029            }
030    
031            @Override
032            public String generate(PasswordPolicy passwordPolicy) {
033                    return _toolkit.generate(passwordPolicy);
034            }
035    
036            public void setToolkit(Toolkit toolkit) {
037                    if (toolkit == null) {
038                            _toolkit = _originalToolkit;
039                    }
040                    else {
041                            _toolkit = toolkit;
042                    }
043            }
044    
045            @Override
046            public void validate(
047                            long userId, String password1, String password2,
048                            PasswordPolicy passwordPolicy)
049                    throws PortalException, SystemException {
050    
051                    _toolkit.validate(userId, password1, password2, passwordPolicy);
052            }
053    
054            @Override
055            public void validate(
056                            String password1, String password2, PasswordPolicy passwordPolicy)
057                    throws PortalException, SystemException {
058    
059                    _toolkit.validate(password1, password2, passwordPolicy);
060            }
061    
062            private Toolkit _originalToolkit;
063            private Toolkit _toolkit;
064    
065    }