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.processor;
024:
025: import com.sun.xml.ws.security.opt.impl.JAXBFilterProcessingContext;
026: import com.sun.xml.wss.BasicSecurityProfile;
027: import javax.xml.namespace.QName;
028: import javax.xml.stream.StreamFilter;
029: import javax.xml.stream.XMLStreamReader;
030:
031: /**
032: *
033: * @author Ashutosh.Shahi@sun.com
034: */
035: public class TimestampProcessor implements StreamFilter {
036:
037: private String created = null;
038: private String expires = null;
039: private String currentElement = "";
040: private JAXBFilterProcessingContext context = null;
041: private static String EXPIRES = "Expires".intern();
042: private static String CREATED = "Created".intern();
043:
044: /** Creates a new instance of TimestampProcessor */
045: public TimestampProcessor(JAXBFilterProcessingContext ctx) {
046: this .context = ctx;
047: }
048:
049: public boolean accept(XMLStreamReader reader) {
050: if (reader.getEventType() == XMLStreamReader.START_ELEMENT) {
051: if ("Created".equals(reader.getLocalName())) {
052: currentElement = CREATED;
053: if (context.isBSP() && created != null) {
054: BasicSecurityProfile.log_bsp_3203();
055: }
056: if (context.isBSP() && hasValueType(reader)) {
057: BasicSecurityProfile.log_bsp_3225();
058: }
059:
060: } else if ("Expires".equals(reader.getLocalName())) {
061: if (context.isBSP() && expires != null) {
062: BasicSecurityProfile.log_bsp_3224();
063: }
064: if (context.isBSP() && created == null) {
065: BasicSecurityProfile.log_bsp_3221();
066: }
067:
068: if (context.isBSP() && hasValueType(reader)) {
069: BasicSecurityProfile.log_bsp_3226();
070: }
071: currentElement = EXPIRES;
072: } else {
073: //throw Unsupportedexception
074: // if(context.isBSP() && ! "Timestamp".equals(reader.getLocalName())){
075: // BasicSecurityProfile.log_bsp_3222(reader.getLocalName());
076: // }
077: }
078: }
079:
080: if (reader.getEventType() == XMLStreamReader.CHARACTERS) {
081: if (currentElement == CREATED) {
082: created = reader.getText();
083: currentElement = "";
084: } else if (currentElement == EXPIRES) {
085: expires = reader.getText();
086: currentElement = "";
087: }
088: }
089: return true;
090: }
091:
092: public String getCreated() {
093: return created;
094: }
095:
096: public String getExpires() {
097: return expires;
098: }
099:
100: private boolean hasValueType(XMLStreamReader reader) {
101: for (int i = 0; i < reader.getAttributeCount(); i++) {
102: QName name = reader.getAttributeName(i);
103: if (name != null && "ValueType".equals(name.getLocalPart())) {
104: return true;
105: }
106: }
107: return false;
108: }
109: }
|