Samples JDK
SSLInterceptor.java
1 package com.freemindcafe.apache.cxf.wsdl.sample3;
2 
3 import java.security.cert.X509Certificate;
4 
5 import javax.naming.InvalidNameException;
6 import javax.naming.ldap.LdapName;
7 import javax.naming.ldap.Rdn;
8 import javax.servlet.http.HttpServletRequest;
9 
10 import org.apache.cxf.binding.soap.SoapMessage;
11 import org.apache.cxf.binding.soap.interceptor.SoapHeaderInterceptor;
12 import org.apache.cxf.interceptor.Fault;
13 import org.apache.cxf.transport.http.AbstractHTTPDestination;
14 import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
15 
16 //\cond HIDDEN_SYMBOLS
17 //Phase.PRE_PROTOCOL
18 public class SSLInterceptor extends WSS4JInInterceptor{
19 
20  public void handleMessage(SoapMessage message) throws Fault {
21  System.out.println("SSLInterceptor-----------------");
22  //if you want to read more http header messages, just use get method to obtain from HttpServletRequest.
23  HttpServletRequest request = (HttpServletRequest) message.get(AbstractHTTPDestination.HTTP_REQUEST);
24  X509Certificate certs[] =
25  (X509Certificate[])request.getAttribute("javax.servlet.request.X509Certificate");
26  String dn = certs[0].getSubjectX500Principal().getName();
27  LdapName ldapDN;
28  try {
29  ldapDN = new LdapName(dn);
30  for(Rdn rdn: ldapDN.getRdns()) {
31  System.out.println(rdn.getType() + " -> " + rdn.getValue());
32  }
33  } catch (InvalidNameException e) {
34  // TODO Auto-generated catch block
35  e.printStackTrace();
36  }
37 
38  }
39 
40 
41 }
42 //\endcond