Author: ruchithf
Date: Sun Jul 8 08:31:43 2007
New Revision: 554376
URL: http://svn.apache.org/viewvc?view=rev&rev=554376
Log:
Updated org.apache.rahas.impl.SAMLTokenIssuerConfig to be able to generate an
axis2 param that carries the configuration
Modified:
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/TrustUtil.java
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/AbstractIssuerConfig.java
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuer.java
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java
Modified:
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/TrustUtil.java
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/TrustUtil.java?view=diff&rev=554376&r1=554375&r2=554376
==============================================================================
---
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/TrustUtil.java
(original)
+++
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/TrustUtil.java
Sun Jul 8 08:31:43 2007
@@ -26,6 +26,7 @@
import org.apache.axis2.addressing.AddressingConstants;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.context.ConfigurationContext;
+import org.apache.rahas.impl.AbstractIssuerConfig;
import org.apache.ws.security.WSConstants;
import org.apache.ws.security.message.token.Reference;
import org.apache.ws.security.message.token.SecurityTokenReference;
@@ -43,7 +44,6 @@
public class TrustUtil {
- private static final QName PROVIDER = new QName("provider");
private static final QName NAME = new QName("name");
/**
@@ -511,7 +511,8 @@
properties.setProperty(name, value);
}
properties.setProperty("org.apache.ws.security.crypto.provider",
-
cryptoElem.getAttribute(PROVIDER).getAttributeValue().trim());
+ cryptoElem.getAttribute(AbstractIssuerConfig.PROVIDER)
+ .getAttributeValue().trim());
return properties;
}
Modified:
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/AbstractIssuerConfig.java
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/AbstractIssuerConfig.java?view=diff&rev=554376&r1=554375&r2=554376
==============================================================================
---
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/AbstractIssuerConfig.java
(original)
+++
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/AbstractIssuerConfig.java
Sun Jul 8 08:31:43 2007
@@ -44,6 +44,8 @@
*/
public final static QName CRYPTO_PROPERTIES = new
QName("cryptoProperties");
public static final QName CRYPTO = new QName("crypto");
+ public static final QName PROVIDER = new QName("provider");
+ public static final QName PROPERTY = new QName("property");
protected int keyComputation = KeyComputation.KEY_COMP_PROVIDE_ENT;
protected String proofKeyType = TokenIssuerUtil.ENCRYPTED_KEY;
@@ -53,5 +55,26 @@
protected String cryptoPropertiesFile;
protected OMElement cryptoPropertiesElement;
protected int keySize = 256;
+
+ public void setAddRequestedAttachedRef(boolean addRequestedAttachedRef) {
+ this.addRequestedAttachedRef = addRequestedAttachedRef;
+ }
+ public void setAddRequestedUnattachedRef(boolean
addRequestedUnattachedRef) {
+ this.addRequestedUnattachedRef = addRequestedUnattachedRef;
+ }
+ public void setKeyComputation(int keyComputation) {
+ this.keyComputation = keyComputation;
+ }
+ public void setProofKeyType(String proofKeyType) {
+ this.proofKeyType = proofKeyType;
+ }
+ public void setTtl(long ttl) {
+ this.ttl = ttl;
+ }
+ public void setKeySize(int keySize) {
+ this.keySize = keySize;
+ }
+
+
}
Modified:
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuer.java
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuer.java?view=diff&rev=554376&r1=554375&r2=554376
==============================================================================
---
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuer.java
(original)
+++
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuer.java
Sun Jul 8 08:31:43 2007
@@ -53,7 +53,6 @@
import java.security.Principal;
import java.security.SecureRandom;
-import java.security.cert.CertificateEncodingException;
import java.security.cert.X509Certificate;
import java.text.DateFormat;
import java.util.Arrays;
@@ -77,21 +76,20 @@
SAMLTokenIssuerConfig config = null;
if (this.configElement != null) {
- config = SAMLTokenIssuerConfig
- .load(configElement
+ config = new SAMLTokenIssuerConfig(configElement
.getFirstChildWithName(SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG));
}
// Look for the file
if (config == null && this.configFile != null) {
- config = SAMLTokenIssuerConfig.load(this.configFile);
+ config = new SAMLTokenIssuerConfig(this.configFile);
}
// Look for the param
if (config == null && this.configParamName != null) {
Parameter param = inMsgCtx.getParameter(this.configParamName);
if (param != null && param.getParameterElement() != null) {
- config = SAMLTokenIssuerConfig.load(param
+ config = new SAMLTokenIssuerConfig(param
.getParameterElement().getFirstChildWithName(
SAMLTokenIssuerConfig.SAML_ISSUER_CONFIG));
} else {
Modified:
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java
URL:
http://svn.apache.org/viewvc/webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java?view=diff&rev=554376&r1=554375&r2=554376
==============================================================================
---
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java
(original)
+++
webservices/rampart/trunk/java/modules/rampart-trust/src/main/java/org/apache/rahas/impl/SAMLTokenIssuerConfig.java
Sun Jul 8 08:31:43 2007
@@ -16,17 +16,22 @@
package org.apache.rahas.impl;
+import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMAttribute;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axis2.description.Parameter;
import org.apache.rahas.TrustException;
import javax.xml.namespace.QName;
import java.io.FileInputStream;
+import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
+import java.util.Properties;
/**
* Configuration manager for the <code>SAMLTokenIssuer</code>
@@ -75,10 +80,38 @@
protected String issuerKeyAlias;
protected String issuerKeyPassword;
protected String issuerName;
- protected Map trustedServices;
+ protected Map trustedServices = new HashMap();
protected String trustStorePropFile;
- private SAMLTokenIssuerConfig(OMElement elem) throws TrustException {
+ /**
+ * Create a SAMLTokenIssuer configuration with a config file picked from
the
+ * given location.
+ * @param configFilePath Path to the config file
+ * @throws TrustException
+ */
+ public SAMLTokenIssuerConfig(String configFilePath) throws TrustException {
+ FileInputStream fis;
+ StAXOMBuilder builder;
+ try {
+ fis = new FileInputStream(configFilePath);
+ builder = new StAXOMBuilder(fis);
+ } catch (Exception e) {
+ throw new TrustException("errorLoadingConfigFile",
+ new String[] { configFilePath });
+ }
+ this.load(builder.getDocumentElement());
+ }
+
+ /**
+ * Create a SAMLTokenIssuer configuration using the give config element
+ * @param elem Configuration element as an <code>OMElement</code>
+ * @throws TrustException
+ */
+ public SAMLTokenIssuerConfig(OMElement elem) throws TrustException {
+ this.load(elem);
+ }
+
+ private void load(OMElement elem) throws TrustException {
OMElement proofKeyElem = elem.getFirstChildWithName(PROOF_KEY_TYPE);
if (proofKeyElem != null) {
this.proofKeyType = proofKeyElem.getText().trim();
@@ -116,7 +149,7 @@
if (cryptoPropElem != null) {
if ((cryptoPropertiesElement =
cryptoPropElem.getFirstChildWithName(CRYPTO)) == null){
- // no children. Hence, prop file shud have been defined
+ // no children. Hence, prop file should have been defined
this.cryptoPropertiesFile = cryptoPropElem.getText().trim();
}
// else Props should be defined as children of a crypto element
@@ -186,22 +219,110 @@
}
}
- public static SAMLTokenIssuerConfig load(OMElement elem) throws
TrustException {
- return new SAMLTokenIssuerConfig(elem);
+ /**
+ * Generate an Axis2 parameter for this configuration
+ * @return An Axis2 Parameter instance with configuration information
+ */
+ public Parameter getParameter() {
+ Parameter param = new Parameter();
+
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+
+ OMElement paramElem = fac.createOMElement("Parameter", null);
+ paramElem.addAttribute("name", SAML_ISSUER_CONFIG.getLocalPart(),
null);
+
+ OMElement configElem = fac.createOMElement(SAML_ISSUER_CONFIG,
paramElem);
+
+ OMElement issuerNameElem = fac.createOMElement(ISSUER_NAME,
configElem);
+ issuerNameElem.setText(this.issuerName);
+
+ OMElement issuerKeyAliasElem = fac.createOMElement(ISSUER_KEY_ALIAS,
configElem);
+ issuerKeyAliasElem.setText(this.issuerKeyAlias);
+
+ OMElement issuerKeyPasswd = fac.createOMElement(ISSUER_KEY_PASSWD,
configElem);
+ issuerKeyPasswd.setText(this.issuerKeyPassword);
+
+ configElem.addChild(this.cryptoPropertiesElement);
+
+ OMElement keySizeElem = fac.createOMElement(KEY_SIZE, configElem);
+ keySizeElem.setText(Integer.toString(this.keySize));
+
+ if(this.addRequestedAttachedRef) {
+ fac.createOMElement(ADD_REQUESTED_ATTACHED_REF, configElem);
+ }
+ if(this.addRequestedUnattachedRef) {
+ fac.createOMElement(ADD_REQUESTED_UNATTACHED_REF, configElem);
+ }
+
+ OMElement keyCompElem =
fac.createOMElement(KeyComputation.KEY_COMPUTATION, configElem);
+ keyCompElem.setText(Integer.toString(this.keyComputation));
+
+ OMElement proofKeyTypeElem = fac.createOMElement(PROOF_KEY_TYPE,
configElem);
+ proofKeyTypeElem.setText(this.proofKeyType);
+
+ OMElement trustedServicesElem = fac.createOMElement(TRUSTED_SERVICES,
configElem);
+ for (Iterator iterator = this.trustedServices.keySet().iterator();
iterator.hasNext();) {
+ String service = (String) iterator.next();
+ OMElement serviceElem = fac.createOMElement(SERVICE,
trustedServicesElem);
+ serviceElem.setText(service);
+ serviceElem.addAttribute("alias",
(String)this.trustedServices.get(service), null);
+
+ }
+
+ param.setParameterElement(paramElem);
+ return param;
+ }
+
+ public void setIssuerKeyAlias(String issuerKeyAlias) {
+ this.issuerKeyAlias = issuerKeyAlias;
}
- public static SAMLTokenIssuerConfig load(String configFilePath)
- throws TrustException {
- FileInputStream fis;
- StAXOMBuilder builder;
- try {
- fis = new FileInputStream(configFilePath);
- builder = new StAXOMBuilder(fis);
- } catch (Exception e) {
- throw new TrustException("errorLoadingConfigFile",
- new String[]{configFilePath});
- }
- return load(builder.getDocumentElement());
+ public void setIssuerKeyPassword(String issuerKeyPassword) {
+ this.issuerKeyPassword = issuerKeyPassword;
+ }
+
+ public void setIssuerName(String issuerName) {
+ this.issuerName = issuerName;
+ }
+
+ public void setTrustedServices(Map trustedServices) {
+ this.trustedServices = trustedServices;
}
+ public void setTrustStorePropFile(String trustStorePropFile) {
+ this.trustStorePropFile = trustStorePropFile;
+ }
+
+ /**
+ * Add a new trusted service endpoint address with its certificate
+ * @param address Service endpoint address
+ * @param alias certificate alias
+ */
+ public void addTrustedServiceEndpointAddress(String address, String alias)
{
+ this.trustedServices.put(address, alias);
+ }
+
+ /**
+ * Set crypto information using WSS4J mechanisms
+ *
+ * @param providerClassName
+ * Provider class - an implementation of
+ * org.apache.ws.security.components.crypto.Crypto
+ * @param props Configuration properties
+ */
+ public void setCryptoProperties(String providerClassName, Properties
props) {
+ OMFactory fac = OMAbstractFactory.getOMFactory();
+ this.cryptoPropertiesElement= fac.createOMElement(CRYPTO_PROPERTIES);
+ OMElement cryptoElem = fac.createOMElement(CRYPTO,
this.cryptoPropertiesElement);
+ cryptoElem.addAttribute(PROVIDER.getLocalPart(), providerClassName,
null);
+ Enumeration keys = props.keys();
+ while (keys.hasMoreElements()) {
+ String prop = (String) keys.nextElement();
+ String value = (String)props.get(prop);
+ OMElement propElem = fac.createOMElement(PROPERTY, cryptoElem);
+ propElem.setText(value);
+ propElem.addAttribute("name", prop, null);
+ }
+ }
+
}