Author: prabath
Date: Sat Dec 20 11:39:41 2008
New Revision: 27474
URL: http://wso2.org/svn/browse/wso2?view=rev&revision=27474

Log:
modifications to suit carbon - DONE and tested

Added:
   
trunk/wsas/java/modules/samples/sts-sample/src/org/wso2/wsas/sample/sts/client/PWCBHandler.java
Modified:
   trunk/wsas/java/modules/samples/sts-sample/README
   trunk/wsas/java/modules/samples/sts-sample/conf/client-truststore.jks
   trunk/wsas/java/modules/samples/sts-sample/conf/service.policy.xml
   trunk/wsas/java/modules/samples/sts-sample/conf/sts.policy.xml
   
trunk/wsas/java/modules/samples/sts-sample/src/org/wso2/wsas/sample/sts/client/Client.java

Modified: trunk/wsas/java/modules/samples/sts-sample/README
URL: 
http://wso2.org/svn/browse/wso2/trunk/wsas/java/modules/samples/sts-sample/README?rev=27474&r1=27473&r2=27474&view=diff
==============================================================================
--- trunk/wsas/java/modules/samples/sts-sample/README   (original)
+++ trunk/wsas/java/modules/samples/sts-sample/README   Sat Dec 20 11:39:41 2008
@@ -27,10 +27,19 @@
     "SecureConversation - Sign and Encrypt - Service as STS - Bootstrap policy 
- Sign and Encrypt , X509 Authentication" on it.
     Makesure wso2carbon.jks keystore (WSO2WSAS keystore) is used.
 
-7.) Upload sts-sample/conf/client.cert into the wso2carbonkeystore using the 
+7.) Upload sts-sample/conf/client.cert into the wso2carbon keystore using the 
     WSO2WSAS admin console.
 
 8.) Run client
      $ ./run-client.sh <wso2carbon-sts-http-address> 
<hello-service-http-address>
        OR 
      path\>run-client.bat  <wso2carbon-sts-http-address> 
<hello-service-http-address>
+
+
+Notes:
+
+1. You need to download Java Cryptography Extension (JCE) Unlimited Strength 
Jurisdiction Policy Files 5.0 
+   from http://java.sun.com/javase/downloads/index_jdk5.jsp and copy the two 
jar files from the extracted jce directory (local_policy.jar and 
US_export_policy.jar) 
+   to $JAVA_HOME/jre/lib/security.
+
+2. Make sure <hello-service-http-address> is exactly the same as the url you 
added as a trusted service to the STS

Modified: trunk/wsas/java/modules/samples/sts-sample/conf/client-truststore.jks
URL: 
http://wso2.org/svn/browse/wso2/trunk/wsas/java/modules/samples/sts-sample/conf/client-truststore.jks?rev=27474&r1=27473&r2=27474&view=diff
==============================================================================
Binary files. No diff available.

Modified: trunk/wsas/java/modules/samples/sts-sample/conf/service.policy.xml
URL: 
http://wso2.org/svn/browse/wso2/trunk/wsas/java/modules/samples/sts-sample/conf/service.policy.xml?rev=27474&r1=27473&r2=27474&view=diff
==============================================================================
--- trunk/wsas/java/modules/samples/sts-sample/conf/service.policy.xml  
(original)
+++ trunk/wsas/java/modules/samples/sts-sample/conf/service.policy.xml  Sat Dec 
20 11:39:41 2008
@@ -24,8 +24,7 @@
                                                                                
                                        <sp:X509Token
                                                                                
                                                
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never";>
                                                                                
                                                <wsp:Policy>
-                                                                               
                                                        
<sp:RequireThumbprintReference />
-                                                                               
                                                        <sp:WssX509V3Token10 />
+                                                                               
                                                        
<sp:RequireThumbprintReference />                                               
                                                                                
                                                                                
                                                </wsp:Policy>
                                                                                
                                        </sp:X509Token>
                                                                                
                                </wsp:Policy>
@@ -35,8 +34,7 @@
                                                                                
                                        <sp:X509Token
                                                                                
                                                
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never";>
                                                                                
                                                <wsp:Policy>
-                                                                               
                                                        
<sp:RequireThumbprintReference />
-                                                                               
                                                        <sp:WssX509V3Token10 />
+                                                                               
                                                        
<sp:RequireThumbprintReference />                                               
                                                                                
                                                                                
                                                </wsp:Policy>
                                                                                
                                        </sp:X509Token>
                                                                                
                                </wsp:Policy>

Modified: trunk/wsas/java/modules/samples/sts-sample/conf/sts.policy.xml
URL: 
http://wso2.org/svn/browse/wso2/trunk/wsas/java/modules/samples/sts-sample/conf/sts.policy.xml?rev=27474&r1=27473&r2=27474&view=diff
==============================================================================
--- trunk/wsas/java/modules/samples/sts-sample/conf/sts.policy.xml      
(original)
+++ trunk/wsas/java/modules/samples/sts-sample/conf/sts.policy.xml      Sat Dec 
20 11:39:41 2008
@@ -1,75 +1,75 @@
-<!--
-  ~ Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
-  ~
-  ~ 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.
-  -->
-
-<wsp:Policy wsu:Id="scenario-3" 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
 xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy";>
-       <wsp:ExactlyOne>
-               <wsp:All>
-                               <sp:AsymmetricBinding 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
-                                       <wsp:Policy>
-                                               <sp:InitiatorToken>
-                                                       <wsp:Policy>
-                                                               <sp:X509Token 
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient";>
-                                                                       
<wsp:Policy>
-                                                                               
<sp:WssX509V3Token10/>
-                                                                       
</wsp:Policy>
-                                                               </sp:X509Token>
-                                                       </wsp:Policy>
-                                               </sp:InitiatorToken>
-                                               <sp:RecipientToken>
-                                                       <wsp:Policy>
-                                                               <sp:X509Token 
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never";>
-                                                                       
<wsp:Policy>
-                                                                               
<sp:WssX509V3Token10/>
-                                                                       
</wsp:Policy>
-                                                               </sp:X509Token>
-                                                       </wsp:Policy>
-                                               </sp:RecipientToken>
-                                               <sp:AlgorithmSuite>
-                                                       <wsp:Policy>
-                                                               <sp:Basic256/>
-                                                       </wsp:Policy>
-                                               </sp:AlgorithmSuite>
-                                               <sp:Layout>
-                                                       <wsp:Policy>
-                                                               <sp:Lax/>
-                                                       </wsp:Policy>
-                                               </sp:Layout>
-                                               <sp:IncludeTimestamp/>
-                                               
<sp:OnlySignEntireHeadersAndBody/>
-                                       </wsp:Policy>
-                               </sp:AsymmetricBinding>
-                               <sp:Wss10 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
-                                       <wsp:Policy>
-                                               
<sp:MustSupportRefKeyIdentifier/>
-                                               <sp:MustSupportRefIssuerSerial/>
-                                       </wsp:Policy>
-                               </sp:Wss10>
-                               <sp:Trust10 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
-                                       <wsp:Policy>
-                                               <sp:MustSupportIssuedTokens/>
-                                               <sp:RequireClientEntropy/>
-                                               <sp:RequireServerEntropy/>
-                                       </wsp:Policy>
-                               </sp:Trust10>
-                               <sp:SignedParts 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
-                                       <sp:Body/>
-                               </sp:SignedParts>
-                               <sp:EncryptedParts 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
-                                       <sp:Body/>
-                               </sp:EncryptedParts>
-               </wsp:All>
-       </wsp:ExactlyOne>
-</wsp:Policy>
+<!--
+  ~ Copyright 2005-2007 WSO2, Inc. (http://wso2.com)
+  ~
+  ~ 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.
+  -->
+
+<wsp:Policy wsu:Id="scenario-3" 
xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd";
 xmlns:wsp="http://schemas.xmlsoap.org/ws/2004/09/policy";>
+       <wsp:ExactlyOne>
+               <wsp:All>
+                               <sp:AsymmetricBinding 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
+                                       <wsp:Policy>
+                                               <sp:InitiatorToken>
+                                                       <wsp:Policy>
+                                                               <sp:X509Token 
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/AlwaysToRecipient";>
+                                                                       
<wsp:Policy>                                                                    
+                                                            
<sp:RequireThumbprintReference/>
+                                                                       
</wsp:Policy>
+                                                               </sp:X509Token>
+                                                       </wsp:Policy>
+                                               </sp:InitiatorToken>
+                                               <sp:RecipientToken>
+                                                       <wsp:Policy>
+                                                               <sp:X509Token 
sp:IncludeToken="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy/IncludeToken/Never";>
+                                                                       
<wsp:Policy>
+                                                                               
<sp:RequireThumbprintReference/>
+                                                                       
</wsp:Policy>
+                                                               </sp:X509Token>
+                                                       </wsp:Policy>
+                                               </sp:RecipientToken>
+                                               <sp:AlgorithmSuite>
+                                                       <wsp:Policy>
+                                                               <sp:Basic256/>
+                                                       </wsp:Policy>
+                                               </sp:AlgorithmSuite>
+                                               <sp:Layout>
+                                                       <wsp:Policy>
+                                                               <sp:Lax/>
+                                                       </wsp:Policy>
+                                               </sp:Layout>
+                                               <sp:IncludeTimestamp/>
+                                               
<sp:OnlySignEntireHeadersAndBody/>
+                                       </wsp:Policy>
+                               </sp:AsymmetricBinding>
+                               <sp:Wss10 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
+                                       <wsp:Policy>
+                                               
<sp:MustSupportRefKeyIdentifier/>
+                                               <sp:MustSupportRefIssuerSerial/>
+                                       </wsp:Policy>
+                               </sp:Wss10>
+                               <sp:Trust10 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
+                                       <wsp:Policy>
+                                               <sp:MustSupportIssuedTokens/>
+                                               <sp:RequireClientEntropy/>
+                                               <sp:RequireServerEntropy/>
+                                       </wsp:Policy>
+                               </sp:Trust10>
+                               <sp:SignedParts 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
+                                       <sp:Body/>
+                               </sp:SignedParts>
+                               <sp:EncryptedParts 
xmlns:sp="http://schemas.xmlsoap.org/ws/2005/07/securitypolicy";>
+                                       <sp:Body/>
+                               </sp:EncryptedParts>
+               </wsp:All>
+       </wsp:ExactlyOne>
+</wsp:Policy>

Modified: 
trunk/wsas/java/modules/samples/sts-sample/src/org/wso2/wsas/sample/sts/client/Client.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/wsas/java/modules/samples/sts-sample/src/org/wso2/wsas/sample/sts/client/Client.java?rev=27474&r1=27473&r2=27474&view=diff
==============================================================================
--- 
trunk/wsas/java/modules/samples/sts-sample/src/org/wso2/wsas/sample/sts/client/Client.java
  (original)
+++ 
trunk/wsas/java/modules/samples/sts-sample/src/org/wso2/wsas/sample/sts/client/Client.java
  Sat Dec 20 11:39:41 2008
@@ -1,31 +1,21 @@
-/*
- * Copyright 2006,2007 WSO2, Inc. http://www.wso2.org\
- *
- * 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.wso2.wsas.sample.sts.client;
 
+import java.util.Properties;
+
+import javax.xml.namespace.QName;
+
 import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
 import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.OMNamespace;
 import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.axiom.om.util.Base64;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axis2.addressing.EndpointReference;
 import org.apache.axis2.client.Options;
 import org.apache.axis2.client.ServiceClient;
 import org.apache.axis2.context.ConfigurationContext;
 import org.apache.axis2.context.ConfigurationContextFactory;
+import org.apache.axis2.util.Base64;
 import org.apache.neethi.Policy;
 import org.apache.neethi.PolicyEngine;
 import org.apache.rahas.RahasConstants;
@@ -37,152 +27,140 @@
 import org.apache.rampart.policy.model.CryptoConfig;
 import org.apache.rampart.policy.model.RampartConfig;
 import org.apache.ws.secpolicy.Constants;
-import org.apache.ws.security.WSPasswordCallback;
 import org.opensaml.XML;
+import java.io.File;
 
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.UnsupportedCallbackException;
-import javax.xml.namespace.QName;
+public class Client {
 
-import java.io.File;
-import java.io.IOException;
-import java.util.Properties;
 
-/**
- * Client of the STS sample
- */
-public class Client implements CallbackHandler {
-
-    private static final String wso2wsasHome = 
System.getProperty("wso2wsas.home");
-    
-    public static void main(String[] args) throws Exception {
-        
-        String sts;
-        String service;
-        if(args.length != 2) {
-            sts = "http://localhost:9763/services/wso2carbon-sts";;
-            service = "http://localhost:9763/services/HelloService";;
-        } else {
-            sts = args[0];
-            service = args[1];
-        }
-
-        System.out.println("Security token service endpoint address: " + sts);
-        System.out.println("Secured Service endpoint address: " + service);
-        
-        String clientSSLStore = wso2wsasHome + File.separator + "conf"
-                + File.separator + "client-truststore.jks";
-        
-        System.getProperties().remove("javax.net.ssl.trustStore");
-        System.getProperties().remove("javax.net.ssl.trustStoreType");
-        System.getProperties().remove("javax.net.ssl.trustStorePassword");
-
-        System.setProperty("javax.net.ssl.trustStore", clientSSLStore);
-        System.setProperty("javax.net.ssl.trustStoreType", "JKS");
-        System.setProperty("javax.net.ssl.trustStorePassword", "wso2wsas");
-
-        ConfigurationContext ctx  =
-            
ConfigurationContextFactory.createConfigurationContextFromFileSystem("repository");
-        //STS Invocation 
-        STSClient stsClient = new STSClient(ctx);
-        
-        Policy stsPolicy = loadPolicy(wso2wsasHome +  
-                "/samples/sts-sample/conf/sts.policy.xml");
-        Policy servicePolicy = loadPolicy(wso2wsasHome +  
-                "/samples/sts-sample/conf/service.policy.xml");
-        
-        stsClient.setRstTemplate(getRSTTemplate());
-        stsClient.setAction(RahasConstants.WST_NS_05_02 + 
RahasConstants.RST_ACTION_ISSUE);
-        Token responseToken = stsClient.requestSecurityToken(servicePolicy,  
sts, stsPolicy, service);
-        
-        System.out.println("\nRECEIVED SECRET: "
-                + Base64.encode(responseToken.getSecret()) + "\n");
-        System.out.println("RECEIVED TOKEN: " + responseToken.getToken() + 
"\n");
-        
-        
-        //Store token
-        TokenStorage store = TrustUtil.getTokenStore(ctx);
-        store.add(responseToken);
-        
-        //Service invocation
-        ServiceClient client = new ServiceClient(ctx, null);
-        client.engageModule("rampart");
-        client.engageModule("addressing");
-        
-        
client.getServiceContext().setProperty(RampartMessageData.KEY_RAMPART_POLICY, 
servicePolicy);
-        Options options = client.getOptions();
-        options.setAction("urn:echoOMElement");
-        options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-        options.setTo(new EndpointReference(service));
-        options.setProperty(RampartMessageData.KEY_CUSTOM_ISSUED_TOKEN, 
responseToken.getId());
-        OMElement respEelm = client.sendReceive(getPayload());
-        System.out.println("RESPONSE FROM SERVICE: \n" + respEelm);
-    }
-  
-
-    private static Policy loadPolicy(String xmlPath) throws Exception {
-        StAXOMBuilder builder = new StAXOMBuilder(xmlPath);
-        Policy policy = PolicyEngine.getPolicy(builder.getDocumentElement());
-        
-        RampartConfig rc = new RampartConfig();
-
-        rc.setUser("client");
-        rc.setEncryptionUser("wso2wsas");
-        rc.setPwCbClass(Client.class.getName());
-
-        CryptoConfig sigCryptoConfig = new CryptoConfig();
-
-        
sigCryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin");
-
-        String keystore = wso2wsasHome + File.separator + "samples" +
-                          File.separator + "sts-sample" + File.separator +
-                          "conf" + File.separator + "client-truststore.jks";
-
-        Properties prop1 = new Properties();
-        prop1.put("org.apache.ws.security.crypto.merlin.keystore.type", "JKS");
-        prop1.put("org.apache.ws.security.crypto.merlin.file", keystore);
-        prop1.put("org.apache.ws.security.crypto.merlin.keystore.password", 
"wso2wsas");
-        sigCryptoConfig.setProp(prop1);
-
-        CryptoConfig encrCryptoConfig = new CryptoConfig();
-        
encrCryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin");
-
-        Properties prop2 = new Properties();
-
-        prop2.put("org.apache.ws.security.crypto.merlin.keystore.type", "JKS");
-        prop2.put("org.apache.ws.security.crypto.merlin.file", keystore);
-        prop2.put("org.apache.ws.security.crypto.merlin.keystore.password", 
"wso2wsas");
-        encrCryptoConfig.setProp(prop2);
-
-        rc.setSigCryptoConfig(sigCryptoConfig);
-        rc.setEncrCryptoConfig(encrCryptoConfig);
-
-        policy.addAssertion(rc);
-
-        return policy;
-    }
-
-    private static OMElement getRSTTemplate() throws Exception {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-        OMElement elem = fac.createOMElement(Constants.RST_TEMPLATE);
-        TrustUtil.createTokenTypeElement(RahasConstants.VERSION_05_02, 
elem).setText(XML.SAML_NS);
-        TrustUtil.createKeyTypeElement(RahasConstants.VERSION_05_02, elem, 
RahasConstants.KEY_TYPE_SYMM_KEY);
-        TrustUtil.createKeySizeElement(RahasConstants.VERSION_05_02, elem, 
256);
-        return elem;
-    }
-    
-    private static OMElement getPayload() {
-        OMFactory fac = OMAbstractFactory.getOMFactory();
-        OMElement elem = fac.createOMElement(new QName("http://www.wso2.org";, 
"greet" ));
-        elem.setText("WSO2 WSAS Rocks!!!");
-        return elem;
-    }
-    
-    public void handle(Callback[] callbacks) throws IOException,
-            UnsupportedCallbackException {
-        WSPasswordCallback cb = (WSPasswordCallback)callbacks[0];
-        cb.setPassword("wso2wsas");
-    }
+       final static String SERVICE_EPR = 
"http://localhost:9763/services/HelloService";;
+        final static String STS_EPR = 
"http://localhost:9763/services/wso2carbon-sts";;
+
+        private static final String wso2wsasHome = 
System.getProperty("wso2wsas.home");
 
+       public static void main(String[] args) throws Exception {
+               ServiceClient client = null;
+               Options options = null;
+               ConfigurationContext ctx = null;
+               Policy stsPolicy = null;
+               STSClient stsClient = null;
+               Policy servicePolicy = null;
+               Token responseToken = null;
+               TokenStorage store = null;
+                String serviceEpr = null;
+                String stsEpr = null;
+
+                if (args.length > 1) {
+                   stsEpr = args[0];
+                   serviceEpr = args[1];
+                } else {
+                   stsEpr = STS_EPR ;
+                   serviceEpr = SERVICE_EPR ;
+                }
+
+               ctx = 
ConfigurationContextFactory.createConfigurationContextFromFileSystem("repository");
+
+               stsClient = new STSClient(ctx);
+
+               stsClient.setRstTemplate(getRSTTemplate());
+               stsClient.setAction(RahasConstants.WST_NS_05_02 + 
RahasConstants.RST_ACTION_SCT);
+
+               stsPolicy = loadPolicy(wso2wsasHome + 
"/samples/sts-sample/conf/sts.policy.xml");
+
+               servicePolicy = loadPolicy(wso2wsasHome + 
"/samples/sts-sample/conf/service.policy.xml");       
+
+               responseToken = stsClient.requestSecurityToken(servicePolicy, 
stsEpr, stsPolicy,
+                               serviceEpr);
+
+               System.out.println("RECEIVED SECRET: " + 
Base64.encode(responseToken.getSecret()) + "\n");
+               System.out.println("RECEIVED TOKEN: " + 
responseToken.getToken() + "\n");
+
+               // Store token
+               store = TrustUtil.getTokenStore(ctx);
+               store.add(responseToken);
+
+               client = new ServiceClient(ctx, null);
+               client.engageModule("rampart");
+               client.engageModule("addressing");
+               options = new Options();
+               options.setAction("urn:greet");
+               
options.setSoapVersionURI(SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+               options.setProperty(RampartMessageData.KEY_RAMPART_POLICY, 
servicePolicy);
+               options.setProperty(RampartMessageData.SCT_ID, 
responseToken.getId());
+               options.setTo(new EndpointReference(serviceEpr ));
+               client.setOptions(options);
+
+               System.out.println(client.sendReceive(getPayload("Hello")));
+
+       }
+
+       private static OMElement getPayload(String value) {
+               OMFactory factory = null;
+               OMNamespace ns = null;
+               OMElement elem = null;
+               OMElement childElem = null;
+
+               factory = OMAbstractFactory.getOMFactory();
+               ns = factory.createOMNamespace("http://www.wso2.org/types";, 
"ns1");
+               elem = factory.createOMElement("greet", ns);
+               childElem = factory.createOMElement("param0", null);
+               childElem.setText(value);
+               elem.addChild(childElem);
+
+               return elem;
+       }
+
+       private static Policy loadPolicy(String xmlPath) throws Exception {
+
+               StAXOMBuilder builder = null;
+               Policy policy = null;
+               RampartConfig rc = null;
+               CryptoConfig sigCryptoConfig = null;
+               String keystore = null;
+               Properties merlinProp = null;
+               CryptoConfig encrCryptoConfig = null;
+
+               builder = new StAXOMBuilder(xmlPath);
+               policy = PolicyEngine.getPolicy(builder.getDocumentElement());
+
+               rc = new RampartConfig();
+
+               rc.setUser("client");
+               rc.setEncryptionUser("wso2carbon");
+               rc.setPwCbClass(PWCBHandler.class.getName());
+
+               keystore = wso2wsasHome + File.separator + "samples" +
+                               File.separator + "sts-sample" + File.separator +
+                               "conf" + File.separator + 
"client-truststore.jks";
+
+               merlinProp = new Properties();
+               
merlinProp.put("org.apache.ws.security.crypto.merlin.keystore.type", "JKS");
+               merlinProp.put("org.apache.ws.security.crypto.merlin.file", 
keystore);
+               
merlinProp.put("org.apache.ws.security.crypto.merlin.keystore.password", 
"wso2wsas");
+
+               sigCryptoConfig = new CryptoConfig();
+               
sigCryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin");
+               sigCryptoConfig.setProp(merlinProp);
+
+               encrCryptoConfig = new CryptoConfig();
+               
encrCryptoConfig.setProvider("org.apache.ws.security.components.crypto.Merlin");
+               encrCryptoConfig.setProp(merlinProp);
+
+               rc.setSigCryptoConfig(sigCryptoConfig);
+               rc.setEncrCryptoConfig(encrCryptoConfig);
+
+               policy.addAssertion(rc);
+
+               return policy;
+       }
+
+       private static OMElement getRSTTemplate() throws Exception {
+               OMFactory fac = OMAbstractFactory.getOMFactory();
+               OMElement elem = fac.createOMElement(Constants.RST_TEMPLATE);
+               TrustUtil.createTokenTypeElement(RahasConstants.VERSION_05_02, 
elem).setText(XML.SAML_NS);
+               TrustUtil.createKeyTypeElement(RahasConstants.VERSION_05_02, 
elem,
+                               RahasConstants.KEY_TYPE_SYMM_KEY);
+               TrustUtil.createKeySizeElement(RahasConstants.VERSION_05_02, 
elem, 256);
+               return elem;
+       }
 }

Added: 
trunk/wsas/java/modules/samples/sts-sample/src/org/wso2/wsas/sample/sts/client/PWCBHandler.java
URL: 
http://wso2.org/svn/browse/wso2/trunk/wsas/java/modules/samples/sts-sample/src/org/wso2/wsas/sample/sts/client/PWCBHandler.java?pathrev=27474
==============================================================================
--- (empty file)
+++ 
trunk/wsas/java/modules/samples/sts-sample/src/org/wso2/wsas/sample/sts/client/PWCBHandler.java
     Sat Dec 20 11:39:41 2008
@@ -0,0 +1,15 @@
+package org.wso2.wsas.sample.sts.client;
+
+import org.apache.ws.security.WSPasswordCallback;
+
+import javax.security.auth.callback.Callback;
+import javax.security.auth.callback.CallbackHandler;
+import javax.security.auth.callback.UnsupportedCallbackException;
+
+public class PWCBHandler implements CallbackHandler {
+
+       public void handle(Callback[] callbacks) throws 
UnsupportedCallbackException {
+               WSPasswordCallback cb = (WSPasswordCallback) callbacks[0];
+               cb.setPassword("wso2wsas");
+       }
+}

_______________________________________________
Wsas-java-dev mailing list
[email protected]
https://wso2.org/cgi-bin/mailman/listinfo/wsas-java-dev

Reply via email to