You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fx-dev@ws.apache.org by mu...@apache.org on 2004/10/16 08:16:08 UTC
cvs commit: ws-fx/wss4j/src/org/apache/ws/security/trust/message/token Entropy.java BinarySecret.java ComputedKey.java
muthulee 2004/10/15 23:16:08
Added: wss4j/src/org/apache/ws/security/trust/message/token
Entropy.java BinarySecret.java ComputedKey.java
Log:
Element classes for Trust.
Revision Changes Path
1.1 ws-fx/wss4j/src/org/apache/ws/security/trust/message/token/Entropy.java
Index: Entropy.java
===================================================================
/*
* Copyright 2003-2004 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.ws.security.trust.message.token;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.WSSConfig;
import org.apache.ws.security.trust.TrustConstants;
import org.apache.ws.security.trust.WSTrustException;
import org.apache.ws.security.util.DOM2Writer;
import org.apache.ws.security.util.WSSecurityUtil;
import org.apache.xml.utils.QName;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
*
* @author Dimuthu Leelarathne. (muthulee@yahoo.com)
*/
public class Entropy {
private static Log log =
LogFactory.getLog(Entropy.class.getName());
public static final String ENTROPY = "Entropy";
public static final QName TOKEN = new QName(TrustConstants.WST_NS,ENTROPY);
public static final String BINARY_SECURITY = "BinarySecret";
protected WSSConfig wssConfig = WSSConfig.getDefaultWSConfig();
protected Element element = null;
/**
* Constructor.
* <p/>
*
* @param wssConfig
* @param elem
* @throws WSSecurityException
*/
public Entropy(Element elem) throws WSTrustException {
this.element = elem;
QName el = new QName(this.element.getNamespaceURI(),
this.element.getLocalName());
if (!el.equals(TOKEN)) {
throw new WSTrustException();
}
}
/**
* Constructor.
* <p/>
*
* @param wssConfig
* @param doc
*/
public Entropy(Document doc) {
this.element =
doc.createElementNS(TrustConstants.WST_NS,
TrustConstants.WST_PREFIX+":"+ENTROPY);
}
/*
* Here the methods that handle the direct reference inside
* a SecurityTokenReference
*/
/**
* set the BinarySecret.
* <p/>
*
* @param secret
*/
public void setBinarySecret(BinarySecret secret) {
this.element.appendChild(secret.getElement());
}
/**
*
* @return
* @throws WSTrustException
*/
public BinarySecret getBinarySecret() throws WSTrustException {
Element elem = getFirstElement();
return new BinarySecret(elem);
}
/**
* get the first child element.
*
* @return the first <code>Element</code> child node
*/
public Element getFirstElement() {
for (Node currentChild = this.element.getFirstChild();
currentChild != null;
currentChild = currentChild.getNextSibling()) {
if (currentChild instanceof Element) {
return (Element) currentChild;
}
}
return null;
}
/**
* get the dom element.
* <p/>
*
* @return
*/
public Element getElement() {
return this.element;
}
/**
* set the id.
* <p/>
*
* @param id
*/
public void setID(String id) {
String prefix =
WSSecurityUtil.setNamespace(this.element,
wssConfig.getWsuNS(),
WSConstants.WSU_PREFIX);
this.element.setAttributeNS(wssConfig.getWsuNS(), prefix + ":Id", id);
}
/**
* return the string representation.
* <p/>
*
* @return
*/
public String toString() {
return DOM2Writer.nodeToString((Node) this.element);
}
}
1.1 ws-fx/wss4j/src/org/apache/ws/security/trust/message/token/BinarySecret.java
Index: BinarySecret.java
===================================================================
/*
* Copyright 2003-2004 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.ws.security.trust.message.token;
import org.apache.ws.security.trust.TrustConstants;
import org.apache.ws.security.trust.WSTrustException;
import org.apache.ws.security.util.DOM2Writer;
import org.apache.xml.utils.QName;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
*
* @author Dimuthu Leelarathne. muthulee@yahoo.com
*/
public class BinarySecret {
public static final QName TOKEN =new QName(TrustConstants.WST_NS,"BinarySecret");
public static final String PRIVATE_KEY = "http://schemas.xmlsoap.org/ws/2004/04/security/trust/AsymmetricKey";
public static final String SYMMETRIC_KEY ="http://schemas.xmlsoap.org/ws/2004/04/security/trust/SymmetricKey";
public static final String NONCE_VAL="http://schemas.xmlsoap.org/ws/2004/04/security/trust/Nonce";
protected Element element = null;
protected String typeAttr = null;
// protected WSSConfig wssConfig = WSSConfig.getDefaultWSConfig();
/**
* Constructor.
* <p/>
*
* @param wssConfig
* @param elem
*/
public BinarySecret(Element elem)
throws WSTrustException {
this.element = elem;
QName el = new QName(this.element.getNamespaceURI(),
this.element.getLocalName());
if (!el.equals(TOKEN)) {
throw new WSTrustException();
}
}
/**
* Constructor.
* <p/>
*
* @param wssConfig
* @param doc
*/
public BinarySecret(Document doc) {
this.element = doc.createElementNS(TrustConstants.WST_NS,
"wst:BinarySecret");
}
/*
* Here the methods that handle the direct reference inside
* a SecurityTokenReference
*/
/**
* set the Type.
* Set one of the three types.
* @param ref
*/
public void setTypeAttribute(String type) {
this.typeAttr=type;
this.element.setAttribute("Type", typeAttr);
}
public String getTypeAttribute() {
return this.element.getAttribute("Type");
}
/**
* Sets the text node
*
* @param val
*/
public void setBinarySecretValue(String val) {
this.element.appendChild(
element.getOwnerDocument().createTextNode(val));
}
/**
* return the value of the text node
*
* @return
*/
public String getBinarySecretValue() {
String val = "";
if (this.element.getFirstChild().getNodeType() != Node.TEXT_NODE) {
return null;
}
val = this.element.getFirstChild().getNodeValue();
return val;
}
/**
* get the element
*
* @return
*/
public Element getElement() {
return this.element;
}
/**
* set the element
*
* @param element
*/
public void setElement(Element element) {
this.element = element;
}
public String toString() {
return DOM2Writer.nodeToString((Node) this.element);
}
}
1.1 ws-fx/wss4j/src/org/apache/ws/security/trust/message/token/ComputedKey.java
Index: ComputedKey.java
===================================================================
/*
* Created on Sep 4, 2004
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package org.apache.ws.security.trust.message.token;
import org.apache.ws.security.trust.TrustConstants;
import org.apache.ws.security.trust.WSTrustException;
import org.apache.ws.security.util.DOM2Writer;
import org.apache.xml.utils.QName;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
/**
* @author Dimuthu Leelarathne. (muthulee@yahoo.com)
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class ComputedKey {
public static final String PSHA1 = "http://schemas.xmlsoap.org/ws/2004/04/security/trust/CK/PSHA1";
public static final QName TOKEN = new QName(TrustConstants.WST_NS, "ComputedKey");
protected Element element = null;
/**
* Constructor.
* <p/>
*
* @param wssConfig
* @param elem
*/
public ComputedKey(Element elem)
throws WSTrustException {
this.element = elem;
QName el = new QName(this.element.getNamespaceURI(),
this.element.getLocalName());
if (!el.equals(TOKEN)) {
throw new WSTrustException();
}
}
/**
* Constructor.
* <p/>
*
* @param wssConfig
* @param doc
*/
public ComputedKey(Document doc) {
this.element = doc.createElementNS(TrustConstants.WST_NS,
"wst:ComputedKey");
}
/**
* Sets the text node
*
* @param val
*/
public void setComputedKeyValue(String val) {
this.element.appendChild(
element.getOwnerDocument().createTextNode(val));
}
/**
* return the value of the text node
*
* @return
*/
public String getComputedKeyValue() {
String val = "";
if (this.element.getFirstChild().getNodeType() != Node.TEXT_NODE) {
return null;
}
val = this.element.getFirstChild().getNodeValue();
return val;
}
/**
* get the element
*
* @return
*/
public Element getElement() {
return this.element;
}
/**
* set the element
*
* @param element
*/
public void setElement(Element element) {
this.element = element;
}
public String toString() {
return DOM2Writer.nodeToString((Node) this.element);
}
}