001: /*
002: * $Id: Subject.java,v 1.3 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.ObjectFactory;
033: import com.sun.xml.wss.saml.internal.saml20.jaxb20.SubjectType;
034: import com.sun.xml.wss.saml.util.SAML20JAXBUtil;
035: import java.util.logging.Logger;
036:
037: import javax.xml.bind.JAXBContext;
038:
039: /**
040: * The <code>Subject</code> element specifies one or more subjects. It contains either or
041: both of the following elements:<code>NameID</code>;
042: An identification of a subject by its name and security domain.
043: <code>SubjectConfirmation</code>;
044: Information that allows the subject to be authenticated.
045:
046: If a <code>Subject</code> element contains more than one subject specification,
047: the issuer is asserting that the surrounding statement is true for
048: all of the subjects specified. For example, if both a
049: <code>NameID</code> and a <code>SubjectConfirmation</code> element are
050: present, the issuer is asserting that the statement is true of both subjects
051: being identified. A <Subject> element SHOULD NOT identify more than one
052: principal.
053: */
054: public class Subject extends SubjectType implements
055: com.sun.xml.wss.saml.Subject {
056:
057: protected static final Logger log = Logger.getLogger(
058: LogDomainConstants.WSS_API_DOMAIN,
059: LogDomainConstants.WSS_API_DOMAIN_BUNDLE);
060:
061: /**
062: * Constructs a Subject object from a <code>NameID</code>
063: * object and a <code>SubjectConfirmation</code> object.
064: *
065: * @param NameID <code>NameID</code> object.
066: * @param subjectConfirmation <code>SubjectConfirmation</code> object.
067: * @exception SAMLException if it could not process the
068: * Element properly, implying that there is an error in the
069: * sender or in the element definition.
070: */
071: public Subject(NameID nameId,
072: SubjectConfirmation subjectConfirmation) {
073: ObjectFactory factory = new ObjectFactory();
074:
075: if (nameId != null)
076: getContent().add(factory.createNameID(nameId));
077:
078: if (subjectConfirmation != null)
079: getContent()
080: .add(
081: factory
082: .createSubjectConfirmation(subjectConfirmation));
083: }
084:
085: /**
086: * This constructor builds a subject element from an existing XML block
087: * which has already been built into a DOM.
088: *
089: * @param subjectElement An Element representing DOM tree for Subject object
090: * @exception SAMLException if it could not process the Element properly,
091: * implying that there is an error in the sender or in the
092: * element definition.
093: */
094: public static SubjectType fromElement(org.w3c.dom.Element element)
095: throws SAMLException {
096: try {
097: JAXBContext jc = SAML20JAXBUtil.getJAXBContext();
098:
099: javax.xml.bind.Unmarshaller u = jc.createUnmarshaller();
100: return (SubjectType) u.unmarshal(element);
101: } catch (Exception ex) {
102: throw new SAMLException(ex.getMessage());
103: }
104: }
105: }
|