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

📄 sipcallpermission.java

📁 First of all, the Applet-phone is a SIP User-Agent with audio and text messaging capabilities. But
💻 JAVA
字号:
/* * SipCallPermission.java * * Created on June 17, 2003, 9:59 AM */package gov.nist.security.permissions;import java.util.*;/** * Permission specific to the sip protocol * checking the sip address of either the incoming request * or the outgoing request or both * @author  DERUELLE Jean */public class SipCallPermission extends java.security.Permission {    /**mask of the actions*/    protected int mask;    static private int OUTGOING=0x01;    static private int INCOMING=0x02;           /**      * Creates a new instance of SipCallPermission      * @param name - name of the permission          */    public SipCallPermission(String name) {        //Our Permission must always have an action, so we choose        //a default one here        this(name,"outgoing");    }        /**      * Creates a new instance of CallPermission      * @param name - name of the permission          * @param actions - the actions of the permission     */    public SipCallPermission(String name, String actions) {        //Our super class, however, does not support actions                //so we don't provide one to that.        super(name);        parse(actions);    }        /**     * @see java.security.Permission#getActions()     */    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==OUTGOING)            return "outgoing";        else if(mask==INCOMING)            return "incoming";        else if(mask==(INCOMING|OUTGOING))            return "outgoing, incoming";        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 SipCallPermission))            return false;        SipCallPermission sipCallPermission=(SipCallPermission)permission;        String name=getName();        //Check the domain        int nameIndexAt=name.indexOf("@");        int permissionIndexAt=sipCallPermission.getName().indexOf("@");        if(permissionIndexAt!=-1 && nameIndexAt!=-1){            String permissionBeforeAt=sipCallPermission.getName().substring(0,permissionIndexAt);            String permissionAfterAt=sipCallPermission.getName().substring(permissionIndexAt+1);            String nameBeforeAt=name.substring(0,nameIndexAt);            String nameAfterAt=name.substring(nameIndexAt+1);            if(nameBeforeAt.equals("*") && permissionAfterAt.equals(nameAfterAt)            && (mask & sipCallPermission.mask) ==sipCallPermission.mask )                    return true;                    }        //The name must be a wildcard *, which signifies        //all the possible names, or the name must match our name        if(!name.equals("*") && !name.equals(sipCallPermission.getName()))            return false;        //Similarly, the requested actions must macth all match actions        //that we've been constructed with        if((mask & sipCallPermission.mask) !=sipCallPermission.mask)            return false;        //Only if both the action and the name match do we return true        return true;    }        /**     * 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("outgoing"))                    mask|=OUTGOING;            else if(tok.equals("incoming"))                    mask|=INCOMING;                                    else throw new IllegalArgumentException("Unknown action "+ tok);        }                    }        /**     * @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 SipCallPermission))            return false;        SipCallPermission sipCallPermission=(SipCallPermission)o;        //For equality, we check the name and the action mask        return ((sipCallPermission.getName().equals(getName())) && (sipCallPermission.mask == mask));    }}

⌨️ 快捷键说明

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