001: /*
002: * $Id: DirectReference.java,v 1.4 2007/01/08 16:06:12 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.core.reference;
028:
029: import java.util.logging.Level;
030: import java.util.logging.Logger;
031:
032: import javax.xml.soap.SOAPElement;
033: import javax.xml.soap.SOAPException;
034:
035: import com.sun.xml.wss.impl.MessageConstants;
036: import com.sun.xml.wss.logging.LogDomainConstants;
037: import com.sun.xml.wss.impl.XMLUtil;
038: import com.sun.xml.wss.XWSSecurityException;
039: import com.sun.xml.wss.core.ReferenceElement;
040:
041: /**
042: * @author Vishal Mahajan
043: */
044: public class DirectReference extends ReferenceElement {
045:
046: protected static final Logger log = Logger.getLogger(
047: LogDomainConstants.WSS_API_DOMAIN,
048: LogDomainConstants.WSS_API_DOMAIN_BUNDLE);
049:
050: /**
051: * Creates a DirectReference element.
052: */
053: public DirectReference() throws XWSSecurityException {
054: try {
055: setSOAPElement(soapFactory.createElement("Reference",
056: "wsse", MessageConstants.WSSE_NS));
057: } catch (SOAPException e) {
058: log.log(Level.SEVERE, "WSS0750.soap.exception",
059: new Object[] { "wsse:Reference", e.getMessage() });
060: throw new XWSSecurityException(e);
061: }
062: }
063:
064: /**
065: * Takes a SOAPElement and checks if it has the right name.
066: */
067: public DirectReference(SOAPElement element, boolean isBSP)
068: throws XWSSecurityException {
069: setSOAPElement(element);
070: if (!(element.getLocalName().equals("Reference") && XMLUtil
071: .inWsseNS(element))) {
072: log.log(Level.SEVERE, "WSS0751.invalid.direct.reference",
073: "{" + element.getNamespaceURI() + "}"
074: + element.getLocalName());
075: throw new XWSSecurityException(
076: "Invalid DirectReference passed");
077: }
078:
079: if (isBSP && (getURI() == null)) {
080: throw new XWSSecurityException(
081: "Violation of BSP R3062"
082: + ": A wsse:Reference element in a SECURITY_TOKEN_REFERENCE MUST specify a URI attribute");
083: }
084: }
085:
086: public DirectReference(SOAPElement element)
087: throws XWSSecurityException {
088: this (element, false);
089: }
090:
091: /**
092: * If this attr is not present, returns null.
093: */
094: public String getValueType() {
095: String valueType = getAttribute("ValueType");
096: if (valueType.equals(""))
097: return null;
098: return valueType;
099: }
100:
101: public void setValueType(String valueType) {
102: setAttribute("ValueType", valueType);
103: }
104:
105: /**
106: * @return URI attr value.
107: * If this attr is not present, returns null.
108: */
109: public String getURI() {
110: String uri = getAttribute("URI");
111: if (uri.equals(""))
112: return null;
113: return uri;
114: }
115:
116: /**
117: * @param uri Value to be assigned to URI attr.
118: */
119: public void setURI(String uri) {
120: setAttribute("URI", uri);
121: }
122:
123: /**
124: * @param uri Value to be assigned to URI attr.
125: */
126: public void setSCTURI(String uri, String instance) {
127: setAttribute("URI", uri);
128: //setAttributeNS(MessageConstants.WSSC_NS, MessageConstants.WSSC_PREFIX + ":Instance" , instance);
129: setAttribute("ValueType", MessageConstants.SCT_VALUETYPE);
130: }
131: }
|