⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setpasswordform.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
/*
 *  SSL-Explorer
 *
 *  Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2 of
 *  the License, or (at your option) any later version.
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
			
package com.sslexplorer.security.forms;

import java.util.regex.Pattern;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.forms.CoreForm;
import com.sslexplorer.security.User;
import com.sslexplorer.security.UserDatabaseException;

public class SetPasswordForm extends CoreForm {

    private static final long serialVersionUID = -4783370317292273239L;
    String newPassword, confirmPassword;
    User user;
    boolean forceChangePasswordAtLogon;

    public void initialize(User user) {
        this.user = user;
    }

    public boolean getForceChangePasswordAtLogon() {
        return forceChangePasswordAtLogon;
    }

    public void setForceChangePasswordAtLogon(boolean forceChangePasswordAtLogon) {
        this.forceChangePasswordAtLogon = forceChangePasswordAtLogon;
    }

    public String getNewPassword() {
        return newPassword;
    }

    public String getConfirmPassword() {
        return confirmPassword;
    }

    public void setNewPassword(String newPassword) {
        this.newPassword = newPassword;
    }

    public void setConfirmPassword(String confirmPassword) {
        this.confirmPassword = confirmPassword;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.struts.action.ActionForm#reset(org.apache.struts.action.ActionMapping,
     *      javax.servlet.http.HttpServletRequest)
     */
    public void reset(ActionMapping mapping, javax.servlet.http.HttpServletRequest request) {
        newPassword = null;
        confirmPassword = null;
        forceChangePasswordAtLogon = false;
    }

    /*
     * (non-Javadoc)
     * 
     * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping,
     *      javax.servlet.http.HttpServletRequest)
     */
    public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) {
        if ("commit".equals(request.getParameter("action"))) {
            ActionErrors errors = new ActionErrors();
            try {
                if (getNewPassword().length() == 0) {
                    errors.add(Globals.ERROR_KEY, new ActionMessage("setPassword.error.noNewPassword"));
                } else if (!getNewPassword().equals(getConfirmPassword())) {
                    errors.add(Globals.ERROR_KEY, new ActionMessage("setPassword.error.newAndConfirmPasswordsDontMatch"));
                } else {
                    // Check that the password matches the current policy, if
                    // not then request a new one
                    try {
                        String pattern = CoreServlet.getServlet().getPropertyDatabase().getProperty(0, null,
                                        "security.password.pattern");
                        Pattern p = Pattern.compile(pattern);
                        if (!p.matcher(newPassword).matches()) {
                            errors.add(Globals.ERROR_KEY, new ActionMessage("setPassword.error.doesNotMatchPolicy"));
                        }
                    } catch (Exception e) {
                        throw new UserDatabaseException("Could not check password against current policy.", e);
                    }
                }
            } catch (Exception e) {
                errors.add(Globals.ERROR_KEY, new ActionMessage("setPassword.error.validateFailed", e.getMessage()));
            }
            return errors;
        }
        return null;
    }

    /**
     * @return
     */
    public User getUser() {
        return user;
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -