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

📄 subject.java

📁 gcc的组建
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
          {            result.add(o);          }      }    return Collections.unmodifiableSet (result);  }  public Set getPrivateCredentials()  {    return privCred;  }  public Set getPrivateCredentials (Class clazz)  {    HashSet result = new HashSet (privCred.size());    for (Iterator it = privCred.iterator(); it.hasNext(); )      {        Object o = it.next();        if (o != null && clazz.isAssignableFrom (o.getClass()))          {            result.add(o);          }      }    return Collections.unmodifiableSet (result);  }  public Set getPublicCredentials()  {    return pubCred;  }  public Set getPublicCredentials (Class clazz)  {    HashSet result = new HashSet (pubCred.size());    for (Iterator it = pubCred.iterator(); it.hasNext(); )      {        Object o = it.next();        if (o != null && clazz.isAssignableFrom (o.getClass()))          {            result.add(o);          }      }    return Collections.unmodifiableSet (result);  }  public int hashCode()  {    return principals.hashCode() + privCred.hashCode() + pubCred.hashCode();  }  /**   * <p>Returns whether or not this subject is read-only.</p>   *   * @return True is this subject is read-only.   */  public boolean isReadOnly()  {    return readOnly;  }  /**   * <p>Marks this subject as read-only.</p>   *   * @throws SecurityException If the caller does not have permission to   *  set this subject as read-only (<code>"setReadOnly"</code> target of   *  {@link AuthPermission}.   */  public void setReadOnly()  {    final SecurityManager sm = System.getSecurityManager();    if (sm != null)      {        sm.checkPermission (new AuthPermission ("setReadOnly"));      }    readOnly = true;  }  public String toString()  {    return Subject.class.getName() + " [ principals=" + principals +      ", private credentials=" + privCred + ", public credentials=" +      pubCred + ", read-only=" + readOnly + " ]";  }// Inner class.  // -------------------------------------------------------------------------  /**   * An undocumented inner class that is used for sets in the parent class.   */  private static class SecureSet extends AbstractSet implements Serializable  {    // Fields.    // -----------------------------------------------------------------------    private static final long serialVersionUID = 7911754171111800359L;    static final int PRINCIPALS = 0;    static final int PUBLIC_CREDENTIALS = 1;    static final int PRIVATE_CREDENTIALS = 2;    private final Subject subject;    private final LinkedList elements;    private final transient int type;    // Constructors.    // -----------------------------------------------------------------------    SecureSet (final Subject subject, final int type, final Collection inElements)    {      this (subject, type);      for (Iterator it = inElements.iterator(); it.hasNext(); )        {          Object o = it.next();          if (type == PRINCIPALS && !(o instanceof Principal))            {              throw new IllegalArgumentException(o+" is not a Principal");            }          if (!this.elements.contains (o))            {              this.elements.add (o);            }        }    }    SecureSet (final Subject subject, final int type)    {      this.subject = subject;      this.type = type;      this.elements = new LinkedList();    }    // Instance methods.    // -----------------------------------------------------------------------    public synchronized int size()    {      return elements.size();    }    public Iterator iterator()    {      return elements.iterator();    }    public synchronized boolean add(Object element)    {      if (subject.isReadOnly())        {          throw new IllegalStateException ("subject is read-only");        }      final SecurityManager sm = System.getSecurityManager();      switch (type)        {        case PRINCIPALS:          if (sm != null)            {              sm.checkPermission (new AuthPermission ("modifyPrincipals"));            }          if (!(element instanceof Principal))            {              throw new IllegalArgumentException ("element is not a Principal");            }          break;        case PUBLIC_CREDENTIALS:          if (sm != null)            {              sm.checkPermission (new AuthPermission ("modifyPublicCredentials"));            }          break;        case PRIVATE_CREDENTIALS:          if (sm != null)            {              sm.checkPermission (new AuthPermission ("modifyPrivateCredentials"));            }          break;        default:          throw new Error ("this statement should be unreachable");        }      if (elements.contains (element))        {          return false;        }      return elements.add (element);    }    public synchronized boolean remove (final Object element)    {      if (subject.isReadOnly())        {          throw new IllegalStateException ("subject is read-only");        }      final SecurityManager sm = System.getSecurityManager();      switch (type)        {        case PRINCIPALS:          if (sm != null)            {              sm.checkPermission (new AuthPermission ("modifyPrincipals"));            }          if (!(element instanceof Principal))            {              throw new IllegalArgumentException ("element is not a Principal");            }          break;        case PUBLIC_CREDENTIALS:          if (sm != null)            {              sm.checkPermission (new AuthPermission ("modifyPublicCredentials"));            }          break;        case PRIVATE_CREDENTIALS:          if (sm != null)            {              sm.checkPermission (new AuthPermission ("modifyPrivateCredentials"));            }          break;        default:          throw new Error("this statement should be unreachable");        }      return elements.remove(element);    }    public synchronized boolean contains (final Object element)    {      return elements.contains (element);    }    public boolean removeAll (final Collection c)    {      if (subject.isReadOnly())        {          throw new IllegalStateException ("subject is read-only");        }      return super.removeAll (c);    }    public boolean retainAll (final Collection c)    {      if (subject.isReadOnly())        {          throw new IllegalStateException ("subject is read-only");        }      return super.retainAll (c);    }    public void clear()    {      if (subject.isReadOnly())        {          throw new IllegalStateException ("subject is read-only");        }      elements.clear();    }    private synchronized void writeObject (ObjectOutputStream out)      throws IOException    {      throw new UnsupportedOperationException ("FIXME: determine serialization");    }    private void readObject (ObjectInputStream in)      throws ClassNotFoundException, IOException    {      throw new UnsupportedOperationException ("FIXME: determine serialization");    }  }}

⌨️ 快捷键说明

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