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

📄 servicepermission.java

📁 Mobile 应用程序使用 Java Micro Edition (Java ME) 平台
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
	if (action.equals("")) {	    throw new IllegalArgumentException("action can't be empty");	}	int mask = NONE;	char[] a = action.toCharArray();	int i = a.length - 1;	if (i < 0)	    return mask;	while (i != -1) {	    char c;	    // skip whitespace	    while ((i!=-1) && ((c = a[i]) == ' ' ||			       c == '\r' ||			       c == '\n' ||			       c == '\f' ||			       c == '\t'))		i--;	    // check for the known strings	    int matchlen;	    if (i >= 7 && (a[i-7] == 'i' || a[i-7] == 'I') &&			  (a[i-6] == 'n' || a[i-6] == 'N') &&			  (a[i-5] == 'i' || a[i-5] == 'I') &&			  (a[i-4] == 't' || a[i-4] == 'T') &&			  (a[i-3] == 'i' || a[i-3] == 'I') &&			  (a[i-2] == 'a' || a[i-2] == 'A') &&			  (a[i-1] == 't' || a[i-1] == 'T') &&			  (a[i] == 'e' || a[i] == 'E'))	    {		matchlen = 8;		mask |= INITIATE;	    } else if (i >= 5 && (a[i-5] == 'a' || a[i-5] == 'A') &&				 (a[i-4] == 'c' || a[i-4] == 'C') &&				 (a[i-3] == 'c' || a[i-3] == 'C') &&				 (a[i-2] == 'e' || a[i-2] == 'E') &&				 (a[i-1] == 'p' || a[i-1] == 'P') &&				 (a[i] == 't' || a[i] == 'T'))	    {		matchlen = 6;		mask |= ACCEPT;	    } else {		// parse error		throw new IllegalArgumentException(			"invalid permission: " + action);	    }	    // make sure we didn't just match the tail of a word	    // like "ackbarfaccept".  Also, skip to the comma.	    boolean seencomma = false;	    while (i >= matchlen && !seencomma) {		switch(a[i-matchlen]) {		case ',':		    seencomma = true;		    /*FALLTHROUGH*/		case ' ': case '\r': case '\n':		case '\f': case '\t':		    break;		default:		    throw new IllegalArgumentException(			    "invalid permission: " + action);		}		i--;	    }	    // point i at the location of the comma minus one (or -1).	    i -= matchlen;	}	return mask;    }    /**     * WriteObject is called to save the state of the ServicePermission      * to a stream. The actions are serialized, and the superclass     * takes care of the name.     */    private void writeObject(java.io.ObjectOutputStream s)        throws IOException    {	// Write out the actions. The superclass takes care of the name	// call getActions to make sure actions field is initialized	if (actions == null)	    getActions();	s.defaultWriteObject();    }    /**     * readObject is called to restore the state of the     * ServicePermission from a stream.     */    private void readObject(java.io.ObjectInputStream s)         throws IOException, ClassNotFoundException    {	// Read in the action, then initialize the rest	s.defaultReadObject();	init(getName(),getMask(actions));    }    /*      public static void main(String args[]) throws Exception {      ServicePermission this_ =      new ServicePermission(args[0], "accept");      ServicePermission that_ =      new ServicePermission(args[1], "accept,initiate");      System.out.println("-----\n");      System.out.println("this.implies(that) = " + this_.implies(that_));      System.out.println("-----\n");      System.out.println("this = "+this_);      System.out.println("-----\n");      System.out.println("that = "+that_);      System.out.println("-----\n");      KrbServicePermissionCollection nps =      new KrbServicePermissionCollection();      nps.add(this_);      nps.add(new ServicePermission("nfs/example.com@EXAMPLE.COM",      "accept"));      nps.add(new ServicePermission("host/example.com@EXAMPLE.COM",      "initiate"));      System.out.println("nps.implies(that) = " + nps.implies(that_));      System.out.println("-----\n");      Enumeration e = nps.elements();	      while (e.hasMoreElements()) {      ServicePermission x =      (ServicePermission) e.nextElement();      System.out.println("nps.e = " + x);      }      }    */    }final class KrbServicePermissionCollection extends PermissionCollection     implements java.io.Serializable {    // Not serialized; see serialization section at end of class    private transient List perms;    public KrbServicePermissionCollection() {	perms = new ArrayList();    }        /**     * Check and see if this collection of permissions implies the permissions      * expressed in "permission".     *     * @param p the Permission object to compare     *     * @return true if "permission" is a proper subset of a permission in      * the collection, false if not.     */    public boolean implies(Permission permission) {	if (! (permission instanceof ServicePermission))   		return false;	ServicePermission np = (ServicePermission) permission;	int desired = np.getMask();	int effective = 0;	int needed = desired;	synchronized (this) {	    int len = perms.size();		    // need to deal with the case where the needed permission has	    // more than one action and the collection has individual permissions	    // that sum up to the needed.	    for (int i = 0; i < len; i++) {		ServicePermission x = (ServicePermission) perms.get(i);		//System.out.println("  trying "+x);		if (((needed & x.getMask()) != 0) && x.impliesIgnoreMask(np)) {		    effective |=  x.getMask();		    if ((effective & desired) == desired)			return true;		    needed = (desired ^ effective);		}	    }	}	return false;    }    /**     * Adds a permission to the ServicePermissions. The key for     * the hash is the name.     *     * @param permission the Permission object to add.     *     * @exception IllegalArgumentException - if the permission is not a     *                                       ServicePermission     *     * @exception SecurityException - if this PermissionCollection object     *                                has been marked readonly     */    public void add(Permission permission) {	if (! (permission instanceof ServicePermission))	    throw new IllegalArgumentException("invalid permission: "+					       permission);	if (isReadOnly())	    throw new SecurityException("attempt to add a Permission to a readonly PermissionCollection");	synchronized (this) {	    perms.add(0, permission);	}    }    /**     * Returns an enumeration of all the ServicePermission objects     * in the container.     *     * @return an enumeration of all the ServicePermission objects.     */    public Enumeration elements() {        // Convert Iterator into Enumeration	synchronized (this) {	    return Collections.enumeration(perms);	}    }    private static final long serialVersionUID = -4118834211490102011L;    // Need to maintain serialization interoperability with earlier releases,    // which had the serializable field:    // private Vector permissions;    /**     * @serialField permissions java.util.Vector     *     A list of ServicePermission objects.     */    private static final ObjectStreamField[] serialPersistentFields = {        new ObjectStreamField("permissions", Vector.class),    };    /**     * @serialData "permissions" field (a Vector containing the ServicePermissions).     */    /*     * Writes the contents of the perms field out as a Vector for     * serialization compatibility with earlier releases.     */    private void writeObject(ObjectOutputStream out) throws IOException {	// Don't call out.defaultWriteObject()	// Write out Vector	Vector permissions = new Vector(perms.size());	synchronized (this) {	    permissions.addAll(perms);	}        ObjectOutputStream.PutField pfields = out.putFields();        pfields.put("permissions", permissions);        out.writeFields();    }    /*     * Reads in a Vector of ServicePermissions and saves them in the perms field.     */    private void readObject(ObjectInputStream in) throws IOException,     ClassNotFoundException {	// Don't call defaultReadObject()	// Read in serialized fields	ObjectInputStream.GetField gfields = in.readFields();	// Get the one we want	Vector permissions = (Vector)gfields.get("permissions", null);	perms = new ArrayList(permissions.size());	perms.addAll(permissions);    }}

⌨️ 快捷键说明

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