001: /*
002: * The contents of this file are subject to the terms
003: * of the Common Development and Distribution License
004: * (the "License"). You may not use this file except
005: * in compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://jwsdp.dev.java.net/CDDLv1.0.html
009: * See the License for the specific language governing
010: * permissions and limitations under the License.
011: *
012: * When distributing Covered Code, include this CDDL
013: * HEADER in each file and include the License file at
014: * https://jwsdp.dev.java.net/CDDLv1.0.html If applicable,
015: * add the following below this CDDL HEADER, with the
016: * fields enclosed by brackets "[]" replaced with your
017: * own identifying information: Portions Copyright [yyyy]
018: * [name of copyright owner]
019: */
020: /*
021: * $Id: SubjectConfirmation.java,v 1.6 2007/01/08 16:05:58 shyam_rao Exp $
022: */
023:
024: /*
025: * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
026: * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
027: */
028:
029: package com.sun.xml.wss.saml.assertion.saml11.jaxb10;
030:
031: import com.sun.xml.wss.saml.SAMLException;
032: import com.sun.xml.bind.util.ListImpl;
033:
034: import com.sun.xml.wss.logging.LogDomainConstants;
035: import com.sun.xml.wss.saml.internal.saml11.jaxb10.KeyInfoType;
036: import com.sun.xml.wss.saml.internal.saml11.jaxb10.impl.SubjectConfirmationDataImpl;
037: import com.sun.xml.wss.saml.internal.saml11.jaxb10.impl.SubjectConfirmationTypeImpl;
038: import com.sun.xml.wss.saml.util.SAMLJAXBUtil;
039: import java.util.LinkedList;
040: import java.util.List;
041: import org.w3c.dom.Element;
042: import java.util.logging.Logger;
043:
044: import java.security.PublicKey;
045:
046: import javax.xml.bind.JAXBContext;
047:
048: /**
049: * The <code>SubjectConfirmation</code> element specifies a subject by specifying data that
050: * authenticates the subject.
051: */
052: public class SubjectConfirmation
053: extends
054: com.sun.xml.wss.saml.internal.saml11.jaxb10.impl.SubjectConfirmationImpl
055: implements com.sun.xml.wss.saml.SubjectConfirmation {
056:
057: protected PublicKey keyInfoKeyValue = null;
058:
059: protected static final Logger log = Logger.getLogger(
060: LogDomainConstants.WSS_API_DOMAIN,
061: LogDomainConstants.WSS_API_DOMAIN_BUNDLE);
062:
063: public SubjectConfirmation() {
064:
065: }
066:
067: public void setConfirmationMethod(List confirmationMethod) {
068: _ConfirmationMethod = new ListImpl(confirmationMethod);
069: }
070:
071: /**
072: * From scratch constructor for a single confirmation method.
073: *
074: * @param confirmationMethod A URI (String) that identifies a protocol used
075: * to authenticate a <code>Subject</code>. Please refer to
076: * <code>draft-sstc-core-25</code> Section 7 for a list of URIs
077: * identifying common authentication protocols.
078: * @exception SAMLException if the input data is null.
079: */
080: public SubjectConfirmation(java.lang.String confirmationMethod) {
081:
082: List cm = new LinkedList();
083: cm.add(confirmationMethod);
084: setConfirmationMethod(cm);
085: }
086:
087: /**
088: * Constructs a subject confirmation element from an existing
089: * XML block.
090: *
091: * @param subjectConfirmationElement a DOM Element representing the
092: * <code>SubjectConfirmation</code> object.
093: * @throws SAMLException
094: */
095: public static SubjectConfirmationTypeImpl fromElement(
096: org.w3c.dom.Element element) throws SAMLException {
097: try {
098: JAXBContext jc = SAMLJAXBUtil.getJAXBContext();
099: javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
100: return (SubjectConfirmationTypeImpl) u.unmarshal(element);
101: } catch (Exception ex) {
102: throw new SAMLException(ex.getMessage());
103: }
104: }
105:
106: /**
107: * Constructs an <code>SubjectConfirmation</code> instance.
108: *
109: * @param confirmationMethods A set of <code>confirmationMethods</code>
110: * each of which is a URI (String) that identifies a protocol
111: * used to authenticate a <code>Subject</code>. Please refer to
112: * <code>draft-sstc-core-25</code> Section 7 for
113: * a list of URIs identifying common authentication protocols.
114: * @param subjectConfirmationData Additional authentication information to
115: * be used by a specific authentication protocol. Can be passed as
116: * null if there is no <code>subjectConfirmationData</code> for the
117: * <code>SubjectConfirmation</code> object.
118: * @param keyInfo An XML signature element that specifies a cryptographic
119: * key held by the <code>Subject</code>.
120: * @exception SAMLException if the input data is invalid or
121: * <code>confirmationMethods</code> is empty.
122: */
123: public SubjectConfirmation(List confirmationMethods,
124: Element subjectConfirmationData, Element keyInfo)
125: throws SAMLException {
126:
127: JAXBContext jc = null;
128: javax.xml.bind.Unmarshaller u = null;
129:
130: //Unmarshal to JAXB KeyInfo Object and set it
131: try {
132: jc = SAMLJAXBUtil.getJAXBContext();
133: u = jc.createUnmarshaller();
134: } catch (Exception ex) {
135: throw new SAMLException(ex.getMessage());
136: }
137:
138: try {
139: if (keyInfo != null) {
140: setKeyInfo((KeyInfoType) u.unmarshal(keyInfo));
141: }
142:
143: if (subjectConfirmationData != null) {
144: setSubjectConfirmationData((SubjectConfirmationDataImpl) u
145: .unmarshal(subjectConfirmationData));
146: }
147: } catch (Exception ex) {
148: // log here
149: throw new SAMLException(ex);
150: }
151: setConfirmationMethod(confirmationMethods);
152: }
153: }
|