001    /**
002     * Copyright (c) 2000-present 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.model.PasswordPolicy;
019    
020    /**
021     * @author Brian Wing Shun Chan
022     */
023    public class ToolkitWrapper implements Toolkit {
024    
025            public ToolkitWrapper(Toolkit toolkit) {
026                    _originalToolkit = toolkit;
027                    _toolkit = toolkit;
028            }
029    
030            @Override
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            @Override
045            public void validate(
046                            long userId, String password1, String password2,
047                            PasswordPolicy passwordPolicy)
048                    throws PortalException {
049    
050                    _toolkit.validate(userId, password1, password2, passwordPolicy);
051            }
052    
053            @Override
054            public void validate(
055                            String password1, String password2, PasswordPolicy passwordPolicy)
056                    throws PortalException {
057    
058                    _toolkit.validate(password1, password2, passwordPolicy);
059            }
060    
061            private final Toolkit _originalToolkit;
062            private Toolkit _toolkit;
063    
064    }