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

📄 roleform.java

📁 这是linux下ssl vpn的实现程序
💻 JAVA
字号:
package com.sslexplorer.security.forms;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

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.boot.PropertyList;
import com.sslexplorer.core.CoreServlet;
import com.sslexplorer.core.forms.CoreForm;
import com.sslexplorer.security.User;


/**
 * Implementation of a {@link CoreForm} that allows an administrator to 
 * create or edit a <i>Group</i> of users (previously known as a <i>Role</i>).
 * 
 * @author Brett Smith <a href="mailto: brett@3sp.com">&lt;brett@3sp.com&gt;</a>
 * @version $Revision: 1.6 $
 */
public class RoleForm extends CoreForm {
    
    // Private instance variables
    
    private String rolename;    
    private PropertyList users;
    
    /**
     * Get the list of selected users in <i>Text Field Text</i> format
     * 
     * @return selected users
     * @see PropertyList
     */
    public String getUsers() {
        return users.getAsTextFieldText();
    }
    
    /**
     * Set the list of selected users in <i>Text Field Text</i> format
     * 
     * @param users selected users
     * @see PropertyList
     */
    public void setUsers(String users) {
        this.users.setAsTextFieldText(users);
    }
    
    /**
     * Get the name of the group.
     * 
     * @return group
     */
    public String getRolename() {
        return rolename;
    }

    /**
     * Set the name of the role
     * 
     * @param rolename name of role
     */
    public void setRolename(String rolename) {
        this.rolename = rolename.trim();
    }

    /**
     * Initialise the form
     * 
     * @param users list of {@link User} objects attached to the role
     */
    public void initialize(List users) {
        rolename = "";        
        this.users = new PropertyList();
        for(Iterator i = users.iterator(); i.hasNext(); ) {
            this.users.add(((User)i.next()).getPrincipalName());
        }
    }
    
    /* (non-Javadoc)
     * @see org.apache.struts.action.ActionForm#validate(org.apache.struts.action.ActionMapping, javax.servlet.http.HttpServletRequest)
     */
    public ActionErrors validate(ActionMapping arg0, HttpServletRequest arg1) {
        ActionErrors errors = new ActionErrors();
        if (isCommiting()) {
           if (rolename.equals("")) {
                errors.add(Globals.ERROR_KEY, new ActionMessage("availableRoles.noRolenameSupplied"));
            }
            if (rolename.length() > 32) {
                errors.add(Globals.ERROR_KEY, new ActionMessage("availableRoles.roleNameExceeds32Chars"));
            }
            if(!getEditing()) {
                try {
                    CoreServlet.getServlet().getUserDatabase().getRole(rolename);
                    errors.add(Globals.ERROR_KEY, new ActionMessage("availableRoles.roleAlreadyExists", rolename));
                } catch (Exception e) {
                    
                }
            }
        }
        return errors;
    }

    /**
     * Get the selected as users as a list of strings
     *  
     * @return selected users as a list of strings
     */
    public List getUserList() {
        return users;
    }
}

⌨️ 快捷键说明

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