コード例 #1
0
  /**
   * Creates new AuthenticationCredential
   *
   * @param peergroup The peergroup context in which this AuthenticationCredential is created.
   * @param method The authentication method which will be requested when the
   *     AuthentiationCredential is provided to the peergroup Membership Service. Authentication
   *     methods are specific to Membership services. Consult the Documentation for the Membership
   *     service you will be authenticating against in order to determine the valid <tt>method</tt>
   *     values. Every Membership service should support a default authentication method which can
   *     be specified as <tt>null</null>.
   * @param indentityInfo Optional additional information which is used by the authentication method
   *     or <tt>null</tt>. This information is passed to the authentication method during the apply
   *     operation of the Membership Service. Consult the documentation for the specific Membership
   *     Service you are using for details on how this information is used (if at all).
   */
  public AuthenticationCredential(PeerGroup peergroup, String method, Element indentityInfo) {
    this.peergroup = peergroup;

    authenticationMethod = method;

    if (null != indentityInfo) {
      this.identityInfo = StructuredDocumentUtils.copyAsDocument(indentityInfo);
    }
  }
コード例 #2
0
  /**
   * Process an individual element from the document.
   *
   * @param elem the element to be processed.
   * @return true if the element was recognized, otherwise false.
   */
  protected boolean handleElement(TextElement elem) {
    if (elem.getName().equals("PeerGroupID")) {
      try {
        URI gID = new URI(elem.getTextValue());
        ID pgid = IDFactory.fromURI(gID);

        if (!pgid.equals(getPeerGroupID())) {
          throw new IllegalArgumentException(
              "Operation is from a different group. " + pgid + " != " + getPeerGroupID());
        }
      } catch (URISyntaxException badID) {
        throw new IllegalArgumentException("Unusable ID in advertisement: " + elem.getTextValue());
      }
      return true;
    }

    if (elem.getName().equals("PeerID")) {
      try {
        URI pID = new URI(elem.getTextValue());
        ID pid = IDFactory.fromURI(pID);

        if (!pid.equals(getPeerID())) {
          throw new IllegalArgumentException(
              "Operation is from a different group. " + pid + " != " + getPeerID());
        }
      } catch (URISyntaxException badID) {
        throw new IllegalArgumentException("Bad Peer ID in advertisement: " + elem.getTextValue());
      } catch (ClassCastException badID) {
        throw new IllegalArgumentException("Id is not a peer id: " + elem.getTextValue());
      }
      return true;
    }

    if (elem.getName().equals("Method")) {
      setMethod(elem.getTextValue());
      return true;
    }

    if (elem.getName().equals("IdentityInfo")) {
      Enumeration firstChild = elem.getChildren();

      if (!firstChild.hasMoreElements()) {
        throw new IllegalArgumentException("Missing identity info");
      }

      identityInfo = StructuredDocumentUtils.copyAsDocument((Element) firstChild.nextElement());

      return true;
    }

    // element was not handled
    return false;
  }
コード例 #3
0
 /**
  * Returns the StructuredDocument Element containing the identity information which was originally
  * provided when this AuthenticationCredential was created.
  *
  * @return StructuredDocument Element containing the identity information which was originally
  *     provided when this AuthenticationCredential was created.
  */
 public Element getIdentityInfo() {
   return (null == identityInfo) ? null : StructuredDocumentUtils.copyAsDocument(identityInfo);
 }