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

📄 sipdialogpermission.java

📁 First of all, the Applet-phone is a SIP User-Agent with audio and text messaging capabilities. But
💻 JAVA
字号:
/* * SipDialogPermission.java * * Created on September 25, 2003, 12:11 PM */package gov.nist.security.permissions;import java.util.*;/** * Permission specific to the SIP protocol * hecking if we overstepped the maximum number of dialog  * @author  DERUELLE Jean */public class SipDialogPermission extends java.security.Permission {    /**maximum number of dialog allowed*/    int forkingFactor=0;    /**mask of the actions*/    protected int mask;    static private int CREATE=0x01;        /** Creates a new instance of SipDialogPermission      * @param name - name of the permission         */    public SipDialogPermission(String name) {        this(name,"create");                try{            forkingFactor=Integer.parseInt(name);        }        catch(NumberFormatException nfe){            nfe.printStackTrace();        }            }        /** Creates a new instance of SipDialogPermission     * @param name - name of the permission          * @param actions - the actions of the permission     */    public SipDialogPermission(String name,String actions) {        super(name);        try{            forkingFactor=Integer.parseInt(name);        }        catch(NumberFormatException nfe){            nfe.printStackTrace();        }        parse(actions);    }        /**     * Look into the actions String to get the actions     * associated with that permission     * @param actions - the actions String     */    private void parse(String actions){        //Look into the action string for        //the words incoming or outgoing or both        StringTokenizer st=new StringTokenizer(actions,",\t");        mask=0;        while(st.hasMoreTokens()){            String tok=st.nextToken();            if(tok.equals("create"))                    mask|=CREATE;                 else throw new IllegalArgumentException("Unknown action "+ tok);        }                    }    /**     * This method return the actions' String     * @return the actions of the permission     */    public String getActions() {        //This method must return the same String, no matter how        //the action list was passed to the constructor.        if(mask==0)            return "";        else if(mask==CREATE)            return "create";        else throw new IllegalArgumentException("Unknown mask");    }        /**     * Checks if the specified permission's actions are "implied by" this object's actions.     * @param permission - the permission to check against.     * @return if the specified permission is implied by this object, false if not.      */    public boolean implies(java.security.Permission permission) {        if(!(permission instanceof SipDialogPermission))            return false;        SipDialogPermission sipDialogPermission=(SipDialogPermission)permission;        //Similarly, the requested actions must macth all match actions        //that we've been constructed with        if((mask & sipDialogPermission.mask) !=sipDialogPermission.mask)            return false;                int permissionForkingFactor=0;        try{            permissionForkingFactor=Integer.parseInt(sipDialogPermission.getName());        }                catch(NumberFormatException nfe){            nfe.printStackTrace();            return false;        }        //System.out.println("seuil : "+forkingFactor);        //System.out.println("user : "+permissionForkingFactor);        if(permissionForkingFactor<=forkingFactor)            return true;        return false;    }        /**     * @see java.security.Permission#hashCode()     */    public int hashCode(){        //We must always provide the same hashcode for permissions        //because the hashes must match if the permissions compare        // as equals        return getName().hashCode() ^ mask;     }        /**     * @see java.security.Permission#equals(Object obj)     */    public boolean equals(Object o){        if(!(o instanceof SipDialogPermission))            return false;        SipDialogPermission sipDialogPermission=(SipDialogPermission)o;        //For equality, we check the name and the action mask        return ((sipDialogPermission.getName().equals(getName())) && (sipDialogPermission.mask == mask));    }}

⌨️ 快捷键说明

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