Please take our Survey
logo       

Choosing A Webhost:
A web hosting service is a type of Internet hosting service that allows individuals and organizations to provide their own website accessible via the World Wide Web. Web hosts are companies that provide space on a server they own for use by their clients as well as providing Internet connectivity, typically in a data center. Web hosts can also provide data center space and connectivity to the Internet for servers they do not own to be located in their data center, called colocation. more...

[PATCH] : STSAgent WS-Trust: msg#00198

apache.webservices.fx.devel

Subject: [PATCH] : STSAgent WS-Trust

Hi Dimuthu,
 
This is the new implementation of the client side in ws-trust implementation.
I think we can easily integrate ws-trust to ws-secureconversation with this.
There is a test class too.
Please have a look.
 
Rgds,
Kaushalye
 


Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish./*
* Created on Aug 18, 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.apache.ws.axis.security.trust;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Hashtable;

import javax.xml.rpc.ServiceException;

import org.apache.axis.AxisFault;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.message.SOAPBodyElement;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.ws.axis.security.WSDoAllReceiver;
import org.apache.ws.axis.security.WSDoAllSender;
import org.apache.ws.security.trust.message.token.RequestSecurityToken;
import org.apache.ws.security.trust.message.token.RequestType;
import org.apache.ws.security.trust.message.token.TokenType;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
* @author Malinda Kaushalye
*
* STSAgent is an axis specific component resides in the client side to request
a token.
* The main task is to act as an Agent on behalf of the STS.
*
*
*/
public class STSAgent {
static Log log = LogFactory.getLog(STSAgent.class.getName());
String url;
RequestSecurityToken reqSecTok;
Document doc;
SOAPEnvelope env;
Call call;

/**
* Agent initialization
* @param url Endpoint Address
* @param senderOptions WSDoAllSender options
* @param recieverOptions WSDoAllReceiver options
* @throws ServiceException
* @throws MalformedURLException
* @throws Exception
*
* @see org.apache.ws.axis.security.WSDoAllReceiver
* @see org.apache.ws.axis.security.WSDoAllSender
*/
public STSAgent(String url,Hashtable senderOptions,Hashtable
recieverOptions)throws ServiceException,MalformedURLException,Exception{
Service service = new Service();
call = (Call) service.createCall();
//--

WSDoAllSender doAllSender=new WSDoAllSender();
WSDoAllReceiver doAllReciever=new WSDoAllReceiver();

// if there are options to encrypt and sign hand them over to
WSDoAllSender/Reciever
if(senderOptions !=null){
log.debug("WSDoAllSender options are null");
doAllSender.setOptions(senderOptions);

}
if(recieverOptions !=null){
log.debug("WSDoAllReceiver options are null");
doAllReciever.setOptions(recieverOptions);
}
call.setClientHandlers(doAllSender,doAllReciever);
//--
this.url=url;
call.setTargetEndpointAddress(new URL(url));
log.debug("Endpoint Address : "+url);
env = new SOAPEnvelope();
doc = env.getAsDocument();
reqSecTok=new RequestSecurityToken(doc);
}

/**
* Sets token type element
* @param value
*/
public void setTokenTypeElement(String value){
TokenType tokenType=new TokenType(this.doc);
tokenType.setValue(value);
reqSecTok.addToken(tokenType.getElement());
}
/**
* Sets request type element
* @param value
*/
public void setRequestTypeElement(String value){
RequestType requestType=new RequestType(this.doc);
requestType.setValue(value);
reqSecTok.addToken(requestType.getElement());
}
/**
* Use this method to add any element to the request
* @param element
*/
public void setAnyElement(Element element){
reqSecTok.addToken(element);
}


/**
* request call
* Thank goes to David Del Vecchio for giving his code(=>idea)
*
* @return
* @throws AxisFault
* @throws Exception
*/
public Element request()throws AxisFault,Exception{
SOAPBodyElement sbe = new
SOAPBodyElement(reqSecTok.getElement());
env.addBodyElement(sbe);
log.debug("Invoke");
SOAPEnvelope response = call.invoke(env);
Element responseElement =response.getAsDOM();
return responseElement;
}


public Document getDoc() {
return doc;
}
public SOAPEnvelope getEnv() {
return env;
}
public RequestSecurityToken getReqSecTok() {
return reqSecTok;
}
public void setReqSecTok(RequestSecurityToken reqSecTok) {
this.reqSecTok = reqSecTok;
}
/**
* to retrieve the endpoint url of the agent
* @return
*/
public String getUrl() {
return url;
}

public void setUrl(String url) {
this.url = url;
}
}
/*
* Created on Aug 18, 2004
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package org.apache.ws.security.trust.test;

import java.net.MalformedURLException;
import java.security.cert.X509Certificate;
import java.util.Hashtable;

import javax.xml.rpc.ServiceException;

import org.apache.axis.utils.XMLUtils;
import org.apache.ws.axis.security.trust.STSAgent;
import org.apache.ws.security.WSSecurityException;
import org.apache.ws.security.components.crypto.Crypto;
import org.apache.ws.security.components.crypto.CryptoFactory;
import org.apache.ws.security.message.token.BinarySecurity;
import org.apache.ws.security.message.token.X509Security;
import org.apache.ws.security.policy.message.token.AppliesTo;
import org.apache.ws.security.trust.TrustConstants;
import org.apache.ws.security.trust.WSTrustException;
import org.apache.ws.security.trust.message.token.BaseToken;
import org.apache.ws.security.trust.message.token.TokenType;
import org.w3c.dom.Element;

/**
* @author Malinda Kaushalye
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public class STSAgentTest {
public static void main(String []args) {
try {
//This HT will provide the input values to WSDoAllSender
Hashtable hts=new Hashtable();
hts.put("signatureKeyIdentifier","DirectReference");
hts.put("user","16c73ab6-b892-458f-abf5-2f875f74882e");
//hts.put("encryptionKeyIdentifier","X509KeyIdentifier");
hts.put("signaturePropFile","crypto.properties");
hts.put("encryptionUser","16c73ab6-b892-458f-abf5-2f875f74882e");

hts.put("passwordCallbackClass","org.apache.ws.axis.oasis.PWCallback");
hts.put("action","Signature");


//This HT will provide the input values to WSDoAllReceiver
Hashtable htr=new Hashtable();
htr.put("signaturePropFile","crypto.properties");

htr.put("passwordCallbackClass","org.apache.ws.axis.oasis.PWCallback");
htr.put("action","Signature");

//if u need security uncomment this
STSAgent sTSAgent =new
STSAgent("http://localhost:8081/axis/services/SecurityTokenService",hts,htr);
//if u do not need security uncomment this
//but make sure that server side may does not need a signed request
//STSAgent sTSAgent =new
STSAgent("http://localhost:8081/axis/services/SecurityTokenService",null,null);
sTSAgent.setRequestTypeElement(TrustConstants.ISSUE_SECURITY_TOKEN);
sTSAgent.setTokenTypeElement(TokenType.SCT);
BaseToken baseToken = new BaseToken(sTSAgent.getDoc());
BinarySecurity binarySecurity = new X509Security(sTSAgent.getDoc());
Crypto crypto = CryptoFactory.getInstance("crypto.properties");
try {
X509Certificate[] certs = crypto

.getCertificates("16c73ab6-b892-458f-abf5-2f875f74882e");
((X509Security) binarySecurity).setX509Certificate(certs[0]);
baseToken.setBinarySecurityToken(binarySecurity);

} catch (WSSecurityException e) {
throw new WSTrustException(
"X509BasedRequester: generating binary security token
failed",
e);
}

AppliesTo appliesTo = new AppliesTo(sTSAgent.getDoc());
appliesTo.setValue("Kau");

sTSAgent.setAnyElement(baseToken.getElement());
sTSAgent.setAnyElement(appliesTo.getElement());

Element resp=sTSAgent.request();

System.out.println("\n============= Response ==============");
XMLUtils.PrettyElementToStream(resp, System.out);



} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

Recently Viewed:
hardware.arm.at...    cms.citadel.dev...    video.gstreamer...    java.facelets.u...    misc.basics.qna...    web.wiki.instik...    network.uip.use...    xdg.devel/2003-...    tex.bibtex.bibd...    finance.quotesp...    ietf.zeroconf/2...    redhat.blinux.g...    suse.db2/2003-0...    php.phpesp/2004...    uml.devel/2003-...    gnome.labyrinth...    qnx.openqnx.dev...    boot-loaders.gr...    db.dataperfect....    audio.audacity....    linux.uclinux.m...    editors.j.devel...    os.openbsd.tech...    kde.users.multi...   
Home | advertise | OSDir is an inevitable website. super tiny logo

Free Magazines

Cisco News
Receive a free quarterly e-newsletter with exclusive articles on how Cisco IT uses its own products and solutions to enable the business.
subscribe

Systems Management News, the newspaper for IT systems administration and data center managers! Each issue of Systems Management News is chock-full of news and analysis to help you understand what's happening in your field.
subscribe

The Enterprise Newsweekly eWeek is the essential technology information source for builders of e-business.
subscribe

Oracle Magazine Oracle Magazine contains technology strategy articles, sample code, tips, Oracle and partner news, how to articles for developers and DBAs, and more. Oracle (NASDAQ: ORCL) is the world's largest enterprise software company.
subscribe

Total Telecom Total Telecom is "The Economist of the communications industry".
subscribe

Navigation