a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * The contents of this file are subject to the terms
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * of the Common Development and Distribution License
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * (the License). You may not use this file except in
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * compliance with the License.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * You can obtain a copy of the License at
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * See the License for the specific language governing
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * permission and limitations under the License.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * When distributing Covered Code, include this CDDL
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Header Notice in each file and include the License file
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * If applicable, add the following below the CDDL Header,
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * with the fields enclosed by brackets [] replaced by
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * your own identifying information:
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * $Id: AuthenticationQuery.java,v 1.2 2008/06/25 05:47:36 qcheng Exp $
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml.common.SAMLConstants;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml.common.SAMLException;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterimport com.sun.identity.saml.common.SAMLRequesterException;
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * This concrete class extends from the abstract base class
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * <code>SubjectQuery</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * It represents the query for an authentication assertion. It corresponds
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * to the <code><samlp:AuthenticationQueryType></code> in the SAML
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * protocol schema.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @supported.all.api
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Fosterpublic class AuthenticationQuery extends SubjectQuery {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Default Constructor
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * This constructor is used to build an Authentication Query from a DOM
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * tree that was built from the XML string.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param element the DOM tree element which contains an Authentication
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @exception SAMLException when an error occurs.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public AuthenticationQuery(Element element) throws SAMLException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // make sure input is not null
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("AuthenticationQuery: null input.");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // check if it's an AuthenticationQuery
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster boolean valid = SAMLUtils.checkQuery(element, "AuthenticationQuery");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("AuthenticationQuery: Wrong input.");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // Not checking whether Subject is in front of ConfirmatinMethod XXX
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // But it is checking that there is only one Subject, and
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // 0 or 1 ConfirmationMethod.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // loop through all the children including TEXT and COMMENT
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if ((childName = child.getLocalName()) != null) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("AuthenticationQuery: "
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster + "contained more than one <Subject>");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("AuthenticationQuery: included"
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster } // end childName != null
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster } // end for loop
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // make sure there is one Subject
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("AuthenticationQuery: missing Subject.");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster // obtain the AuthenticationMethod attribute if any
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster if (element.hasAttribute("AuthenticationMethod")) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster authMethod = element.getAttribute("AuthenticationMethod");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructor.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param subject the Subject of the <code>AuthenticationQuery</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param authMethod the <code>AuthenticationMethod</code> in string
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * format. It could be null.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws SAMLException
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("AuthenticationQuery: missing Subject.");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Constructor.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param subject The Subject of the <code>AuthenticationQuery</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @throws SAMLException
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public AuthenticationQuery(Subject subject) throws SAMLException {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster SAMLUtils.debug.message("AuthenticationQuery: missing Subject.");
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns the <code>AuthenticationMethod</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return <code>AuthenticationMethod</code> in string format; or null
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * if there is none.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns the type of this query.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return <code>Query.AUTHENTICATION_QUERY</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Translates the <code>AuthenticationQuery</code> to an XML document
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * String based on the <code>AuthenticationQuery</code> schema described
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return An XML String representing the <code>AuthenticationQuery</code>.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster return this.toString(true, false);
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * Returns a String representation of the <samlp:AuthenticationQuery>
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param includeNS Determines whether or not the namespace qualifier
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * is prepended to the Element when converted
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @param declareNS Determines whether or not the namespace is declared
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * within the Element.
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster * @return A string containing the valid XML for this element
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster public String toString(boolean includeNS, boolean declareNS) {
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster xml.append("<").append(prefix).append("AuthenticationQuery").
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster xml.append(" AuthenticationMethod=\"").append(authMethod).
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster xml.append(">\n").append(subject.toString(true, true));
a688bcbb4bcff5398fdd29b86f83450257dc0df4Allan Foster xml.append("</").append(prefix).append("AuthenticationQuery>\n");