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 in
005: * compliance with the License.
006: *
007: * You can obtain a copy of the license at
008: * https://glassfish.dev.java.net/public/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 Notice in each file and include the License file
014: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
015: * If applicable, add the following below the CDDL Header,
016: * with the fields enclosed by brackets [] replaced by
017: * you own identifying information:
018: * "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
021: */
022:
023: package com.sun.xml.ws.security.opt.impl.incoming;
024:
025: import com.sun.xml.stream.buffer.XMLStreamBuffer;
026: import com.sun.xml.stream.buffer.XMLStreamBufferException;
027: import com.sun.xml.stream.buffer.XMLStreamBufferMark;
028: import com.sun.xml.stream.buffer.stax.StreamReaderBufferCreator;
029: import com.sun.xml.ws.security.opt.api.NamespaceContextInfo;
030: import com.sun.xml.ws.security.opt.api.PolicyBuilder;
031: import com.sun.xml.ws.security.opt.api.SecurityElementWriter;
032: import com.sun.xml.ws.security.opt.api.SecurityHeaderElement;
033: import com.sun.xml.ws.security.opt.api.TokenValidator;
034: import com.sun.xml.ws.security.opt.api.tokens.Timestamp;
035: import com.sun.xml.ws.security.opt.impl.JAXBFilterProcessingContext;
036: import com.sun.xml.ws.security.opt.impl.incoming.processor.TimestampProcessor;
037: import com.sun.xml.ws.security.opt.impl.util.XMLStreamReaderFactory;
038: import com.sun.xml.wss.ProcessingContext;
039: import com.sun.xml.wss.XWSSecurityException;
040: import com.sun.xml.wss.impl.MessageConstants;
041: import com.sun.xml.wss.impl.c14n.AttributeNS;
042: import com.sun.xml.wss.impl.policy.mls.TimestampPolicy;
043: import com.sun.xml.wss.impl.policy.mls.WSSPolicy;
044: import java.io.OutputStream;
045: import java.util.HashMap;
046: import java.util.List;
047: import javax.xml.namespace.QName;
048: import javax.xml.stream.XMLStreamException;
049: import javax.xml.stream.XMLStreamReader;
050: import javax.xml.stream.XMLStreamWriter;
051:
052: /**
053: *
054: * @author Ashutosh.Shahi@sun.com
055: */
056:
057: public class TimestampHeader implements Timestamp,
058: SecurityHeaderElement, TokenValidator, PolicyBuilder,
059: NamespaceContextInfo, SecurityElementWriter {
060:
061: private String localPart = null;
062: private String namespaceURI = null;
063: private String id = "";
064:
065: private XMLStreamBuffer mark = null;
066: private TimestampProcessor filter = null;
067:
068: private TimestampPolicy tsPolicy = null;
069:
070: private HashMap<String, String> nsDecls;
071:
072: /** Creates a new instance of TimestampHeader */
073: public TimestampHeader(XMLStreamReader reader,
074: StreamReaderBufferCreator creator, HashMap nsDecls,
075: JAXBFilterProcessingContext ctx) throws XMLStreamException,
076: XMLStreamBufferException {
077: localPart = reader.getLocalName();
078: namespaceURI = reader.getNamespaceURI();
079: id = reader.getAttributeValue(MessageConstants.WSU_NS, "Id");
080: this .filter = new TimestampProcessor(ctx);
081: mark = new XMLStreamBufferMark(nsDecls, creator);
082: XMLStreamReader tsReader = XMLStreamReaderFactory
083: .createFilteredXMLStreamReader(reader, filter);
084: creator.createElementFragment(tsReader, true);
085:
086: tsPolicy = new TimestampPolicy();
087: tsPolicy.setUUID(id);
088: tsPolicy.setCreationTime(filter.getCreated());
089: tsPolicy.setExpirationTime(filter.getExpires());
090:
091: this .nsDecls = nsDecls;
092: }
093:
094: public void validate(ProcessingContext context)
095: throws XWSSecurityException {
096: context.getSecurityEnvironment().validateTimestamp(
097: context.getExtraneousProperties(), filter.getCreated(),
098: filter.getExpires(), tsPolicy.getMaxClockSkew(),
099: tsPolicy.getTimestampFreshness());
100: }
101:
102: public WSSPolicy getPolicy() {
103: return tsPolicy;
104: }
105:
106: public void setCreated(String created) {
107: throw new UnsupportedOperationException();
108: }
109:
110: public void setExpires(String expires) {
111: throw new UnsupportedOperationException();
112: }
113:
114: public String getCreatedValue() {
115: return filter.getCreated();
116: }
117:
118: public String getExpiresValue() {
119: return filter.getExpires();
120: }
121:
122: public boolean refersToSecHdrWithId(String id) {
123: throw new UnsupportedOperationException();
124: }
125:
126: public String getId() {
127: return id;
128: }
129:
130: public void setId(String id) {
131: throw new UnsupportedOperationException();
132: }
133:
134: public String getNamespaceURI() {
135: return namespaceURI;
136: }
137:
138: public String getLocalPart() {
139: return localPart;
140: }
141:
142: public String getAttribute(String nsUri, String localName) {
143: throw new UnsupportedOperationException();
144: }
145:
146: public String getAttribute(QName name) {
147: throw new UnsupportedOperationException();
148: }
149:
150: public XMLStreamReader readHeader() throws XMLStreamException {
151: return mark.readAsXMLStreamReader();
152: }
153:
154: public void writeTo(OutputStream os) {
155: throw new UnsupportedOperationException();
156: }
157:
158: public void writeTo(XMLStreamWriter streamWriter)
159: throws XMLStreamException {
160: mark.writeToXMLStreamWriter(streamWriter);
161: }
162:
163: public byte[] canonicalize(String algorithm,
164: List<AttributeNS> namespaceDecls) {
165: throw new UnsupportedOperationException();
166: }
167:
168: public boolean isCanonicalized() {
169: throw new UnsupportedOperationException();
170: }
171:
172: public HashMap<String, String> getInscopeNSContext() {
173: return nsDecls;
174: }
175:
176: public void writeTo(javax.xml.stream.XMLStreamWriter streamWriter,
177: HashMap props) throws javax.xml.stream.XMLStreamException {
178: throw new UnsupportedOperationException();
179: }
180:
181: }
|