/** * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved * * The contents of this file are subject to the terms * of the Common Development and Distribution License * (the License). You may not use this file except in * compliance with the License. * * You can obtain a copy of the License at * https://opensso.dev.java.net/public/CDDLv1.0.html or * opensso/legal/CDDLv1.0.txt * See the License for the specific language governing * permission and limitations under the License. * * When distributing Covered Code, include this CDDL * Header Notice in each file and include the License file * at opensso/legal/CDDLv1.0.txt. * If applicable, add the following below the CDDL Header, * with the fields enclosed by brackets [] replaced by * your own identifying information: * "Portions Copyrighted [year] [name of copyright owner]" * * $Id: SASLRequest.java,v 1.2 2008/06/25 05:47:08 qcheng Exp $ * Portions Copyrighted 2014 ForgeRock AS. */ package com.sun.identity.liberty.ws.authnsvc.protocol; import org.w3c.dom.Element; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import com.sun.identity.shared.xml.XMLUtils; import com.sun.identity.shared.encode.Base64; import com.sun.identity.liberty.ws.authnsvc.AuthnSvcConstants; import com.sun.identity.liberty.ws.authnsvc.AuthnSvcException; import com.sun.identity.liberty.ws.authnsvc.AuthnSvcUtils; /** * The SASLRequest class represents SASLRequest * element defined in Authentication Service schema. * @supported.all.api * @deprecated since 12.0.0 */ @Deprecated public class SASLRequest { private byte[] data = null; private Element requestAuthnContext = null; private String mechanism = null; private String authzID = null; private String advisoryAuthnID = null; private String id = null; private String messageID = null; private String refToMessageID = null; /** * Constructs a SASLRequest instance. * * @param mechanism Mechanism attribute value. */ public SASLRequest(String mechanism) { this.mechanism = mechanism; } /** * Constructs a SAMLRequest with a * org.w3c.dom.Element. * @param element a SASLRequest element * @exception AuthnSvcException if an error occurs while parsing the * SASLRequest element */ public SASLRequest(Element element) throws AuthnSvcException { Element dataE = null; NodeList nl = element.getChildNodes(); int length = nl.getLength(); for(int i = 0; i < length; i++) { Node child = nl.item(i); if (child.getNodeType() == Node.ELEMENT_NODE) { Element childElement = (Element)child; String localName = childElement.getLocalName(); String namespaceURI = childElement.getNamespaceURI(); if (AuthnSvcConstants.NS_AUTHN_SVC.equals(namespaceURI) && AuthnSvcConstants.TAG_DATA.equals(localName)) { if (dataE != null) { throw new AuthnSvcException("tooManyDataInReq"); } else if (requestAuthnContext != null) { throw new AuthnSvcException("invalidSeqInReq"); } dataE = childElement; } else if (AuthnSvcConstants.NS_PROTOCOLS_SCHEMA .equals(namespaceURI) && AuthnSvcConstants.TAG_REQUEST_AUTHN_CONTEXT .equals(localName)) { if (requestAuthnContext != null) { throw new AuthnSvcException("tooManyReqAuthnCon"); } requestAuthnContext = childElement; } else { throw new AuthnSvcException("invalidChildReq"); } } } data = AuthnSvcUtils.decodeDataElement(dataE); mechanism = XMLUtils.getNodeAttributeValue(element, AuthnSvcConstants.ATTR_MECHANISM); if (mechanism == null) { String msg = AuthnSvcUtils.getString("missingMechanism"); AuthnSvcUtils.debug.error("SASLRequest: " + msg); throw new AuthnSvcException(msg); } id = XMLUtils.getNodeAttributeValue(element, AuthnSvcConstants.ATTR_id); authzID = XMLUtils.getNodeAttributeValue(element, AuthnSvcConstants.ATTR_AUTHZ_ID); advisoryAuthnID = XMLUtils.getNodeAttributeValue(element, AuthnSvcConstants.ATTR_ADVISORY_AUTHN_ID); } /** * Returns value of Element 'Data'. * @return value of Element 'Data' * @see #setData(byte[]) */ public byte[] getData() { return data; } /** * Returns Element RequestAuthnContext. * @return Element RequestAuthnContext * @see #setRequestAuthnContext(Element) */ public Element getRequestAuthnContext() { return requestAuthnContext; } /** * Returns value of mechanism attribute. * @return value of mechanism attribute * @see #setMechanism(String) */ public String getMechanism() { return mechanism; } /** * Returns value of authzID attribute. * @return value of authzID attribute * @see #setAuthzID(String) */ public String getAuthzID() { return authzID; } /** * Returns value of advisoryAuthnID attribute. * @return value of advisoryAuthnID attribute * @see #setAdvisoryAuthnID(String) */ public String getAdvisoryAuthnID() { return advisoryAuthnID; } /** * Returns value of id attribute. * @return value of id attribute * @see #setId(String) */ public String getId() { return id; } /** * Returns value of messageID attribute of * CorrelationHeader. * @return value of messageID attribute * @see #setMessageID(String) */ public String getMessageID() { return messageID; } /** * Returns value of refToMessageID attribute of * CorrelationHeader. * @return value of refToMessageID attribute * @see #setRefToMessageID(String) */ public String getRefToMessageID() { return refToMessageID; } /** * Sets value of Element 'Data'. * @param data value of Element 'Data' * @see #getData() */ public void setData(byte[] data) { this.data = data; } /** * Sets Element RequestAuthnContext. * @param requestAuthnContext Element RequestAuthnContext * @see #getRequestAuthnContext() */ public void setRequestAuthnContext(Element requestAuthnContext) { this.requestAuthnContext = requestAuthnContext; } /** * Sets value of mechanism attribute * @param mechanism value of mechanism attribute * @see #getMechanism() */ public void setMechanism(String mechanism) { this.mechanism = mechanism; } /** * Sets value of authzID attribute. * @param authzID value of authzID attribute * @see #getAuthzID() */ public void setAuthzID(String authzID) { this.authzID = authzID; } /** * Sets value of advisoryAuthnID attribute. * @param advisoryAuthnID value of advisoryAuthnID attribute * @see #getAdvisoryAuthnID() */ public void setAdvisoryAuthnID(String advisoryAuthnID) { this.advisoryAuthnID = advisoryAuthnID; } /** * Sets value of id attribute. * @param id value of id attribute * @see #getId() */ public void setId(String id) { this.id = id; } /** * Sets value of messageID attribute of * CorrelationHeader. * @param messageID value of messageID attribute * @see #getMessageID() */ public void setMessageID(String messageID) { this.messageID = messageID; } /** * Sets value of refToMessageID attribute of * CorrelationHeader. * @param refToMessageID value of refToMessageID attribute * @see #getRefToMessageID() */ public void setRefToMessageID(String refToMessageID) { this.refToMessageID = refToMessageID; } /** * Returns SASLRequest in org.w3c.dom.Element * format. * * @return SASLRequest in org.w3c.dom.Element * format. * @exception AuthnSvcException if an error occurs while creating the * SASLRequest element */ public Element toElement() throws AuthnSvcException { Document doc = null; try { doc = XMLUtils.newDocument(); } catch (Exception ex) { AuthnSvcUtils.debug.error("SASLRequest:toElement", ex); throw new AuthnSvcException(ex.getMessage()); } Element saslReqE = doc.createElementNS(AuthnSvcConstants.NS_AUTHN_SVC, AuthnSvcConstants.PTAG_SASL_REQUEST); saslReqE.setAttributeNS(AuthnSvcConstants.NS_XML, AuthnSvcConstants.XMLNS_AUTHN_SVC, AuthnSvcConstants.NS_AUTHN_SVC); saslReqE.setAttributeNS(AuthnSvcConstants.NS_XML, AuthnSvcConstants.XMLNS_PROTOCOLS_SCHEMA, AuthnSvcConstants.NS_PROTOCOLS_SCHEMA); saslReqE.setAttributeNS(null, AuthnSvcConstants.ATTR_MECHANISM, mechanism); if (authzID != null) { saslReqE.setAttributeNS(null, AuthnSvcConstants.ATTR_AUTHZ_ID, authzID); } if (advisoryAuthnID != null) { saslReqE.setAttributeNS(null, AuthnSvcConstants.ATTR_ADVISORY_AUTHN_ID, advisoryAuthnID); } if (id != null) { saslReqE.setAttributeNS(null, AuthnSvcConstants.ATTR_id, id); } if (data != null) { Element dataE = doc.createElementNS(AuthnSvcConstants.NS_AUTHN_SVC, AuthnSvcConstants.PTAG_DATA); dataE.appendChild(doc.createTextNode(Base64.encode(data))); saslReqE.appendChild(dataE); } doc.appendChild(saslReqE); return doc.getDocumentElement(); } }