You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by ru...@apache.org on 2005/11/21 15:01:22 UTC

svn commit: r345906 [2/2] - in /webservices/axis2/trunk/java/modules/security: ./ src/META-INF/ src/org/apache/axis2/security/trust/ src/org/apache/axis2/security/trust/client/ src/org/apache/axis2/security/trust/service/ src/org/apache/axis2/security/...

Added: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/RequestSecurityTokenResponse.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/RequestSecurityTokenResponse.java?rev=345906&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/RequestSecurityTokenResponse.java (added)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/RequestSecurityTokenResponse.java Mon Nov 21 06:00:43 2005
@@ -0,0 +1,63 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.apache.axis2.security.trust.token;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.security.trust.TrustException;
+
+/**
+ *
+ * @author Ruchith Fernando (ruchith.fernando@gmail.com)
+ */
+public class RequestSecurityTokenResponse extends CompositeToken {
+
+	/**
+	 * 
+	 */
+	public RequestSecurityTokenResponse() {
+		super();
+		// TODO Auto-generated constructor stub
+	}
+
+	/**
+	 * @param elem
+	 * @throws TrustException
+	 */
+	public RequestSecurityTokenResponse(OMElement elem) throws TrustException {
+		super(elem);
+		// TODO Auto-generated constructor stub
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.axis2.security.trust.token.AbstractToken#getToken()
+	 */
+	protected QName getToken() {
+		// TODO TODO
+		throw new UnsupportedOperationException("TODO");
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.axis2.security.trust.token.AbstractToken#deserializeChildElement(org.apache.axis2.om.OMElement)
+	 */
+	protected void deserializeChildElement(OMElement element)
+			throws TrustException {
+		// TODO TODO
+		throw new UnsupportedOperationException("TODO");
+	}
+
+}

Added: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/RequestType.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/RequestType.java?rev=345906&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/RequestType.java (added)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/RequestType.java Mon Nov 21 06:00:43 2005
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.apache.axis2.security.trust.token;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.security.trust.Constants;
+import org.apache.axis2.security.trust.TrustException;
+
+/**
+ *
+ * @author Ruchith Fernando (ruchith.fernando@gmail.com)
+ */
+public class RequestType extends ValueToken {
+
+    public static final QName TOKEN = new QName(Constants.WST_NS, Constants.LN.REQUEST_TYPE, Constants.WST_PREFIX);
+    
+	public RequestType() {
+		super();
+	}
+
+	/**
+	 * @param elem
+	 * @throws TrustException
+	 */
+	public RequestType(OMElement elem) throws TrustException {
+		super(elem);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.axis2.security.trust.token.AbstractToken#getToken()
+	 */
+	protected QName getToken() {
+		return TOKEN;
+	}
+
+}

Added: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/TokenType.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/TokenType.java?rev=345906&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/TokenType.java (added)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/TokenType.java Mon Nov 21 06:00:43 2005
@@ -0,0 +1,51 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.apache.axis2.security.trust.token;
+
+import javax.xml.namespace.QName;
+
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.security.trust.Constants;
+import org.apache.axis2.security.trust.TrustException;
+
+/**
+ *
+ * @author Ruchith Fernando (ruchith.fernando@gmail.com)
+ */
+public class TokenType extends ValueToken {
+	
+    public static final QName TOKEN = new QName(Constants.WST_NS, Constants.LN.TOKEN_TYPE, Constants.WST_PREFIX);
+    
+	public TokenType() {
+		super();
+	}
+
+	/**
+	 * @param elem
+	 * @throws TrustException
+	 */
+	public TokenType(OMElement elem) throws TrustException {
+		super(elem);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.axis2.security.trust.token.AbstractToken#getToken()
+	 */
+	protected QName getToken() {
+		return TOKEN;
+	}
+
+}

Added: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/ValueToken.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/ValueToken.java?rev=345906&view=auto
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/ValueToken.java (added)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/trust/token/ValueToken.java Mon Nov 21 06:00:43 2005
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ *
+ * Licensed 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.apache.axis2.security.trust.token;
+
+import org.apache.axis2.om.OMElement;
+import org.apache.axis2.om.OMText;
+import org.apache.axis2.security.trust.TrustException;
+
+/**
+ * This is the base class for the elements that carries a
+ * value in the element
+ * Example:
+ * 	<wsu:Created>...</wsu:Created>
+ * @author Ruchith Fernando (ruchith.fernando@gmail.com)
+ */
+public abstract class ValueToken extends AbstractToken {
+	
+	protected OMText valueText;
+	
+	public ValueToken() {
+		super();
+	}
+	
+	public ValueToken(OMElement elem) throws TrustException {
+		super(elem);
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.axis2.security.trust.token.AbstractToken#deserializeChildElement(org.apache.axis2.om.OMElement)
+	 */
+	protected void deserializeChildElement(OMElement element)
+			throws TrustException {
+		//There cannot be any children in this token
+		throw new TrustException(TrustException.INVALID_REQUEST,
+				TrustException.DESC_CHILD_IN_VALUE_ELEM,
+				new Object[] {
+				this.getToken().getNamespaceURI(),this.getToken().getLocalPart(),
+				element.getNamespace().getName(),element.getLocalName()});
+
+	}
+
+	/* (non-Javadoc)
+	 * @see org.apache.axis2.security.trust.token.AbstractToken#setElementTextValue(org.apache.axis2.om.OMText)
+	 */
+	protected void setElementTextValue(OMText textNode) {
+		this.valueText = textNode;
+	}
+	
+	/**
+	 * Returns the value of the token
+	 * @return
+	 */
+	public String getValue() {
+		if(this.valueText != null) 
+			return this.valueText.getText();
+		else
+			return null;
+	}
+	
+	/**
+	 * Sets the value of the token
+	 * @param value
+	 */
+	public void setValue(String value) {
+    	if(this.valueText != null)
+    		this.valueText.detach();
+    	
+    	this.valueText = factory.createText(value);
+        this.tokenElement.addChild(this.valueText);
+	}
+	
+}

Modified: webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java
URL: http://svn.apache.org/viewcvs/webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java?rev=345906&r1=345905&r2=345906&view=diff
==============================================================================
--- webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java (original)
+++ webservices/axis2/trunk/java/modules/security/src/org/apache/axis2/security/util/Axis2Util.java Mon Nov 21 06:00:43 2005
@@ -20,6 +20,7 @@
 import org.apache.axis2.om.impl.OMOutputImpl;
 import org.apache.axis2.om.impl.llom.builder.StAXOMBuilder;
 import org.apache.axis2.security.handler.WSSHandlerConstants;
+import org.apache.axis2.security.trust.TrustException;
 import org.apache.axis2.soap.SOAPEnvelope;
 import org.apache.axis2.soap.impl.llom.builder.StAXSOAPModelBuilder;
 import org.apache.ws.security.SOAPConstants;
@@ -32,6 +33,7 @@
 
 import javax.xml.parsers.DocumentBuilderFactory;
 import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -187,5 +189,55 @@
 				return originalKey + repetition;
 		}
 		return originalKey;
+	}
+	
+	/**
+	 * Convert a given DOM Element to an OMElement
+	 * @param element
+	 * @return
+	 * @throws TrustException
+	 */
+	public static OMElement toOM(Element element) throws TrustException {
+		try {
+			ByteArrayOutputStream os = new ByteArrayOutputStream();
+			XMLUtils.outputDOM(element, os, true);
+			
+			ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
+			XMLStreamReader reader = XMLInputFactory.newInstance()
+					.createXMLStreamReader(is);
+
+			StAXOMBuilder builder = new StAXOMBuilder(reader);
+			builder.setCache(true);
+
+			return builder.getDocumentElement();
+		} catch (XMLStreamException e) {
+			throw new TrustException(TrustException.ERROR_IN_CONVERTING_TO_OM,
+					TrustException.ERROR_IN_CONVERTING_TO_OM, new Object[] {}, e);
+		}
+	}
+	
+
+	/**
+	 * Convert a given OMElement to a DOM Element
+	 * @param element
+	 * @return
+	 * @throws TrustException
+	 */
+	public static Element toDOM(OMElement element) throws TrustException {
+		try {
+			ByteArrayOutputStream baos = new ByteArrayOutputStream();
+	
+			OMOutputImpl output = new OMOutputImpl(baos, false);
+			element.serialize(output);
+			output.flush();
+			ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+	
+			DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+			factory.setNamespaceAware(true);
+			return factory.newDocumentBuilder().parse(bais).getDocumentElement();
+		} catch (Exception e) {
+			throw new TrustException(TrustException.ERROR_IN_CONVERTING_TO_DOM,
+					TrustException.ERROR_IN_CONVERTING_TO_DOM, new Object[] {}, e);			
+		}
 	}
 }