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:06:05 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.jaxb20;
030:
031: import com.sun.xml.wss.saml.SAMLException;
032:
033: import com.sun.xml.wss.logging.LogDomainConstants;
034:
035: import com.sun.xml.security.core.dsig.KeyInfoType;
036: import com.sun.xml.wss.saml.internal.saml11.jaxb20.SubjectConfirmationType;
037: import com.sun.xml.wss.saml.util.SAMLJAXBUtil;
038: import java.util.LinkedList;
039: import java.util.List;
040: import javax.xml.bind.JAXBElement;
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.jaxb20.SubjectConfirmationType
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: this .confirmationMethod = 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 SubjectConfirmationType fromElement(
096: org.w3c.dom.Element element) throws SAMLException {
097: try {
098: JAXBContext jc = SAMLJAXBUtil.getJAXBContext();
099:
100: javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
101: return (SubjectConfirmationType) u.unmarshal(element);
102: } catch (Exception ex) {
103: throw new SAMLException(ex.getMessage());
104: }
105: }
106:
107: /**
108: * Constructs an <code>SubjectConfirmation</code> instance.
109: *
110: * @param confirmationMethods A set of <code>confirmationMethods</code>
111: * each of which is a URI (String) that identifies a protocol
112: * used to authenticate a <code>Subject</code>. Please refer to
113: * <code>draft-sstc-core-25</code> Section 7 for
114: * a list of URIs identifying common authentication protocols.
115: * @param subjectConfirmationData Additional authentication information to
116: * be used by a specific authentication protocol. Can be passed as
117: * null if there is no <code>subjectConfirmationData</code> for the
118: * <code>SubjectConfirmation</code> object.
119: * @param keyInfo An XML signature element that specifies a cryptographic
120: * key held by the <code>Subject</code>.
121: * @exception SAMLException if the input data is invalid or
122: * <code>confirmationMethods</code> is empty.
123: */
124: public SubjectConfirmation(List confirmationMethods,
125: Element subjectConfirmationData, Element keyInfo)
126: throws SAMLException {
127:
128: JAXBContext jc = null;
129: javax.xml.bind.Unmarshaller u = null;
130:
131: //Unmarshal to JAXB KeyInfo Object and set it
132: try {
133: jc = SAMLJAXBUtil.getJAXBContext();
134: ;
135: u = jc.createUnmarshaller();
136: } catch (Exception ex) {
137: throw new SAMLException(ex.getMessage());
138: }
139:
140: try {
141: if (keyInfo != null) {
142: setKeyInfo((KeyInfoType) ((JAXBElement) u
143: .unmarshal(keyInfo)).getValue());
144: }
145: if (subjectConfirmationData != null) {
146: setSubjectConfirmationData((SubjectConfirmationType) ((JAXBElement) u
147: .unmarshal(subjectConfirmationData)).getValue());
148: }
149: } catch (Exception ex) {
150: // log here
151: throw new SAMLException(ex);
152: }
153: setConfirmationMethod(confirmationMethods);
154: }
155:
156: }
|