001    /**
002     * Copyright (c) 2000-2012 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            public String generate(PasswordPolicy passwordPolicy) {
032                    return _toolkit.generate(passwordPolicy);
033            }
034    
035            public void setToolkit(Toolkit toolkit) {
036                    if (toolkit == null) {
037                            _toolkit = _originalToolkit;
038                    }
039                    else {
040                            _toolkit = toolkit;
041                    }
042            }
043    
044            public void validate(
045                            long userId, String password1, String password2,
046                            PasswordPolicy passwordPolicy)
047                    throws PortalException, SystemException {
048    
049                    _toolkit.validate(userId, password1, password2, passwordPolicy);
050            }
051    
052            public void validate(
053                            String password1, String password2, PasswordPolicy passwordPolicy)
054                    throws PortalException, SystemException {
055    
056                    _toolkit.validate(password1, password2, passwordPolicy);
057            }
058    
059            private Toolkit _originalToolkit;
060            private Toolkit _toolkit;
061    
062    }