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