/**
   * Constructor that uses DOM Element
   *
   * @param element the DOM representation of security token.
   * @throws com.sun.identity.wss.security.SecurityException
   */
  public FAMSecurityToken(Element element) throws SecurityException {
    if (element == null) {
      throw new SecurityException(WSSUtils.bundle.getString("nullInput"));
    }

    String localName = element.getLocalName();
    if (!"FAMToken".equals(localName)) {
      throw new SecurityException(WSSUtils.bundle.getString("invalidElement"));
    }

    NodeList nl = element.getChildNodes();
    int length = nl.getLength();
    if (length == 0) {
      throw new SecurityException(WSSUtils.bundle.getString("invalidElement"));
    }

    for (int i = 0; i < length; i++) {
      Node child = (Node) nl.item(i);
      if (child.getNodeType() != Node.ELEMENT_NODE) {
        continue;
      }

      String childName = child.getLocalName();
      if (childName.equals("TokenValue")) {
        tokenID = XMLUtils.getElementValue((Element) child);
      } else if (childName.equals("AppTokenValue")) {
        appTokenID = XMLUtils.getElementValue((Element) child);
      } else if (childName.equals("TokenType")) {
        tokenType = XMLUtils.getElementValue((Element) child);
      }
    }
  }
 /**
  * Constructor creates <code>SPProvidedNameIdentifier</code> object from Document Element.
  *
  * @param spProvidedNameIdentifierElement the Document Element.
  * @throws FSMsgException on errors.
  */
 public SPProvidedNameIdentifier(Element spProvidedNameIdentifierElement) throws FSMsgException {
   Element elt = (Element) spProvidedNameIdentifierElement;
   String eltName = elt.getLocalName();
   if (eltName == null) {
     if (FSUtils.debug.messageEnabled()) {
       FSUtils.debug.message("SPProvidedNameIdentifier(Element): " + "local name missing");
     }
     throw new FSMsgException("nullInput", null);
   }
   if (!(eltName.equals("SPProvidedNameIdentifier"))) {
     if (FSUtils.debug.messageEnabled()) {
       FSUtils.debug.message("SPProvidedNameIdentifier(Element: " + "invalid root element");
     }
     throw new FSMsgException("invalidElement", null);
   }
   String read = elt.getAttribute("NameQualifier");
   if (read != null) {
     setNameQualifier(read);
   }
   read = elt.getAttribute("Format");
   if (read != null) {
     setFormat(read);
   }
   read = XMLUtils.getElementValue(elt);
   if ((read == null) || (read.length() == 0)) {
     if (FSUtils.debug.messageEnabled()) {
       FSUtils.debug.message("SPProvidedNameIdentifier(Element:  " + "null input specified");
     }
     throw new FSMsgException("nullInput", null);
   } else {
     setName(read);
   }
 }
示例#3
0
 /**
  * Constructor creates <code>IDPEntry</code> Object from
  * Document Element.
  *
  * @param root Document Element of <code>IDPEntry<code> object.
  * @throws FSMsgException if <code>IDPEntry<code> cannot be created.
  */
 public IDPEntry(Element root) throws FSMsgException {
   if (root == null) {
     SAMLUtils.debug.message("IDPEntry.parseXML: null input.");
     throw new FSMsgException("nullInput", null);
   }
   String tag = null;
   if (((tag = root.getLocalName()) == null) || (!tag.equals("IDPEntry"))) {
     FSUtils.debug.message("IDPEntry.parseXML: wrong input.");
     throw new FSMsgException("wrongInput", null);
   }
   NodeList nl = root.getChildNodes();
   Node child;
   String nodeName;
   int length = nl.getLength();
   for (int i = 0; i < length; i++) {
     child = nl.item(i);
     if ((nodeName = child.getLocalName()) != null) {
       if (nodeName.equals("ProviderID")) {
         if (providerID != null) {
           if (FSUtils.debug.messageEnabled()) {
             FSUtils.debug.message("IDPEntry(Element): should" + "contain only one ProviderID");
           }
           throw new FSMsgException("wrongInput", null);
         }
         providerID = XMLUtils.getElementValue((Element) child);
       } else if (nodeName.equals("ProviderName")) {
         if (providerName != null) {
           if (FSUtils.debug.messageEnabled()) {
             FSUtils.debug.message("IDPEntry(Element): should" + "contain only one ProviderName");
           }
           throw new FSMsgException("wrongInput", null);
         }
         providerName = XMLUtils.getElementValue((Element) child);
       } else if (nodeName.equals("Loc")) {
         if (location != null) {
           if (FSUtils.debug.messageEnabled()) {
             FSUtils.debug.message("IDPEntry(Element): should" + "contain only one Loc");
           }
           throw new FSMsgException("wrongInput", null);
         }
         location = XMLUtils.getElementValue((Element) child);
       }
     }
   }
 }
 /**
  * Constructs an <code>AudienceRestrictionCondition</code> element from an existing XML block.
  *
  * @param audienceRestrictionConditionElement A <code>org.w3c.dom.Element</code> representing DOM
  *     tree for <code>AudienceRestrictionCondition</code> object.
  * @exception SAMLException if it could not process the <code>org.w3c.dom.Element</code> properly,
  *     implying that there is an error in the sender or in the element definition.
  */
 public AudienceRestrictionCondition(org.w3c.dom.Element audienceRestrictionConditionElement)
     throws SAMLException {
   Element elt = (Element) audienceRestrictionConditionElement;
   String eltName = elt.getLocalName();
   if (eltName == null) {
     if (SAMLUtilsCommon.debug.messageEnabled()) {
       SAMLUtilsCommon.debug.message("AudienceRestrictionCondition: " + "null condition ");
     }
     throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("nullInput"));
   }
   if (!(eltName.equals("AudienceRestrictionCondition"))) {
     if (!(eltName.equals("Condition"))) {
       if (SAMLUtilsCommon.debug.messageEnabled()) {
         SAMLUtilsCommon.debug.message(
             "AudienceRestrictionCondition: " + "unsupported condition ");
       }
       throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("unsupportedCondition"));
     }
   }
   if (eltName.equals("Condition")) { // seems like extension type
     String type = elt.getAttribute("xsi:type");
     if (!(type.equals("AudienceRestrictionCondition"))) {
       if (SAMLUtilsCommon.debug.messageEnabled()) {
         SAMLUtilsCommon.debug.message("AudienceRestrictionCondition: invalid condition");
       }
       throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("invalidElement"));
     }
   }
   NodeList nl = elt.getChildNodes();
   if (nl.getLength() <= 0) {
     if (SAMLUtilsCommon.debug.messageEnabled()) {
       SAMLUtilsCommon.debug.message(
           "AudienceRestrictionCondition: " + "no Audience in this Element");
     }
     throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("noElement"));
   }
   int length = nl.getLength();
   for (int n = 0; n < length; n++) {
     Node child = (Node) nl.item(n);
     if (child.getNodeType() != Node.ELEMENT_NODE) {
       continue;
     }
     String childName = child.getLocalName();
     if (childName.equals("Audience")) {
       _audience.add(XMLUtils.getElementValue((Element) child));
     } else {
       if (SAMLUtilsCommon.debug.messageEnabled()) {
         SAMLUtilsCommon.debug.message(
             "AudienceRestrictionCondition:" + "  invalid element found");
       }
       throw new SAMLRequesterException(SAMLUtilsCommon.bundle.getString("invalidElement"));
     }
   }
 }