001: /*
002: * $Id: AuthnStatement.java,v 1.3 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: import com.sun.xml.wss.logging.LogDomainConstants;
031: import com.sun.xml.wss.saml.internal.saml20.jaxb20.AuthnStatementType;
032: import com.sun.xml.wss.saml.util.SAML20JAXBUtil;
033: import java.util.GregorianCalendar;
034: import javax.xml.datatype.DatatypeConfigurationException;
035: import javax.xml.datatype.DatatypeFactory;
036: import org.w3c.dom.Element;
037: import java.util.logging.Logger;
038:
039: import javax.xml.bind.JAXBContext;
040:
041: /**
042: * The <code>AuthnStatement</code> element supplies a
043: * statement by the issuer that its subject was authenticated by a
044: * particular means at a particular time. The
045: * <code>AuthnStatement</code> element is of type
046: * <code>AuthnStatementType</code>, which extends the
047: * <code>SubjectStatementAbstractType</code> with the additional element and
048: * attributes.
049: */
050: public class AuthnStatement extends AuthnStatementType implements
051: com.sun.xml.wss.saml.AuthnStatement {
052:
053: protected static final Logger log = Logger.getLogger(
054: LogDomainConstants.WSS_API_DOMAIN,
055: LogDomainConstants.WSS_API_DOMAIN_BUNDLE);
056:
057: /**
058: *Default constructor
059: */
060: protected AuthnStatement() {
061: super ();
062: }
063:
064: /**
065: * This constructor builds an authentication statement element from an
066: * existing XML block.
067: *
068: * @param element representing a DOM tree element.
069: * @exception SAMLException if there is an error in the sender or in the
070: * element definition.
071: */
072: public static AuthnStatementType fromElement(Element element)
073: throws SAMLException {
074: try {
075: JAXBContext jc = SAML20JAXBUtil.getJAXBContext();
076:
077: javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
078: return (AuthnStatementType) u.unmarshal(element);
079: } catch (Exception ex) {
080: throw new SAMLException(ex.getMessage());
081: }
082: }
083:
084: // private void setAuthnContext(AuthnContext authnContext) {
085: // this.authnContext = authnContext;
086: // }
087:
088: /**
089: * Constructor for authentication statement
090: *
091: * @param authMethod (optional) A String specifies the type of authentication
092: * that took place.
093: * @param authInstant (optional) A GregorianCalendar specifies the time at which the
094: * authentication that took place.
095: * @param subject (required) A Subject object
096: * @param subjectLocality (optional) A <code>SubjectLocality</code> object.
097: * @param authorityBinding (optional) A List of <code>AuthorityBinding</code>
098: * objects.
099: * @exception SAMLException if there is an error in the sender.
100: */
101: public AuthnStatement(GregorianCalendar authInstant,
102: SubjectLocality subjectLocality, AuthnContext authnContext) {
103:
104: if (authInstant != null) {
105: try {
106: DatatypeFactory factory = DatatypeFactory.newInstance();
107: setAuthnInstant(factory
108: .newXMLGregorianCalendar(authInstant));
109: } catch (DatatypeConfigurationException ex) {
110: //ignore
111: }
112: }
113:
114: if (subjectLocality != null)
115: setSubjectLocality(subjectLocality);
116:
117: if (authnContext != null)
118: setAuthnContext(authnContext);
119: }
120: }
|