コード例 #1
0
ファイル: Subject.java プロジェクト: jshjs11/xi
  /**
   * Returns a {@code String} representation of this {@code Subject}.
   *
   * @return a {@code String} representation of this {@code Subject}.
   */
  @Override
  public String toString() {
    StringBuilder buf = new StringBuilder("Subject:\n");

    Iterator<?> it = principals.iterator();
    while (it.hasNext()) {
      buf.append("\tPrincipal: ");
      buf.append(it.next());
      buf.append('\n');
    }

    it = publicCredentials.iterator();
    while (it.hasNext()) {
      buf.append("\tPublic Credential: ");
      buf.append(it.next());
      buf.append('\n');
    }

    int offset = buf.length() - 1;
    it = privateCredentials.iterator();
    try {
      while (it.hasNext()) {
        buf.append("\tPrivate Credential: ");
        buf.append(it.next());
        buf.append('\n');
      }
    } catch (SecurityException e) {
      buf.delete(offset, buf.length());
      buf.append("\tPrivate Credentials: no accessible information\n");
    }
    return buf.toString();
  }
コード例 #2
0
ファイル: Subject.java プロジェクト: jshjs11/xi
  /**
   * Checks two Subjects for equality. More specifically if the principals, public and private
   * credentials are equal, equality for two {@code Subjects} is implied.
   *
   * @param obj the {@code Object} checked for equality with this {@code Subject}.
   * @return {@code true} if the specified {@code Subject} is equal to this one.
   */
  @Override
  public boolean equals(Object obj) {

    if (this == obj) {
      return true;
    }

    if (obj == null || this.getClass() != obj.getClass()) {
      return false;
    }

    Subject that = (Subject) obj;

    if (principals.equals(that.principals)
        && publicCredentials.equals(that.publicCredentials)
        && privateCredentials.equals(that.privateCredentials)) {
      return true;
    }
    return false;
  }
コード例 #3
0
ファイル: Subject.java プロジェクト: jshjs11/xi
 /**
  * Returns a hash code of this {@code Subject}.
  *
  * @return a hash code of this {@code Subject}.
  */
 @Override
 public int hashCode() {
   return principals.hashCode() + privateCredentials.hashCode() + publicCredentials.hashCode();
 }
コード例 #4
0
ファイル: Subject.java プロジェクト: jshjs11/xi
 /**
  * Returns this {@code Subject}'s public credentials which are a subclass of the {@code Class}
  * provided.
  *
  * @param c the {@code Class} as a criteria which the public credentials returned must satisfy.
  * @return this {@code Subject}'s public credentials. Modifications to the returned set of
  *     credentials do not affect this {@code Subject}'s credentials.
  */
 public <T> Set<T> getPublicCredentials(Class<T> c) {
   return publicCredentials.get(c);
 }
コード例 #5
0
ファイル: Subject.java プロジェクト: jshjs11/xi
 /**
  * Returns this {@code Subject}'s private credentials which are a subclass of the {@code Class}
  * provided.
  *
  * @param c the {@code Class} as a criteria which the private credentials returned must satisfy.
  * @return this {@code Subject}'s private credentials. Modifications to the returned set of
  *     credentials do not affect this {@code Subject}'s credentials.
  */
 public <T> Set<T> getPrivateCredentials(Class<T> c) {
   return privateCredentials.get(c);
 }