• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Jeanne Boyarsky
  • Liutauras Vilda
Sheriffs:
  • Rob Spoor
  • Bear Bibeault
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • Frits Walraven
  • Himai Minh

add certificate to httpservlet request header in axis client

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Need Help in Adding Certificate to HTTP Header in Axis Web Service Client(for certificate based authentication).

ServerSide:

This is my Server Side handler which intercepts my message that is sent and checks for certificate in HTTP header.

/**
* Simple Axis handler which looks for a http header
* containing myCert. Invoke() method
* checks these...
public class MyCertificateHandler extends BasicHandler {
/**
*
*/

private USAuthentication authenticator = new USAuthentication();


@Override
public void invoke(MessageContext context) throws AxisFault {
// Check to see if the config file has Client Certificate Authentication disabled (by default we'll enable).
String certAuth = Config.getInstance().getProperty("myapiCertificateAuth", "true");

if (certAuth.equalsIgnoreCase("false")){
logger.info("Certificate authentication disabled.");
}
else{

if (!(context.getProperty("transport.http.servletRequest") instanceof HttpServletRequest)) return;

HttpServletRequest request;
request = (HttpServletRequest)context.getProperty("transport.http.servletRequest");

String myclientCertStr = null;
Enumeration clientCertHeader = request.getHeaders("myCert");
if (clientCertHeader.hasMoreElements()) {
clientCertStr = (String)clientCertHeader.nextElement();
}

if (myclientCertStr == null) {
throw new AxisFault("There is No Certificate in header.");
}
else {
X509Certificate clientCert = CertUtilSuper.generateCertificateFromXClientCert(clientCertStr);

if (clientCert == null) {
throw new AxisFault("Cannot generate X509cert for: " + myclientCertStr);
}
else{
String subject = clientCert.getSubjectX500Principal().getName();
String ca = clientCert.getIssuerX500Principal().getName();

if (MyCertVerify.validateCert(clientCert)){ //validate cert
}
else{
logger.error("Not A Valid certificate");
throw new AxisFault("cant be validate this certificate.");
}
}
}
}


}


}


}



Client Side.

1) With the WSDL I have, i generated proxy classes using eclipse WSDL2Java

2) With proxy class (generated stub) i am setting the endpoint calling desired method

Since I’m not setting certificate anywhere I’m getting the following exception

NO Certificate in header.

Can you please help me to find out how to add certificate to Http Header when I’m using apache axis web service client
 
yashika kady
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This one worked for me.


System.setProperty("javax.net.ssl.trustStoreType", "JKS");
System.setProperty("javax.net.ssl.trustStore", "keystore.jks");
System.setProperty("javax.net.ssl.trustStorePassword", "password");
System.setProperty("javax.net.ssl.keyStoreType", "pkcs12");
System.setProperty("javax.net.ssl.keyStore", "client.p12");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
DeServiceProxy d=new DeServiceProxy ();
dm.setEndpoint("https://xxx.xx.100.xxx/services/DmtService");
dm.getDeviceStatus("61656","2256");
 
and POOF! You're gone! But look, this tiny ad is still here:
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic