ws-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gi...@apache.org
Subject svn commit: r1172285 [16/48] - in /webservices/wss4j/branches/swssf: ./ cxf-integration/ cxf-integration/src/ cxf-integration/src/main/ cxf-integration/src/main/java/ cxf-integration/src/main/java/org/ cxf-integration/src/main/java/org/swssf/ cxf-integ...
Date Sun, 18 Sep 2011 13:51:36 GMT
Added: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSPasswordCallback.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSPasswordCallback.java?rev=1172285&view=auto
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSPasswordCallback.java (added)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSPasswordCallback.java Sun Sep 18 13:51:23 2011
@@ -0,0 +1,228 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.swssf.ext;
+
+import org.w3c.dom.Element;
+
+import javax.security.auth.callback.Callback;
+
+/**
+ * class lent from apache wss4j
+ */
+
+/**
+ * Simple class to provide a password callback mechanism.
+ * <p/>
+ * It uses the JAAS authentication mechanisms and callback methods.
+ * In addition to the identifier (user name) this class also provides
+ * information what type of information the callback <code>handle</code>
+ * method shall provide.
+ * <p/>
+ * The <code> WSPasswordCallback</code> class defines the following usage
+ * codes:
+ * <ul>
+ * <li><code>UNKNOWN</code> - an unknown usage. Never used by the WSS4J
+ * implementation and shall be treated as an error by the <code>handle
+ * </code> method.</li>
+ * <li><code>DECRYPT</code> - need a password to get the private key of
+ * this identifier (username) from the keystore. WSS4J uses this private
+ * key to decrypt the session (symmetric) key. Because the encryption
+ * method uses the public key to encrypt the session key it needs no
+ * password (a public key is usually not protected by a password).</li>
+ * <li><code>USERNAME_TOKEN</code> - need the password to fill in or to
+ * verify a <code>UsernameToken</code>.</li>
+ * <li><code>SIGNATURE</code> - need the password to get the private key of
+ * this identifier (username) from    the keystore. WSS4J uses this private
+ * key to produce a signature. The signature verification uses the public
+ * key to verify the signature.</li>
+ * <li><code>KEY_NAME</code> - need the <i>key</i>, not the password,
+ * associated with the identifier. WSS4J uses this key to encrypt or
+ * decrypt parts of the SOAP request. Note, the key must match the
+ * symmetric encryption/decryption algorithm specified (refer to
+ * {@link org.apache.ws.security.handler.WSHandlerConstants#ENC_SYM_ALGO}).</li>
+ * <li><code>USERNAME_TOKEN_UNKNOWN</code> - either an not specified
+ * password type or a password type passwordText. In these both cases <b>only</b>
+ * the password variable is <b>set</b>. The callback class now may check if
+ * the username and password match. If they don't match the callback class must
+ * throw an exception. The exception can be a UnsupportedCallbackException or
+ * an IOException.</li>
+ * <li><code>SECURITY_CONTEXT_TOKEN</code> - need the key to to be associated
+ * with a <code>wsc:SecurityContextToken</code>.</li>
+ * </ul>
+ *
+ * @author Werner Dittmann (Werner.Dittmann@siemens.com).
+ */
+
+public class WSPasswordCallback implements Callback {
+
+    public enum Usage {
+        UNKNOWN,
+        DECRYPT,
+        USERNAME_TOKEN,
+        SIGNATURE,
+        KEY_NAME,
+        USERNAME_TOKEN_UNKNOWN,
+        SECURITY_CONTEXT_TOKEN,
+        CUSTOM_TOKEN,
+        ENCRYPTED_KEY_TOKEN,
+        SECRET_KEY,
+    }
+
+    private String identifier;
+    private String password;
+    private byte[] key;
+    private Usage usage;
+    private String type;
+    private Element customToken;
+
+    /**
+     * Constructor.
+     *
+     * @param id The application called back must supply the password for
+     *           this identifier.
+     */
+    public WSPasswordCallback(String id, Usage usage) {
+        this(id, null, null, usage);
+    }
+
+    /**
+     * Constructor.
+     *
+     * @param id The application called back must supply the password for
+     *           this identifier.
+     */
+    public WSPasswordCallback(String id, String pw, String type, Usage usage) {
+        identifier = id;
+        password = pw;
+        this.type = type;
+        this.usage = usage;
+    }
+
+    /**
+     * Get the identifier.
+     * <p/>
+     *
+     * @return The identifier
+     */
+    public String getIdentifier() {
+        return identifier;
+    }
+
+    /**
+     * Get the identifier.
+     * <p/>
+     *
+     * @return The identifier
+     * @deprecated use getIdentifier() instead
+     */
+    public String getIdentifer() {
+        return getIdentifier();
+    }
+
+    /**
+     * Extended callback interface allows for setting the username as well.
+     * Callback functions can change the identifier, this is intended in the usernametoken scenario
+     * where the usernametoken denotes the identity, but a fixed identity for signing is used
+     * The initial value is that from the configuration file. If this method is not called, the
+     * configured identity is used.
+     *
+     * @param ident The identity.
+     */
+    public void setIdentifier(String ident) {
+        this.identifier = ident;
+    }
+
+    /**
+     * Set the password.
+     * <p/>
+     *
+     * @param passwd is the password associated to the identifier
+     */
+    public void setPassword(String passwd) {
+        password = passwd;
+    }
+
+    /**
+     * Get the password.
+     * <p/>
+     *
+     * @return The password
+     */
+    public String getPassword() {
+        return password;
+    }
+
+    /**
+     * Set the Key.
+     * <p/>
+     *
+     * @param key is the key associated to the identifier
+     */
+    public void setKey(byte[] key) {
+        this.key = key;
+    }
+
+    /**
+     * Get the key.
+     * <p/>
+     *
+     * @return The key
+     */
+    public byte[] getKey() {
+        return this.key;
+    }
+
+    /**
+     * Get the usage.
+     * <p/>
+     *
+     * @return The usage for this callback
+     */
+    public Usage getUsage() {
+        return usage;
+    }
+
+    /**
+     * The password type is only relevant for usage <code>USERNAME_TOKEN</code>
+     * and <code>USERNAME_TOKEN_UNKNOWN</code>.
+     *
+     * @return Returns the passwordType.
+     */
+    public String getPasswordType() {
+        return type;
+    }
+
+    /**
+     * The key type is only relevant for usage <code>ENCRYPTED_KEY_TOKEN</code>
+     *
+     * @return Returns the type.
+     */
+    public String getKeyType() {
+        return type;
+    }
+
+    public Element getCustomToken() {
+        return customToken;
+    }
+
+    public void setCustomToken(Element customToken) {
+        this.customToken = customToken;
+    }
+}
\ No newline at end of file

Propchange: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSPasswordCallback.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSSConfigurationException.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSSConfigurationException.java?rev=1172285&view=auto
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSSConfigurationException.java (added)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSSConfigurationException.java Sun Sep 18 13:51:23 2011
@@ -0,0 +1,56 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.swssf.ext;
+
+/**
+ * Exception when configuration errors are detected
+ *
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class WSSConfigurationException extends WSSecurityException {
+
+    public WSSConfigurationException(ErrorCode errorCode, String msgId, Object[] args, Throwable exception) {
+        super(errorCode, msgId, exception, args);
+    }
+
+    public WSSConfigurationException(ErrorCode errorCode, String msgId, Throwable exception) {
+        super(errorCode, msgId, exception);
+    }
+
+    public WSSConfigurationException(ErrorCode errorCode, String msgId, Object[] args) {
+        super(errorCode, msgId, args);
+    }
+
+    public WSSConfigurationException(ErrorCode errorCode, String msgId) {
+        super(errorCode, msgId);
+    }
+
+    public WSSConfigurationException(ErrorCode errorCode) {
+        super(errorCode);
+    }
+
+    public WSSConfigurationException(String errorMessage) {
+        super(errorMessage);
+    }
+
+    public WSSConfigurationException(String errorMessage, Throwable t) {
+        super(errorMessage, t);
+    }
+}

Propchange: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSSConfigurationException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSSecurityException.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSSecurityException.java?rev=1172285&view=auto
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSSecurityException.java (added)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSSecurityException.java Sun Sep 18 13:51:23 2011
@@ -0,0 +1,248 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.swssf.ext;
+
+import javax.xml.namespace.QName;
+import java.rmi.RemoteException;
+import java.text.MessageFormat;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.MissingResourceException;
+import java.util.ResourceBundle;
+
+/**
+ * class lent from apache wss4j
+ */
+
+/**
+ * Exception class for WS-Security.
+ * <p/>
+ *
+ * @author Davanum Srinivas (dims@yahoo.com).
+ */
+public class WSSecurityException extends RemoteException {
+
+    public enum ErrorCode {
+        FAILURE,
+        UNSUPPORTED_SECURITY_TOKEN,
+        UNSUPPORTED_ALGORITHM,
+        INVALID_SECURITY,
+        INVALID_SECURITY_TOKEN,
+        FAILED_AUTHENTICATION,
+        FAILED_CHECK,
+        SECURITY_TOKEN_UNAVAILABLE,
+        MESSAGE_EXPIRED,
+        FAILED_ENCRYPTION,
+        FAILED_SIGNATURE,
+    }
+
+    private static ResourceBundle resources;
+    /*
+     * This is an Integer -> QName map. Its function is to map the integer error codes
+     * given above to the QName fault codes as defined in the SOAP Message Security 1.1
+     * specification. A client application can simply call getFaultCode rather than do
+     * any parsing of the error code. Note that there are no mappings for "FAILURE",
+     * "FAILED_ENCRYPTION" and "FAILED_SIGNATURE" as these are not standard error messages.
+     */
+    private static final Map<ErrorCode, QName> FAULT_CODE_MAP = new HashMap<ErrorCode, QName>();
+
+    static {
+        try {
+            resources = ResourceBundle.getBundle("messages.errors");
+        } catch (MissingResourceException e) {
+            throw new RuntimeException(e.getMessage(), e);
+        }
+
+        FAULT_CODE_MAP.put(
+                ErrorCode.UNSUPPORTED_SECURITY_TOKEN,
+                Constants.UNSUPPORTED_SECURITY_TOKEN
+        );
+        FAULT_CODE_MAP.put(
+                ErrorCode.UNSUPPORTED_ALGORITHM,
+                Constants.UNSUPPORTED_ALGORITHM
+        );
+        FAULT_CODE_MAP.put(
+                ErrorCode.INVALID_SECURITY,
+                Constants.INVALID_SECURITY
+        );
+        FAULT_CODE_MAP.put(
+                ErrorCode.INVALID_SECURITY_TOKEN,
+                Constants.INVALID_SECURITY_TOKEN
+        );
+        FAULT_CODE_MAP.put(
+                ErrorCode.FAILED_AUTHENTICATION,
+                Constants.FAILED_AUTHENTICATION
+        );
+        FAULT_CODE_MAP.put(
+                ErrorCode.FAILED_CHECK,
+                Constants.FAILED_CHECK
+        );
+        FAULT_CODE_MAP.put(
+                ErrorCode.FAILED_SIGNATURE,
+                Constants.FAILED_CHECK
+        );
+        FAULT_CODE_MAP.put(
+                ErrorCode.FAILED_ENCRYPTION,
+                Constants.FAILED_CHECK
+        );
+        FAULT_CODE_MAP.put(
+                ErrorCode.SECURITY_TOKEN_UNAVAILABLE,
+                Constants.SECURITY_TOKEN_UNAVAILABLE
+        );
+        FAULT_CODE_MAP.put(
+                ErrorCode.MESSAGE_EXPIRED,
+                Constants.MESSAGE_EXPIRED
+        );
+    }
+
+    private ErrorCode errorCode;
+
+    /**
+     * Constructor.
+     * <p/>
+     *
+     * @param errorCode
+     * @param msgId
+     * @param exception
+     * @param arguments
+     */
+    public WSSecurityException(ErrorCode errorCode, String msgId, Throwable exception, Object... arguments) {
+        super(getMessage(errorCode, msgId, arguments), exception);
+        this.errorCode = errorCode;
+    }
+
+    /**
+     * Constructor.
+     * <p/>
+     *
+     * @param errorCode
+     * @param msgId
+     * @param exception
+     */
+    public WSSecurityException(ErrorCode errorCode, String msgId, Throwable exception) {
+        super(getMessage(errorCode, msgId), exception);
+        this.errorCode = errorCode;
+    }
+
+    public WSSecurityException(ErrorCode errorCode, Throwable exception) {
+        super(getMessage(errorCode, null), exception);
+        this.errorCode = errorCode;
+    }
+
+    /**
+     * Constructor.
+     * <p/>
+     *
+     * @param errorCode
+     * @param msgId
+     * @param arguments
+     */
+    public WSSecurityException(ErrorCode errorCode, String msgId, Object... arguments) {
+        super(getMessage(errorCode, msgId, arguments));
+        this.errorCode = errorCode;
+    }
+
+    /**
+     * Constructor.
+     * <p/>
+     *
+     * @param errorCode
+     * @param msgId
+     */
+    public WSSecurityException(ErrorCode errorCode, String msgId) {
+        this(errorCode, msgId, (Object[]) null);
+    }
+
+    /**
+     * Constructor.
+     * <p/>
+     *
+     * @param errorCode
+     */
+    public WSSecurityException(ErrorCode errorCode) {
+        this(errorCode, null, (Object[]) null);
+    }
+
+    /**
+     * Constructor.
+     * <p/>
+     *
+     * @param errorMessage
+     */
+    public WSSecurityException(String errorMessage) {
+        super(errorMessage);
+    }
+
+    /**
+     * Constructor.
+     * <p/>
+     *
+     * @param errorMessage
+     */
+    public WSSecurityException(String errorMessage, Throwable t) {
+        super(errorMessage, t);
+    }
+
+    /**
+     * Get the error code.
+     * <p/>
+     *
+     * @return error code of this exception See values above.
+     */
+    public ErrorCode getErrorCode() {
+        return this.errorCode;
+    }
+
+    /**
+     * Get the fault code QName for this associated error code.
+     * <p/>
+     *
+     * @return the fault code QName of this exception
+     */
+    public javax.xml.namespace.QName getFaultCode() {
+        QName ret = FAULT_CODE_MAP.get(this.errorCode);
+        if (ret != null) {
+            return ret;
+        }
+        return null;
+    }
+
+    /**
+     * get the message from resource bundle.
+     * <p/>
+     *
+     * @param errorCode
+     * @param msgId
+     * @param arguments
+     * @return the message translated from the property (message) file.
+     */
+    private static String getMessage(ErrorCode errorCode, String msgId, Object... arguments) {
+        String msg = null;
+        try {
+            msg = resources.getString(String.valueOf(errorCode.ordinal()));
+            if (msgId != null) {
+                return msg += (" (" + MessageFormat.format(resources.getString(msgId), arguments) + ")");
+            }
+        } catch (MissingResourceException e) {
+            throw new RuntimeException("Undefined '" + msgId + "' resource property", e);
+        }
+        return msg;
+    }
+}
\ No newline at end of file

Propchange: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/WSSecurityException.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/XMLEventNS.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/XMLEventNS.java?rev=1172285&view=auto
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/XMLEventNS.java (added)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/XMLEventNS.java Sun Sep 18 13:51:23 2011
@@ -0,0 +1,134 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.swssf.ext;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.Location;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.Characters;
+import javax.xml.stream.events.EndElement;
+import javax.xml.stream.events.StartElement;
+import javax.xml.stream.events.XMLEvent;
+import java.io.Writer;
+import java.util.List;
+
+/**
+ * A Customized XMLEvent class to provide all Namespaces and Attributes from the current scope
+ *
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class XMLEventNS implements XMLEvent {
+
+    private XMLEvent xmlEvent;
+    private List<ComparableNamespace>[] namespaceList;
+    List<ComparableAttribute>[] attributeList;
+
+    public XMLEventNS(XMLEvent xmlEvent, List<ComparableNamespace>[] namespaceList, List<ComparableAttribute>[] attributeList) {
+        this.xmlEvent = xmlEvent;
+        this.namespaceList = namespaceList;
+        this.attributeList = attributeList;
+    }
+
+    /**
+     * Returns all Namespaces in the current scope
+     *
+     * @return The Namespaces as List
+     */
+    public List<ComparableNamespace>[] getNamespaceList() {
+        return namespaceList;
+    }
+
+    /**
+     * Returns all C14N relevant Attributes in the current scope
+     *
+     * @return The Attributes as List
+     */
+    public List<ComparableAttribute>[] getAttributeList() {
+        return attributeList;
+    }
+
+    public XMLEvent getCurrentEvent() {
+        return xmlEvent;
+    }
+
+    public int getEventType() {
+        return xmlEvent.getEventType();
+    }
+
+    public Location getLocation() {
+        return xmlEvent.getLocation();
+    }
+
+    public boolean isStartElement() {
+        return xmlEvent.isStartElement();
+    }
+
+    public boolean isAttribute() {
+        return xmlEvent.isAttribute();
+    }
+
+    public boolean isNamespace() {
+        return xmlEvent.isNamespace();
+    }
+
+    public boolean isEndElement() {
+        return xmlEvent.isEndElement();
+    }
+
+    public boolean isEntityReference() {
+        return xmlEvent.isEntityReference();
+    }
+
+    public boolean isProcessingInstruction() {
+        return xmlEvent.isProcessingInstruction();
+    }
+
+    public boolean isCharacters() {
+        return xmlEvent.isCharacters();
+    }
+
+    public boolean isStartDocument() {
+        return xmlEvent.isStartDocument();
+    }
+
+    public boolean isEndDocument() {
+        return xmlEvent.isEndDocument();
+    }
+
+    public StartElement asStartElement() {
+        return xmlEvent.asStartElement();
+    }
+
+    public EndElement asEndElement() {
+        return xmlEvent.asEndElement();
+    }
+
+    public Characters asCharacters() {
+        return xmlEvent.asCharacters();
+    }
+
+    public QName getSchemaType() {
+        return xmlEvent.getSchemaType();
+    }
+
+    public void writeAsEncodedUnicode(Writer writer) throws XMLStreamException {
+        xmlEvent.writeAsEncodedUnicode(writer);
+    }
+}

Propchange: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/ext/XMLEventNS.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/DocumentContextImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/DocumentContextImpl.java?rev=1172285&view=auto
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/DocumentContextImpl.java (added)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/DocumentContextImpl.java Sun Sep 18 13:51:23 2011
@@ -0,0 +1,157 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.swssf.impl;
+
+import org.swssf.ext.Constants;
+import org.swssf.ext.DocumentContext;
+
+import javax.xml.namespace.QName;
+import javax.xml.stream.XMLStreamConstants;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * A concrete DocumentContext Implementation
+ *
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class DocumentContextImpl implements DocumentContext, Cloneable {
+
+    private static final QName nullElement = new QName("", "");
+    private List<QName> path = new ArrayList<QName>(10);
+    private String encoding;
+
+    public String getEncoding() {
+        return encoding;
+    }
+
+    public void setEncoding(String encoding) {
+        this.encoding = encoding;
+    }
+
+    public String getSOAPMessageVersionNamespace() {
+        if (path.size() >= 1 && path.get(0).equals(Constants.TAG_soap11_Envelope)) {
+            return Constants.NS_SOAP11;
+        } else if (path.size() >= 1 && path.get(0).equals(Constants.TAG_soap12_Envelope)) {
+            return Constants.NS_SOAP12;
+        }
+        return null;
+    }
+
+    public void addPathElement(QName qName) {
+        path.add(qName);
+    }
+
+    public QName removePathElement() {
+        return path.remove(path.size() - 1);
+    }
+
+    protected void setPath(List<QName> path) {
+        this.path = path;
+    }
+
+    public List<QName> getPath() {
+        return path;
+    }
+
+    public QName getParentElement(int eventType) {
+        if (eventType == XMLStreamConstants.START_ELEMENT || eventType == XMLStreamConstants.END_ELEMENT) {
+            if (path.size() >= 2) {
+                return path.get(path.size() - 2);
+            } else {
+                return nullElement;
+            }
+        } else {
+            if (path.size() >= 1) {
+                return path.get(path.size() - 1);
+            } else {
+                return nullElement;
+            }
+        }
+    }
+
+    public boolean isInSOAPHeader() {
+        return (path.size() > 1
+                && path.get(1).getLocalPart().equals(Constants.TAG_soap_Header_LocalName)
+                && path.get(0).getNamespaceURI().equals(path.get(1).getNamespaceURI()));
+    }
+
+    public boolean isInSOAPBody() {
+        return (path.size() > 1
+                && path.get(1).getLocalPart().equals(Constants.TAG_soap_Body_LocalName)
+                && path.get(0).getNamespaceURI().equals(path.get(1).getNamespaceURI()));
+    }
+
+    public int getDocumentLevel() {
+        return path.size();
+    }
+
+    private boolean inSecurityHeader = false;
+
+    public boolean isInSecurityHeader() {
+        return inSecurityHeader;
+    }
+
+    public void setInSecurityHeader(boolean inSecurityHeader) {
+        this.inSecurityHeader = inSecurityHeader;
+    }
+
+    private int actualEncryptedContentCounter = 0;
+
+    public synchronized void setIsInEncryptedContent() {
+        this.actualEncryptedContentCounter++;
+    }
+
+    public synchronized void unsetIsInEncryptedContent() {
+        this.actualEncryptedContentCounter--;
+    }
+
+    public boolean isInEncryptedContent() {
+        return this.actualEncryptedContentCounter > 0;
+    }
+
+    private int actualSignedContentCounter = 0;
+
+    public synchronized void setIsInSignedContent() {
+        this.actualSignedContentCounter++;
+    }
+
+    public synchronized void unsetIsInSignedContent() {
+        this.actualSignedContentCounter--;
+    }
+
+    public boolean isInSignedContent() {
+        return this.actualSignedContentCounter > 0;
+    }
+
+    @Override
+    protected DocumentContextImpl clone() throws CloneNotSupportedException {
+        super.clone();
+        DocumentContextImpl documentContext = new DocumentContextImpl();
+        List<QName> subPath = new ArrayList<QName>();
+        subPath.addAll(this.path);
+        documentContext.setEncoding(this.encoding);
+        documentContext.setPath(subPath);
+        documentContext.setInSecurityHeader(isInSecurityHeader());
+        documentContext.actualEncryptedContentCounter = this.actualEncryptedContentCounter;
+        documentContext.actualSignedContentCounter = this.actualSignedContentCounter;
+        return documentContext;
+    }
+}

Propchange: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/DocumentContextImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/EncryptionPartDef.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/EncryptionPartDef.java?rev=1172285&view=auto
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/EncryptionPartDef.java (added)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/EncryptionPartDef.java Sun Sep 18 13:51:23 2011
@@ -0,0 +1,69 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.swssf.impl;
+
+import org.swssf.ext.SecurePart;
+
+import java.security.Key;
+
+/**
+ * EncryptionPartDef holds information about parts to be encrypt
+ *
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class EncryptionPartDef {
+
+    private SecurePart.Modifier modifier;
+    private Key symmetricKey;
+    private String keyId;
+    private String encRefId;
+
+    public SecurePart.Modifier getModifier() {
+        return modifier;
+    }
+
+    public void setModifier(SecurePart.Modifier modifier) {
+        this.modifier = modifier;
+    }
+
+    public Key getSymmetricKey() {
+        return symmetricKey;
+    }
+
+    public void setSymmetricKey(Key symmetricKey) {
+        this.symmetricKey = symmetricKey;
+    }
+
+    public String getKeyId() {
+        return keyId;
+    }
+
+    public void setKeyId(String keyId) {
+        this.keyId = keyId;
+    }
+
+    public String getEncRefId() {
+        return encRefId;
+    }
+
+    public void setEncRefId(String encRefId) {
+        this.encRefId = encRefId;
+    }
+}

Propchange: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/EncryptionPartDef.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/InputProcessorChainImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/InputProcessorChainImpl.java?rev=1172285&view=auto
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/InputProcessorChainImpl.java (added)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/InputProcessorChainImpl.java Sun Sep 18 13:51:23 2011
@@ -0,0 +1,215 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.swssf.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.swssf.ext.*;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.XMLEvent;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Implementation of a InputProcessorChain
+ *
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class InputProcessorChainImpl implements InputProcessorChain {
+
+    protected static final transient Log log = LogFactory.getLog(InputProcessorChainImpl.class);
+
+    private List<InputProcessor> inputProcessors = Collections.synchronizedList(new ArrayList<InputProcessor>());
+    private int startPos = 0;
+    private int curPos = 0;
+
+    private SecurityContext securityContext;
+    private DocumentContextImpl documentContext;
+
+    public InputProcessorChainImpl(SecurityContext securityContext) {
+        this(securityContext, 0);
+    }
+
+    public InputProcessorChainImpl(SecurityContext securityContext, int startPos) {
+        this(securityContext, new DocumentContextImpl(), startPos);
+    }
+
+    public InputProcessorChainImpl(SecurityContext securityContext, DocumentContextImpl documentContext) {
+        this(securityContext, documentContext, 0);
+    }
+
+    protected InputProcessorChainImpl(SecurityContext securityContext, DocumentContextImpl documentContextImpl, int startPos) {
+        this.securityContext = securityContext;
+        this.curPos = this.startPos = startPos;
+        documentContext = documentContextImpl;
+    }
+
+    public int getCurPos() {
+        return curPos;
+    }
+
+    public void setCurPos(int curPos) {
+        this.curPos = curPos;
+    }
+
+    public int getPosAndIncrement() {
+        return this.curPos++;
+    }
+
+    public void reset() {
+        setCurPos(startPos);
+    }
+
+    public SecurityContext getSecurityContext() {
+        return this.securityContext;
+    }
+
+    public DocumentContext getDocumentContext() {
+        return this.documentContext;
+    }
+
+    private void setInputProcessors(List<InputProcessor> inputProcessors) {
+        this.inputProcessors = inputProcessors;
+    }
+
+    public void addProcessor(InputProcessor newInputProcessor) {
+        int startPhaseIdx = 0;
+        int endPhaseIdx = inputProcessors.size();
+
+        Constants.Phase targetPhase = newInputProcessor.getPhase();
+
+        for (int i = inputProcessors.size() - 1; i >= 0; i--) {
+            InputProcessor inputProcessor = inputProcessors.get(i);
+            if (inputProcessor.getPhase().ordinal() > targetPhase.ordinal()) {
+                startPhaseIdx = i + 1;
+                break;
+            }
+        }
+        for (int i = startPhaseIdx; i < inputProcessors.size(); i++) {
+            InputProcessor inputProcessor = inputProcessors.get(i);
+            if (inputProcessor.getPhase().ordinal() < targetPhase.ordinal()) {
+                endPhaseIdx = i;
+                break;
+            }
+        }
+
+        //just look for the correct phase and append as last
+        if (newInputProcessor.getBeforeProcessors().isEmpty()
+                && newInputProcessor.getAfterProcessors().isEmpty()) {
+            inputProcessors.add(startPhaseIdx, newInputProcessor);
+        } else if (newInputProcessor.getBeforeProcessors().isEmpty()) {
+            int idxToInsert = startPhaseIdx;
+
+            for (int i = endPhaseIdx - 1; i >= startPhaseIdx; i--) {
+                InputProcessor inputProcessor = inputProcessors.get(i);
+                if (newInputProcessor.getAfterProcessors().contains(inputProcessor)
+                        || newInputProcessor.getAfterProcessors().contains(inputProcessor.getClass().getName())) {
+                    idxToInsert = i;
+                    break;
+                }
+            }
+            inputProcessors.add(idxToInsert, newInputProcessor);
+        } else if (newInputProcessor.getAfterProcessors().isEmpty()) {
+            int idxToInsert = endPhaseIdx;
+
+            for (int i = startPhaseIdx; i < endPhaseIdx; i++) {
+                InputProcessor inputProcessor = inputProcessors.get(i);
+                if (newInputProcessor.getBeforeProcessors().contains(inputProcessor)
+                        || newInputProcessor.getBeforeProcessors().contains(inputProcessor.getClass().getName())) {
+                    idxToInsert = i + 1;
+                    break;
+                }
+            }
+            inputProcessors.add(idxToInsert, newInputProcessor);
+        } else {
+            boolean found = false;
+            int idxToInsert = startPhaseIdx;
+
+            for (int i = endPhaseIdx - 1; i >= startPhaseIdx; i--) {
+                InputProcessor inputProcessor = inputProcessors.get(i);
+                if (newInputProcessor.getAfterProcessors().contains(inputProcessor)
+                        || newInputProcessor.getAfterProcessors().contains(inputProcessor.getClass().getName())) {
+                    idxToInsert = i;
+                    found = true;
+                    break;
+                }
+            }
+            if (found) {
+                inputProcessors.add(idxToInsert, newInputProcessor);
+            } else {
+                for (int i = startPhaseIdx; i < endPhaseIdx; i++) {
+                    InputProcessor inputProcessor = inputProcessors.get(i);
+                    if (newInputProcessor.getBeforeProcessors().contains(inputProcessor)
+                            || newInputProcessor.getBeforeProcessors().contains(inputProcessor.getClass().getName())) {
+                        idxToInsert = i + 1;
+                        break;
+                    }
+                }
+                inputProcessors.add(idxToInsert, newInputProcessor);
+            }
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("Added " + newInputProcessor.getClass().getName() + " to input chain: ");
+            for (int i = 0; i < inputProcessors.size(); i++) {
+                InputProcessor inputProcessor = inputProcessors.get(i);
+                log.debug("Name: " + inputProcessor.getClass().getName() + " phase: " + inputProcessor.getPhase());
+            }
+        }
+    }
+
+    public void removeProcessor(InputProcessor inputProcessor) {
+        log.debug("Removing processor " + inputProcessor.getClass().getName() + " from input chain");
+        if (this.inputProcessors.indexOf(inputProcessor) <= getCurPos()) {
+            this.curPos--;
+        }
+        this.inputProcessors.remove(inputProcessor);
+    }
+
+    public List<InputProcessor> getProcessors() {
+        return this.inputProcessors;
+    }
+
+    public XMLEvent processHeaderEvent() throws XMLStreamException, WSSecurityException {
+        return inputProcessors.get(getPosAndIncrement()).processNextHeaderEvent(this);
+    }
+
+    public XMLEvent processEvent() throws XMLStreamException, WSSecurityException {
+        return inputProcessors.get(getPosAndIncrement()).processNextEvent(this);
+    }
+
+    public void doFinal() throws XMLStreamException, WSSecurityException {
+        inputProcessors.get(getPosAndIncrement()).doFinal(this);
+    }
+
+    public InputProcessorChain createSubChain(InputProcessor inputProcessor) throws XMLStreamException, WSSecurityException {
+        //we don't clone the processor-list to get updates in the sublist too!
+        InputProcessorChainImpl inputProcessorChain = null;
+        try {
+            inputProcessorChain = new InputProcessorChainImpl(securityContext, documentContext.clone(),
+                    inputProcessors.indexOf(inputProcessor) + 1);
+        } catch (CloneNotSupportedException e) {
+            throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, e);
+        }
+        inputProcessorChain.setInputProcessors(new ArrayList<InputProcessor>(this.inputProcessors));
+        return inputProcessorChain;
+    }
+}

Propchange: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/InputProcessorChainImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/OutputProcessorChainImpl.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/OutputProcessorChainImpl.java?rev=1172285&view=auto
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/OutputProcessorChainImpl.java (added)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/OutputProcessorChainImpl.java Sun Sep 18 13:51:23 2011
@@ -0,0 +1,244 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.swssf.impl;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.swssf.ext.*;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.XMLEvent;
+import java.util.ArrayDeque;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * Implementation of a OutputProcessorChain
+ *
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class OutputProcessorChainImpl implements OutputProcessorChain {
+
+    protected static final transient Log log = LogFactory.getLog(OutputProcessorChainImpl.class);
+
+    private List<OutputProcessor> outputProcessors = Collections.synchronizedList(new ArrayList<OutputProcessor>());
+    private int startPos = 0;
+    private int curPos = 0;
+
+    private ArrayDeque<List<ComparableNamespace>> nsStack = new ArrayDeque<List<ComparableNamespace>>(10);
+    private ArrayDeque<List<ComparableAttribute>> attrStack = new ArrayDeque<List<ComparableAttribute>>(10);
+
+    private SecurityContext securityContext;
+    private DocumentContextImpl documentContext;
+
+    public OutputProcessorChainImpl(SecurityContext securityContext) {
+        this(securityContext, 0);
+    }
+
+    public OutputProcessorChainImpl(SecurityContext securityContext, int startPos) {
+        this(securityContext, new DocumentContextImpl(), startPos);
+    }
+
+    public OutputProcessorChainImpl(SecurityContext securityContext, DocumentContextImpl documentContext) {
+        this(securityContext, documentContext, 0);
+    }
+
+    protected OutputProcessorChainImpl(SecurityContext securityContext, DocumentContextImpl documentContextImpl, int startPos) {
+        this.securityContext = securityContext;
+        this.curPos = this.startPos = startPos;
+        documentContext = documentContextImpl;
+    }
+
+    public int getCurPos() {
+        return curPos;
+    }
+
+    public void setCurPos(int curPos) {
+        this.curPos = curPos;
+    }
+
+    public int getPosAndIncrement() {
+        return this.curPos++;
+    }
+
+    public void reset() {
+        setCurPos(startPos);
+    }
+
+    public SecurityContext getSecurityContext() {
+        return this.securityContext;
+    }
+
+    public DocumentContext getDocumentContext() {
+        return this.documentContext;
+    }
+
+    private void setOutputProcessors(List<OutputProcessor> outputProcessors) {
+        this.outputProcessors = outputProcessors;
+    }
+
+    private ArrayDeque<List<ComparableNamespace>> getNsStack() {
+        return nsStack.clone();
+    }
+
+    private void setNsStack(ArrayDeque<List<ComparableNamespace>> nsStack) {
+        this.nsStack = nsStack;
+    }
+
+    private ArrayDeque<List<ComparableAttribute>> getAttrStack() {
+        return attrStack;
+    }
+
+    private void setAttrStack(ArrayDeque<List<ComparableAttribute>> attrStack) {
+        this.attrStack = attrStack.clone();
+    }
+
+    public void addProcessor(OutputProcessor newOutputProcessor) {
+        int startPhaseIdx = 0;
+        int endPhaseIdx = outputProcessors.size();
+        int idxToInsert = endPhaseIdx;
+        Constants.Phase targetPhase = newOutputProcessor.getPhase();
+
+        for (int i = outputProcessors.size() - 1; i >= 0; i--) {
+            OutputProcessor outputProcessor = outputProcessors.get(i);
+            if (outputProcessor.getPhase().ordinal() < targetPhase.ordinal()) {
+                startPhaseIdx = i + 1;
+                break;
+            }
+        }
+        for (int i = startPhaseIdx; i < outputProcessors.size(); i++) {
+            OutputProcessor outputProcessor = outputProcessors.get(i);
+            if (outputProcessor.getPhase().ordinal() > targetPhase.ordinal()) {
+                endPhaseIdx = i;
+                break;
+            }
+        }
+
+        //just look for the correct phase and append as last
+        if (newOutputProcessor.getBeforeProcessors().isEmpty()
+                && newOutputProcessor.getAfterProcessors().isEmpty()) {
+            outputProcessors.add(endPhaseIdx, newOutputProcessor);
+        } else if (newOutputProcessor.getBeforeProcessors().isEmpty()) {
+            idxToInsert = endPhaseIdx;
+
+            for (int i = endPhaseIdx - 1; i >= startPhaseIdx; i--) {
+                OutputProcessor outputProcessor = outputProcessors.get(i);
+                if (newOutputProcessor.getAfterProcessors().contains(outputProcessor)
+                        || newOutputProcessor.getAfterProcessors().contains(outputProcessor.getClass().getName())) {
+                    idxToInsert = i + 1;
+                    break;
+                }
+            }
+            outputProcessors.add(idxToInsert, newOutputProcessor);
+        } else if (newOutputProcessor.getAfterProcessors().isEmpty()) {
+            idxToInsert = startPhaseIdx;
+
+            for (int i = startPhaseIdx; i < endPhaseIdx; i++) {
+                OutputProcessor outputProcessor = outputProcessors.get(i);
+                if (newOutputProcessor.getBeforeProcessors().contains(outputProcessor)
+                        || newOutputProcessor.getBeforeProcessors().contains(outputProcessor.getClass().getName())) {
+                    idxToInsert = i;
+                    break;
+                }
+            }
+            outputProcessors.add(idxToInsert, newOutputProcessor);
+        } else {
+            boolean found = false;
+            idxToInsert = endPhaseIdx;
+
+            for (int i = startPhaseIdx; i < endPhaseIdx; i++) {
+                OutputProcessor outputProcessor = outputProcessors.get(i);
+                if (newOutputProcessor.getBeforeProcessors().contains(outputProcessor)
+                        || newOutputProcessor.getBeforeProcessors().contains(outputProcessor.getClass().getName())) {
+                    idxToInsert = i;
+                    found = true;
+                    break;
+                }
+            }
+            if (found) {
+                outputProcessors.add(idxToInsert, newOutputProcessor);
+            } else {
+                for (int i = endPhaseIdx - 1; i >= startPhaseIdx; i--) {
+                    OutputProcessor outputProcessor = outputProcessors.get(i);
+                    if (newOutputProcessor.getAfterProcessors().contains(outputProcessor)
+                            || newOutputProcessor.getAfterProcessors().contains(outputProcessor.getClass().getName())) {
+                        idxToInsert = i + 1;
+                        break;
+                    }
+                }
+                outputProcessors.add(idxToInsert, newOutputProcessor);
+            }
+        }
+        if (idxToInsert < this.curPos) {
+            this.curPos++;
+        }
+        if (log.isDebugEnabled()) {
+            log.debug("Added " + newOutputProcessor.getClass().getName() + " to output chain: ");
+            for (int i = 0; i < outputProcessors.size(); i++) {
+                OutputProcessor outputProcessor = outputProcessors.get(i);
+                log.debug("Name: " + outputProcessor.getClass().getName() + " phase: " + outputProcessor.getPhase());
+            }
+        }
+    }
+
+    public void removeProcessor(OutputProcessor outputProcessor) {
+        log.debug("Removing processor " + outputProcessor.getClass().getName() + " from output chain");
+        if (this.outputProcessors.indexOf(outputProcessor) <= getCurPos()) {
+            this.curPos--;
+        }
+        this.outputProcessors.remove(outputProcessor);
+    }
+
+    public List<OutputProcessor> getProcessors() {
+        return this.outputProcessors;
+    }
+
+    public void processEvent(XMLEvent xmlEvent) throws XMLStreamException, WSSecurityException {
+        if (this.curPos == this.startPos) {
+            xmlEvent = Utils.createXMLEventNS(xmlEvent, nsStack, attrStack);
+            if (xmlEvent.isStartElement()) {
+                getDocumentContext().addPathElement(xmlEvent.asStartElement().getName());
+            } else if (xmlEvent.isEndElement()) {
+                getDocumentContext().removePathElement();
+            }
+        }
+        outputProcessors.get(getPosAndIncrement()).processNextEvent(xmlEvent, this);
+    }
+
+    public void doFinal() throws XMLStreamException, WSSecurityException {
+        outputProcessors.get(getPosAndIncrement()).doFinal(this);
+    }
+
+    public OutputProcessorChain createSubChain(OutputProcessor outputProcessor) throws XMLStreamException, WSSecurityException {
+        //we don't clone the processor-list to get updates in the sublist too!
+        OutputProcessorChainImpl outputProcessorChain = null;
+        try {
+            outputProcessorChain = new OutputProcessorChainImpl(securityContext, documentContext.clone(),
+                    outputProcessors.indexOf(outputProcessor) + 1);
+        } catch (CloneNotSupportedException e) {
+            throw new WSSecurityException(WSSecurityException.ErrorCode.FAILURE, e);
+        }
+        outputProcessorChain.setOutputProcessors(this.outputProcessors);
+        outputProcessorChain.setNsStack(getNsStack());
+        outputProcessorChain.setAttrStack(getAttrStack());
+        return outputProcessorChain;
+    }
+}

Propchange: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/OutputProcessorChainImpl.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/SignaturePartDef.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/SignaturePartDef.java?rev=1172285&view=auto
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/SignaturePartDef.java (added)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/SignaturePartDef.java Sun Sep 18 13:51:23 2011
@@ -0,0 +1,74 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.swssf.impl;
+
+/**
+ * SignaturePartDef holds information about parts to be signed
+ *
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class SignaturePartDef {
+
+    private String sigRefId;
+    private String digestValue;
+    private String transformAlgo;
+    private String c14nAlgo;
+    private String inclusiveNamespaces;
+
+    public String getSigRefId() {
+        return sigRefId;
+    }
+
+    public void setSigRefId(String sigRefId) {
+        this.sigRefId = sigRefId;
+    }
+
+    public String getDigestValue() {
+        return digestValue;
+    }
+
+    public void setDigestValue(String digestValue) {
+        this.digestValue = digestValue;
+    }
+
+    public String getTransformAlgo() {
+        return transformAlgo;
+    }
+
+    public void setTransformAlgo(String transformAlgo) {
+        this.transformAlgo = transformAlgo;
+    }
+
+    public String getC14nAlgo() {
+        return c14nAlgo;
+    }
+
+    public void setC14nAlgo(String c14nAlgo) {
+        this.c14nAlgo = c14nAlgo;
+    }
+
+    public String getInclusiveNamespaces() {
+        return inclusiveNamespaces;
+    }
+
+    public void setInclusiveNamespaces(String inclusiveNamespaces) {
+        this.inclusiveNamespaces = inclusiveNamespaces;
+    }
+}
\ No newline at end of file

Propchange: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/SignaturePartDef.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Added: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/XMLSecurityStreamReader.java
URL: http://svn.apache.org/viewvc/webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/XMLSecurityStreamReader.java?rev=1172285&view=auto
==============================================================================
--- webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/XMLSecurityStreamReader.java (added)
+++ webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/XMLSecurityStreamReader.java Sun Sep 18 13:51:23 2011
@@ -0,0 +1,655 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.swssf.impl;
+
+import org.swssf.ext.InputProcessorChain;
+import org.swssf.ext.SecurityProperties;
+import org.swssf.ext.WSSecurityException;
+
+import javax.xml.namespace.NamespaceContext;
+import javax.xml.namespace.QName;
+import javax.xml.stream.*;
+import javax.xml.stream.events.*;
+import java.util.Iterator;
+
+/**
+ * A custom implementation of a XMLStreamReader to get back from the XMLEventReader world
+ * to XMLStreamReader
+ *
+ * @author $Author$
+ * @version $Revision$ $Date$
+ */
+public class XMLSecurityStreamReader implements XMLStreamReader {
+
+    private SecurityProperties securityProperties;
+    private InputProcessorChain inputProcessorChain;
+    private XMLEvent currentEvent;
+
+    private static final String ERR_STATE_NOT_ELEM = "Current state not START_ELEMENT or END_ELEMENT";
+    private static final String ERR_STATE_NOT_STELEM = "Current state not START_ELEMENT";
+    private static final String ERR_STATE_NOT_PI = "Current state not PROCESSING_INSTRUCTION";
+
+    public XMLSecurityStreamReader(InputProcessorChain inputProcessorChain, SecurityProperties securityProperties) {
+        this.inputProcessorChain = inputProcessorChain;
+        this.securityProperties = securityProperties;
+    }
+
+    public Object getProperty(String name) throws IllegalArgumentException {
+        if (XMLInputFactory.IS_NAMESPACE_AWARE.equals(name)) {
+            return true;
+        }
+        return null;
+    }
+
+    public int next() throws XMLStreamException {
+        try {
+            inputProcessorChain.reset();
+            currentEvent = inputProcessorChain.processEvent();
+            if ((currentEvent.getEventType() == START_DOCUMENT)
+                    && securityProperties.isSkipDocumentEvents()) {
+                currentEvent = inputProcessorChain.processEvent();
+            }
+        } catch (WSSecurityException e) {
+            throw new XMLStreamException(e);
+        }
+        return getCurrentEvent().getEventType();
+    }
+
+    private XMLEvent getCurrentEvent() {
+        return currentEvent;
+    }
+
+    public void require(int type, String namespaceURI, String localName) throws XMLStreamException {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != type) {
+            throw new XMLStreamException("Event type mismatch");
+        }
+
+        if (localName != null) {
+            if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT
+                    && xmlEvent.getEventType() != ENTITY_REFERENCE) {
+                throw new XMLStreamException("Expected non-null local name, but current token not a START_ELEMENT, END_ELEMENT or ENTITY_REFERENCE (was " + xmlEvent.getEventType() + ")");
+            }
+            String n = getLocalName();
+            if (!n.equals(localName)) {
+                throw new XMLStreamException("Expected local name '" + localName + "'; current local name '" + n + "'.");
+            }
+        }
+        if (namespaceURI != null) {
+            if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
+                throw new XMLStreamException("Expected non-null NS URI, but current token not a START_ELEMENT or END_ELEMENT (was " + xmlEvent.getEventType() + ")");
+            }
+            String uri = getNamespaceURI();
+            // No namespace?
+            if (namespaceURI.length() == 0) {
+                if (uri != null && uri.length() > 0) {
+                    throw new XMLStreamException("Expected empty namespace, instead have '" + uri + "'.");
+                }
+            } else {
+                if (!namespaceURI.equals(uri)) {
+                    throw new XMLStreamException("Expected namespace '" + namespaceURI + "'; have '"
+                            + uri + "'.");
+                }
+            }
+        }
+    }
+
+    final private static int MASK_GET_ELEMENT_TEXT =
+            (1 << CHARACTERS) | (1 << CDATA) | (1 << SPACE)
+                    | (1 << ENTITY_REFERENCE);
+
+    public String getElementText() throws XMLStreamException {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT) {
+            throw new XMLStreamException("Not positioned on a start element");
+        }
+        StringBuilder stringBuffer = new StringBuilder();
+
+        /**
+         * Need to loop to get rid of PIs, comments
+         */
+        while (true) {
+            int type = next();
+            if (type == END_ELEMENT) {
+                break;
+            }
+            if (type == COMMENT || type == PROCESSING_INSTRUCTION) {
+                continue;
+            }
+            if (((1 << type) & MASK_GET_ELEMENT_TEXT) == 0) {
+                throw new XMLStreamException("Expected a text token, got " + xmlEvent.getEventType() + ".");
+            }
+            stringBuffer.append(getText());
+        }
+        return stringBuffer.toString();
+    }
+
+    public int nextTag() throws XMLStreamException {
+        while (true) {
+            int next = next();
+
+            switch (next) {
+                case SPACE:
+                case COMMENT:
+                case PROCESSING_INSTRUCTION:
+                    continue;
+                case CDATA:
+                case CHARACTERS:
+                    if (isWhiteSpace()) {
+                        continue;
+                    }
+                    throw new XMLStreamException("Received non-all-whitespace CHARACTERS or CDATA event in nextTag().");
+                case START_ELEMENT:
+                case END_ELEMENT:
+                    return next;
+            }
+            throw new XMLStreamException("Received event " + next
+                    + ", instead of START_ELEMENT or END_ELEMENT.");
+        }
+    }
+
+    public boolean hasNext() throws XMLStreamException {
+        if (currentEvent != null && currentEvent.getEventType() == END_DOCUMENT) {
+            return false;
+        }
+        return true;
+    }
+
+    public void close() throws XMLStreamException {
+        try {
+            inputProcessorChain.reset();
+            inputProcessorChain.doFinal();
+        } catch (WSSecurityException e) {
+            throw new XMLStreamException(e);
+        }
+    }
+
+    public String getNamespaceURI(String prefix) {
+        XMLEvent xmlEvent = getCurrentEvent();
+
+        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
+        }
+
+        if (xmlEvent.isStartElement()) {
+            return xmlEvent.asStartElement().getNamespaceURI(prefix);
+        } else {
+            //todo somehow...
+            return null;
+        }
+    }
+
+    public boolean isStartElement() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        return xmlEvent.isStartElement();
+    }
+
+    public boolean isEndElement() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        return xmlEvent.isEndElement();
+    }
+
+    public boolean isCharacters() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        return xmlEvent.isCharacters();
+    }
+
+    public boolean isWhiteSpace() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        return xmlEvent.isCharacters() && xmlEvent.asCharacters().isWhiteSpace();
+    }
+
+    public String getAttributeValue(String namespaceURI, String localName) {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_STELEM);
+        }
+        Attribute attribute = xmlEvent.asStartElement().getAttributeByName(new QName(namespaceURI, localName));
+        if (attribute != null) {
+            return attribute.getValue();
+        }
+        return null;
+    }
+
+    public int getAttributeCount() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_STELEM);
+        }
+        int count = 0;
+        @SuppressWarnings("unchecked")
+        Iterator<Attribute> attributeIterator = xmlEvent.asStartElement().getAttributes();
+        while (attributeIterator.hasNext()) {
+            attributeIterator.next();
+            count++;
+        }
+        return count;
+    }
+
+    public QName getAttributeName(int index) {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_STELEM);
+        }
+        int count = 0;
+        @SuppressWarnings("unchecked")
+        Iterator<Attribute> attributeIterator = xmlEvent.asStartElement().getAttributes();
+        while (attributeIterator.hasNext()) {
+            Attribute attribute = attributeIterator.next();
+            if (count == index) {
+                return attribute.getName();
+            }
+            count++;
+        }
+        throw new ArrayIndexOutOfBoundsException(index);
+    }
+
+    public String getAttributeNamespace(int index) {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_STELEM);
+        }
+        int count = 0;
+        @SuppressWarnings("unchecked")
+        Iterator<Attribute> attributeIterator = xmlEvent.asStartElement().getAttributes();
+        while (attributeIterator.hasNext()) {
+            Attribute attribute = attributeIterator.next();
+            if (count == index) {
+                return attribute.getName().getNamespaceURI();
+            }
+            count++;
+        }
+        throw new ArrayIndexOutOfBoundsException(index);
+    }
+
+    public String getAttributeLocalName(int index) {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_STELEM);
+        }
+        int count = 0;
+        @SuppressWarnings("unchecked")
+        Iterator<Attribute> attributeIterator = xmlEvent.asStartElement().getAttributes();
+        while (attributeIterator.hasNext()) {
+            Attribute attribute = attributeIterator.next();
+            if (count == index) {
+                return attribute.getName().getLocalPart();
+            }
+            count++;
+        }
+        throw new ArrayIndexOutOfBoundsException(index);
+    }
+
+    public String getAttributePrefix(int index) {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_STELEM);
+        }
+        int count = 0;
+        @SuppressWarnings("unchecked")
+        Iterator<Attribute> attributeIterator = xmlEvent.asStartElement().getAttributes();
+        while (attributeIterator.hasNext()) {
+            Attribute attribute = attributeIterator.next();
+            if (count == index) {
+                return attribute.getName().getPrefix();
+            }
+            count++;
+        }
+        throw new ArrayIndexOutOfBoundsException(index);
+    }
+
+    public String getAttributeType(int index) {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_STELEM);
+        }
+        int count = 0;
+        @SuppressWarnings("unchecked")
+        Iterator<Attribute> attributeIterator = xmlEvent.asStartElement().getAttributes();
+        while (attributeIterator.hasNext()) {
+            Attribute attribute = attributeIterator.next();
+            if (count == index) {
+                return attribute.getDTDType();
+            }
+            count++;
+        }
+        throw new ArrayIndexOutOfBoundsException(index);
+    }
+
+    public String getAttributeValue(int index) {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_STELEM);
+        }
+        int count = 0;
+        @SuppressWarnings("unchecked")
+        Iterator<Attribute> attributeIterator = xmlEvent.asStartElement().getAttributes();
+        while (attributeIterator.hasNext()) {
+            Attribute attribute = attributeIterator.next();
+            if (count == index) {
+                return attribute.getValue();
+            }
+            count++;
+        }
+        throw new ArrayIndexOutOfBoundsException(index);
+    }
+
+    public boolean isAttributeSpecified(int index) {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_STELEM);
+        }
+        int count = 0;
+        @SuppressWarnings("unchecked")
+        Iterator<Attribute> attributeIterator = xmlEvent.asStartElement().getAttributes();
+        while (attributeIterator.hasNext()) {
+            Attribute attribute = attributeIterator.next();
+            if (count == index) {
+                return attribute.isSpecified();
+            }
+            count++;
+        }
+        throw new ArrayIndexOutOfBoundsException(index);
+    }
+
+    @SuppressWarnings("unchecked")
+    public int getNamespaceCount() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
+        }
+        int count = 0;
+        Iterator<Namespace> namespaceIterator;
+        if (xmlEvent.getEventType() == START_ELEMENT) {
+            namespaceIterator = xmlEvent.asStartElement().getNamespaces();
+        } else {
+            namespaceIterator = xmlEvent.asEndElement().getNamespaces();
+        }
+        while (namespaceIterator.hasNext()) {
+            namespaceIterator.next();
+            count++;
+        }
+        return count;
+    }
+
+    @SuppressWarnings("unchecked")
+    public String getNamespacePrefix(int index) {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
+        }
+        int count = 0;
+        Iterator<Namespace> namespaceIterator;
+        if (xmlEvent.getEventType() == START_ELEMENT) {
+            namespaceIterator = xmlEvent.asStartElement().getNamespaces();
+        } else {
+            namespaceIterator = xmlEvent.asEndElement().getNamespaces();
+        }
+        while (namespaceIterator.hasNext()) {
+            Namespace namespace = namespaceIterator.next();
+            if (count == index) {
+                return namespace.getPrefix();
+            }
+            count++;
+        }
+        throw new ArrayIndexOutOfBoundsException(index);
+    }
+
+    public String getNamespaceURI(int index) {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_STELEM);
+        }
+        int count = 0;
+        @SuppressWarnings("unchecked")
+        Iterator<Namespace> namespaceIterator = xmlEvent.asStartElement().getNamespaces();
+        while (namespaceIterator.hasNext()) {
+            Namespace namespace = namespaceIterator.next();
+            if (count == index) {
+                return namespace.getNamespaceURI();
+            }
+            count++;
+        }
+        throw new ArrayIndexOutOfBoundsException(index);
+    }
+
+    public NamespaceContext getNamespaceContext() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_STELEM);
+        }
+        return xmlEvent.asStartElement().getNamespaceContext();
+    }
+
+    public int getEventType() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent == null) {
+            return XMLStreamConstants.START_DOCUMENT;
+        }
+        return xmlEvent.getEventType();
+    }
+
+    final private static int MASK_GET_TEXT =
+            (1 << CHARACTERS) | (1 << CDATA) | (1 << SPACE)
+                    | (1 << COMMENT) | (1 << DTD) | (1 << ENTITY_REFERENCE);
+
+    public String getText() {
+        XMLEvent xmlEvent = getCurrentEvent();
+
+        if (((1 << xmlEvent.getEventType()) & MASK_GET_TEXT) == 0) {
+            throw new IllegalStateException("Current state not TEXT");
+        }
+        if (xmlEvent.getEventType() == ENTITY_REFERENCE) {
+            return ((EntityReference) xmlEvent).getDeclaration().getReplacementText();
+        }
+        if (xmlEvent.getEventType() == DTD) {
+            return ((javax.xml.stream.events.DTD) xmlEvent).getDocumentTypeDeclaration();
+        }
+        if (xmlEvent.getEventType() == COMMENT) {
+            return ((Comment) xmlEvent).getText();
+        }
+        return xmlEvent.asCharacters().getData();
+    }
+
+    final private static int MASK_GET_TEXT_XXX =
+            (1 << CHARACTERS) | (1 << CDATA) | (1 << SPACE) | (1 << COMMENT);
+
+    public char[] getTextCharacters() {
+        XMLEvent xmlEvent = getCurrentEvent();
+
+        if (((1 << xmlEvent.getEventType()) & MASK_GET_TEXT_XXX) == 0) {
+            throw new IllegalStateException("Current state not TEXT");
+        }
+        if (xmlEvent.getEventType() == ENTITY_REFERENCE) {
+            return ((EntityReference) xmlEvent).getDeclaration().getReplacementText().toCharArray();
+        }
+        if (xmlEvent.getEventType() == DTD) {
+            return ((javax.xml.stream.events.DTD) xmlEvent).getDocumentTypeDeclaration().toCharArray();
+        }
+        if (xmlEvent.getEventType() == COMMENT) {
+            return ((Comment) xmlEvent).getText().toCharArray();
+        }
+        return xmlEvent.asCharacters().getData().toCharArray();
+    }
+
+    public int getTextCharacters(int sourceStart, char[] target, int targetStart, int length) throws XMLStreamException {
+        XMLEvent xmlEvent = getCurrentEvent();
+
+        if (((1 << xmlEvent.getEventType()) & MASK_GET_TEXT_XXX) == 0) {
+            throw new IllegalStateException("Current state not TEXT");
+        }
+        if (xmlEvent.getEventType() == ENTITY_REFERENCE) {
+            ((EntityReference) xmlEvent).getDeclaration().getReplacementText().getChars(sourceStart, sourceStart + length, target, targetStart);
+            return sourceStart + length;
+        }
+        if (xmlEvent.getEventType() == DTD) {
+            ((javax.xml.stream.events.DTD) xmlEvent).getDocumentTypeDeclaration().getChars(sourceStart, sourceStart + length, target, targetStart);
+            return sourceStart + length;
+        }
+        if (xmlEvent.getEventType() == COMMENT) {
+            ((Comment) xmlEvent).getText().getChars(sourceStart, sourceStart + length, target, targetStart);
+            return sourceStart + length;
+        }
+        xmlEvent.asCharacters().getData().getChars(sourceStart, sourceStart + length, target, targetStart);
+        return sourceStart + length;
+    }
+
+    public int getTextStart() {
+        return 0;
+    }
+
+    public int getTextLength() {
+        XMLEvent xmlEvent = getCurrentEvent();
+
+        if (((1 << xmlEvent.getEventType()) & MASK_GET_TEXT_XXX) == 0) {
+            throw new IllegalStateException("Current state not TEXT");
+        }
+        if (xmlEvent.getEventType() == ENTITY_REFERENCE) {
+            return ((EntityReference) xmlEvent).getDeclaration().getReplacementText().length();
+        }
+        if (xmlEvent.getEventType() == DTD) {
+            return ((javax.xml.stream.events.DTD) xmlEvent).getDocumentTypeDeclaration().length();
+        }
+        if (xmlEvent.getEventType() == COMMENT) {
+            return ((Comment) xmlEvent).getText().length();
+        }
+        return xmlEvent.asCharacters().getData().length();
+    }
+
+    public String getEncoding() {
+        return null;
+    }
+
+    public boolean hasText() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        return (((1 << xmlEvent.getEventType()) & MASK_GET_TEXT) != 0);
+    }
+
+    public Location getLocation() {
+        return new Location() {
+            public int getLineNumber() {
+                return -1;
+            }
+
+            public int getColumnNumber() {
+                return -1;
+            }
+
+            public int getCharacterOffset() {
+                return -1;
+            }
+
+            public String getPublicId() {
+                return null;
+            }
+
+            public String getSystemId() {
+                return null;
+            }
+        };
+    }
+
+    public QName getName() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
+        }
+        if (xmlEvent.isStartElement()) {
+            return xmlEvent.asStartElement().getName();
+        } else {
+            return xmlEvent.asEndElement().getName();
+        }
+    }
+
+    public String getLocalName() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
+        }
+        if (xmlEvent.isStartElement()) {
+            return xmlEvent.asStartElement().getName().getLocalPart();
+        } else {
+            return xmlEvent.asEndElement().getName().getLocalPart();
+        }
+    }
+
+    public boolean hasName() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
+            return false;
+        }
+        return true;
+    }
+
+    public String getNamespaceURI() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
+        }
+        if (xmlEvent.isStartElement()) {
+            return xmlEvent.asStartElement().getName().getNamespaceURI();
+        } else {
+            return xmlEvent.asEndElement().getName().getNamespaceURI();
+        }
+    }
+
+    public String getPrefix() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != START_ELEMENT && xmlEvent.getEventType() != END_ELEMENT) {
+            throw new IllegalStateException(ERR_STATE_NOT_ELEM);
+        }
+        if (xmlEvent.isStartElement()) {
+            return xmlEvent.asStartElement().getName().getPrefix();
+        } else {
+            return xmlEvent.asEndElement().getName().getPrefix();
+        }
+    }
+
+    public String getVersion() {
+        return null;
+    }
+
+    public boolean isStandalone() {
+        return false;
+    }
+
+    public boolean standaloneSet() {
+        return false;
+    }
+
+    public String getCharacterEncodingScheme() {
+        return null;
+    }
+
+    public String getPITarget() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != PROCESSING_INSTRUCTION) {
+            throw new IllegalStateException(ERR_STATE_NOT_PI);
+        }
+        return ((ProcessingInstruction) xmlEvent).getTarget();
+    }
+
+    public String getPIData() {
+        XMLEvent xmlEvent = getCurrentEvent();
+        if (xmlEvent.getEventType() != PROCESSING_INSTRUCTION) {
+            throw new IllegalStateException(ERR_STATE_NOT_PI);
+        }
+        return ((ProcessingInstruction) xmlEvent).getData();
+    }
+}

Propchange: webservices/wss4j/branches/swssf/streaming-ws-security/src/main/java/org/swssf/impl/XMLSecurityStreamReader.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision



Mime
View raw message