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

📄 userattributedefinitionform.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 javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
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.UserAttributeDefinition;


/**
 * Implementation of a {@link com.sslexplorer.core.forms.CoreForm}
 * that allows an administrator to edit an <i>User Attribute Definition</i>.
 * 
 * @author Brett Smith <a href="mailto:brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.5 $
 * @see com.sslexplorer.security.AuthenticationScheme
 */
public class UserAttributeDefinitionForm extends CoreForm {
    
    final static Log log = LogFactory.getLog(UserAttributeDefinitionForm.class);
    
    // Protected instance variables
    
    protected String name;
    protected String label;
    protected String category;
    protected String description;
    protected String defaultValue;
    protected int visibility;
    protected int sortOrder;
    protected UserAttributeDefinition definition;
    protected boolean confidential;
    
    /**
     * Initialise the form
     * 
     * @param definition definition
     */
    public void initialise(UserAttributeDefinition definition) {
        this.definition = definition;
        this.name = definition.getName();
        this.label = definition.getLabel();
        this.visibility = definition.getVisibility();
        this.defaultValue = definition.getDefaultValue();
        this.sortOrder = definition.getSortOrder();
        this.description = definition.getDescription();
        this.category = definition.getCategoryLabel();
    }

    /**
     * Get the default value
     * 
     * @return default value
     */
    public String getDefaultValue() {
        return defaultValue;
    }

    /**
     * Set the default value
     * 
     * @param defaultValue default value
     */
    public void setDefaultValue(String defaultValue) {
        this.defaultValue = defaultValue;
    }

    /**
     * Get the label
     * 
     * @return label
     */
    public String getLabel() {
        return label;
    }

    /**
     * Set the label
     * 
     * @param label label
     */
    public void setLabel(String label) {
        this.label = label;
    }

    /**
     * Get the description
     * 
     * @return description
     */
    public String getDescription() {
        return description;
    }

    /**
     * Set the description
     * 
     * @param description description
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * Get the category
     * 
     * @return category
     */
    public String getCategory() {
        return category;
    }

    /**
     * Set the category
     * 
     * @param category category
     */
    public void setCategory(String category) {
        this.category = category;
    }

    /**
     * Get the name
     * 
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * Set the name
     * 
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Get the visibility. See {@link UserAttributeDefinitionForm} for
     * the constants to use.
     *  
     * @return visibility
     */
    public int getVisibility() {
        return visibility;
    }

    /**
     * Set the visibility. See {@link UserAttributeDefinitionForm} for
     * the contants to use.
     * 
     * @param visibility visibility
     */
    public void setVisibility(int visibility) {
        this.visibility = visibility;
    }

    /**
     * Get the if this is a <i>Confidential User Attribute</i>
     *  
     * @return confidential
     */
    public boolean getConfidential() {
        return confidential;
    }

    /**
     * Set the if this is a <i>Confidential User Attribute</i>
     *  
     * @param confidential confidential
     */
    public void setConfidential(boolean confidential) {
        this.confidential = confidential;
    }
    
    /**
     * Set the sort order
     * 
     * @param sortOrder sort order
     */
    public void setSortOrder(int sortOrder) {
        this.sortOrder = sortOrder;
    }
    
    /**
     * Get the sort order
     * 
     * @return sort order
     */
    public int getSortOrder() {
        return sortOrder;
    }

    /* (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(isCommiting()) {
            ActionErrors errs = new ActionErrors(); 
            if(getName().trim().equals("")) {
                errs.add(Globals.ERROR_KEY, new ActionMessage("editUserAttributeDefinition.error.noName"));
            }
            else {
                if(!getEditing()) {
                    try {
                        UserAttributeDefinition def = CoreServlet.getServlet().getUserDatabase().getUserAttributeDefinition(getName());
                        if(def != null) {
                            errs.add(Globals.ERROR_KEY, new ActionMessage("editUserAttributeDefinition.error.duplicateName", getName()));                        
                        }
                    }
                    catch(Exception e) {
                        log.error("Failed to test if attribute exists.", e);
                        errs.add(Globals.ERROR_KEY, new ActionMessage("editUserAttributeDefinition.error.duplicateName", getName()));
                    }
                }
                if (!getName().matches("^[a-zA-Z0-9_-]*$")) {
                    errs.add(Globals.ERROR_KEY, new ActionMessage("editUserAttributeDefinition.error.invalidName"));
                }
            }
            return errs;
        }
        return null;
    }

    /**
     * Apply ethe entered values to the user attribute definition being 
     * edited.
     */
    public void applyToDefinition() {
        definition.setDefaultValue(getDefaultValue().trim());
        definition.setLabel(getLabel().trim());
        definition.setSortOrder(getSortOrder());
        definition.setCategoryLabel(getCategory().trim());
        definition.setDescription(getDescription().trim());
        if(!getEditing()) {
            definition.setVisibility(getVisibility());
            definition.setName(getName().trim());
        }
    }

    /**
     * Get the user attribute definition object being edited / created
     * 
     * @return definition
     */
    public UserAttributeDefinition getDefinition() {
        return definition;
    }

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

⌨️ 快捷键说明

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