You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by ff...@apache.org on 2009/06/18 12:34:18 UTC

svn commit: r786010 - in /servicemix/components/bindings/servicemix-cxf-bc/trunk/src: main/java/org/apache/servicemix/cxfbc/ main/java/org/apache/servicemix/cxfbc/interceptors/ test/resources/org/apache/servicemix/cxfbc/ws/security/

Author: ffang
Date: Thu Jun 18 10:34:18 2009
New Revision: 786010

URL: http://svn.apache.org/viewvc?rev=786010&view=rev
Log:
[SMXCOMP-572]JbiJAASInterceptor should also support WS-Security X.509 Certificate Token Profile

Modified:
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiJAASInterceptor.java
    servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/xbean.xml

Modified: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java?rev=786010&r1=786009&r2=786010&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java (original)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/CxfBcConsumer.java Thu Jun 18 10:34:18 2009
@@ -178,6 +178,8 @@
     private boolean isSTFlow;
    
     private ClassLoader suClassLoader;
+   
+    private boolean x509;
 
     /**
      * @return the wsdl
@@ -456,7 +458,7 @@
             cxfService.getInInterceptors().add(new JbiJAASInterceptor(
                     AuthenticationService.Proxy.create(
                         ((CxfBcComponent)this.getServiceUnit().getComponent()).
-                            getConfiguration().getAuthenticationService())));
+                            getConfiguration().getAuthenticationService()), isX509()));
             cxfService.getInInterceptors().add(new JbiInvokerInterceptor());
             cxfService.getInInterceptors().add(new JbiPostInvokerInterceptor());
 
@@ -1078,5 +1080,21 @@
     public List<AbstractFeature> getFeatures() {
         return features;
     }
+ 
+    /**
+     * Specifies if the endpoint use X.509 Certificate to do the authentication.
+     * 
+     * @param x509
+     *            a boolean
+     * @org.apache.xbean.Property description="Specifies if the endpoint use X.509 Certificate to do the authentication.
+     *  Default is <code>false</code>. 
+     */
+    public void setX509(boolean x509) {
+        this.x509 = x509;
+    }
+
+    public boolean isX509() {
+        return x509;
+    }
 
 }

Modified: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiJAASInterceptor.java
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiJAASInterceptor.java?rev=786010&r1=786009&r2=786010&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiJAASInterceptor.java (original)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/main/java/org/apache/servicemix/cxfbc/interceptors/JbiJAASInterceptor.java Thu Jun 18 10:34:18 2009
@@ -17,6 +17,7 @@
 package org.apache.servicemix.cxfbc.interceptors;
 
 import java.security.GeneralSecurityException;
+import java.security.cert.X509Certificate;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
@@ -34,25 +35,27 @@
 import org.apache.ws.security.handler.WSHandlerConstants;
 import org.apache.ws.security.handler.WSHandlerResult;
 
+
 public class JbiJAASInterceptor extends AbstractWSS4JInterceptor {
 
     private String domain = "servicemix-domain";
     private AuthenticationService authenticationService;
     private ThreadLocal<Subject> currentSubject = new ThreadLocal<Subject>();
+    private boolean x509;
     
     
-    public JbiJAASInterceptor(AuthenticationService authenticationService) {
+    public JbiJAASInterceptor(AuthenticationService authenticationService, boolean x509) {
         super();
         setPhase(Phase.PRE_PROTOCOL);
         getAfter().add(WSS4JInInterceptor.class.getName());
         this.authenticationService = authenticationService;
+        this.x509 = x509;
     }
     
     
     public void handleMessage(SoapMessage message) throws Fault {
      
         try {
-            
             Subject subject = (Subject) currentSubject.get();
             
             if (subject == null) {
@@ -68,6 +71,11 @@
                 if (hr == null || hr.getResults() == null) {
                     return;
                 }
+                boolean authenticated = false;
+                
+                //favor WSSE UsernameToken based authentication over X.509 certificate
+                //based authentication. For that purpose we iterate twice over the 
+                //WSHandler result list
                 for (Iterator it = hr.getResults().iterator(); it.hasNext();) {
                     WSSecurityEngineResult er = (WSSecurityEngineResult) it.next();
                         
@@ -75,8 +83,22 @@
                         WSUsernameTokenPrincipal p = (WSUsernameTokenPrincipal)er.getPrincipal();
                         subject.getPrincipals().add(p);
                         this.authenticationService.authenticate(subject, domain, p.getName(), p.getPassword());
+                        authenticated = true;
                     }
                 }
+                
+                //Second iteration checking for X.509 certificate to run authentication on
+                //but only if not already authenticated on WSSE UsernameToken
+                if (!authenticated && x509) {
+	                for (Iterator it = hr.getResults().iterator(); it.hasNext();) {
+	                  WSSecurityEngineResult er = (WSSecurityEngineResult) it.next();
+	
+	                    if (er != null && er.getCertificate() instanceof X509Certificate) {
+	                      X509Certificate cert = er.getCertificate();
+	                      this.authenticationService.authenticate(subject, domain, cert.getIssuerX500Principal().getName(), cert);
+	                  }
+	                }
+                }
             }
             
             message.put(Subject.class, subject);

Modified: servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/xbean.xml
URL: http://svn.apache.org/viewvc/servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/xbean.xml?rev=786010&r1=786009&r2=786010&view=diff
==============================================================================
--- servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/xbean.xml (original)
+++ servicemix/components/bindings/servicemix-cxf-bc/trunk/src/test/resources/org/apache/servicemix/cxfbc/ws/security/xbean.xml Thu Jun 18 10:34:18 2009
@@ -46,6 +46,7 @@
                       targetEndpoint="TimestampSignEncrypt"
                       targetService="greeter:SOAPServiceWSSecurity"
 		      targetInterface="greeter:Greeter"
+                      x509="false"
                       >
         <cxfbc:inInterceptors>
           <bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>