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