001: /*
002: * $Id: SubjectConfirmationData.java,v 1.4 2007/01/08 16:05:59 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.SubjectConfirmationDataType;
033: import com.sun.xml.wss.saml.util.SAML20JAXBUtil;
034: import java.util.logging.Logger;
035: import java.util.GregorianCalendar;
036: import javax.xml.datatype.DatatypeFactory;
037: import javax.xml.datatype.DatatypeConfigurationException;
038: import java.security.PublicKey;
039:
040: import javax.xml.bind.JAXBContext;
041: import org.w3c.dom.Element;
042:
043: /**
044: * The <code>SubjectConfirmationData</code> element specifies a subject by specifying data that
045: * authenticates the subject.
046: */
047: public class SubjectConfirmationData extends
048: SubjectConfirmationDataType implements
049: com.sun.xml.wss.saml.SubjectConfirmationData {
050:
051: protected PublicKey keyInfoKeyValue = null;
052:
053: protected static final Logger log = Logger.getLogger(
054: LogDomainConstants.WSS_API_DOMAIN,
055: LogDomainConstants.WSS_API_DOMAIN_BUNDLE);
056:
057: public SubjectConfirmationData() {
058:
059: }
060:
061: /**
062: * Constructs a subject confirmation element from an existing
063: * XML block.
064: *
065: * @param SubjectConfirmationDataElement a DOM Element representing the
066: * <code>SubjectConfirmationData</code> object.
067: * @throws SAMLException
068: */
069: public static SubjectConfirmationDataType fromElement(
070: org.w3c.dom.Element element) throws SAMLException {
071: try {
072: JAXBContext jc = SAML20JAXBUtil.getJAXBContext();
073:
074: javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
075: return (SubjectConfirmationDataType) u.unmarshal(element);
076: } catch (Exception ex) {
077: throw new SAMLException(ex.getMessage());
078: }
079: }
080:
081: /**
082: * Constructs an <code>SubjectConfirmationData</code> instance.
083: *
084: * @param confirmationMethods A set of <code>confirmationMethods</code>
085: * each of which is a URI (String) that identifies a protocol
086: * used to authenticate a <code>Subject</code>. Please refer to
087: * <code>draft-sstc-core-25</code> Section 7 for
088: * a list of URIs identifying common authentication protocols.
089: * @param SubjectConfirmationDataData Additional authentication information to
090: * be used by a specific authentication protocol. Can be passed as
091: * null if there is no <code>SubjectConfirmationDataData</code> for the
092: * <code>SubjectConfirmationData</code> object.
093: * @param keyInfo An XML signature element that specifies a cryptographic
094: * key held by the <code>Subject</code>.
095: * @exception SAMLException if the input data is invalid or
096: * <code>confirmationMethods</code> is empty.
097: */
098: public SubjectConfirmationData(String address, String inResponseTo,
099: GregorianCalendar notBefore,
100: GregorianCalendar notOnOrAfter, String recipient,
101: Element keyInfo) throws SAMLException {
102:
103: // JAXBContext jc = null;
104: // javax.xml.bind.Unmarshaller u = null;
105: //
106: // //Unmarshal to JAXB KeyInfo Object and set it
107: // try {
108: // jc = SAML20JAXBUtil.getJAXBContext();
109: // u = jc.createUnmarshaller();
110: // } catch ( Exception ex) {
111: // throw new SAMLException(ex.getMessage());
112: // }
113:
114: // try {
115: // if ( keyInfo != null) {
116: // setKeyInfo((KeyInfoType)((JAXBElement)u.unmarshal(keyInfo)).getValue());
117: // }
118: // if ( SubjectConfirmationDataData != null) {
119: // setSubjectConfirmationDataData((SubjectConfirmationDataType)((JAXBElement)u.unmarshal(SubjectConfirmationDataData)).getValue());
120: // }
121: // } catch (Exception ex) {
122: // // log here
123: // throw new SAMLException(ex);
124: // }
125: setAddress(address);
126: setInResponseTo(inResponseTo);
127: if (notBefore != null) {
128: try {
129: DatatypeFactory factory = DatatypeFactory.newInstance();
130: setNotBefore(factory.newXMLGregorianCalendar(notBefore));
131: } catch (DatatypeConfigurationException ex) {
132: //ignore
133: }
134: }
135:
136: if (notOnOrAfter != null) {
137: try {
138: DatatypeFactory factory = DatatypeFactory.newInstance();
139: setNotOnOrAfter(factory
140: .newXMLGregorianCalendar(notOnOrAfter));
141: } catch (DatatypeConfigurationException ex) {
142: //ignore
143: }
144: }
145:
146: setRecipient(recipient);
147:
148: if (keyInfo != null) {
149: this.getContent().add(keyInfo);
150: }
151: }
152: }
|