You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicemix.apache.org by gn...@apache.org on 2007/06/26 14:28:35 UTC

svn commit: r550790 - /incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/WSSecurityHandler.java

Author: gnodet
Date: Tue Jun 26 05:28:35 2007
New Revision: 550790

URL: http://svn.apache.org/viewvc?view=rev&rev=550790
Log:
SM-972: authenticationService is null - Several SA deployed on the same instance of Smx

Modified:
    incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/WSSecurityHandler.java

Modified: incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/WSSecurityHandler.java
URL: http://svn.apache.org/viewvc/incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/WSSecurityHandler.java?view=diff&rev=550790&r1=550789&r2=550790
==============================================================================
--- incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/WSSecurityHandler.java (original)
+++ incubator/servicemix/branches/servicemix-3.1/common/servicemix-soap/src/main/java/org/apache/servicemix/soap/handlers/security/WSSecurityHandler.java Tue Jun 26 05:28:35 2007
@@ -78,10 +78,15 @@
     private CallbackHandler handler = new DefaultHandler();
     
     private ThreadLocal currentSubject = new ThreadLocal();
+    private static ThreadLocal currentHandler = new ThreadLocal();
 
     public WSSecurityHandler() {
         WSSecurityEngine.setWssConfig(new ServiceMixWssConfig());
     }
+
+    static WSSecurityHandler getCurrentHandler() {
+        return (WSSecurityHandler) currentHandler.get();
+    }
     
     /**
      * @return the authenticationService
@@ -97,7 +102,7 @@
         this.authenticationService = authenticationService;
     }
 
-    private class ServiceMixWssConfig extends WSSConfig {
+    private static class ServiceMixWssConfig extends WSSConfig {
         public Processor getProcessor(QName el) throws WSSecurityException {
             if (el.equals(WSSecurityEngine.SIGNATURE)) {
                 return new SignatureProcessor();
@@ -107,7 +112,7 @@
         }
     }
     
-    private class SignatureProcessor extends org.apache.ws.security.processor.SignatureProcessor {
+    private static class SignatureProcessor extends org.apache.ws.security.processor.SignatureProcessor {
         private String signatureId;
         public void handleToken(Element elem, Crypto crypto, Crypto decCrypto, CallbackHandler cb, WSDocInfo wsDocInfo, Vector returnResults, WSSConfig wsc) throws WSSecurityException {
             WSDocInfoStore.store(wsDocInfo);
@@ -116,13 +121,14 @@
             byte[][] signatureValue = new byte[1][];
             Principal lastPrincipalFound = null;
             try {
+                WSSecurityHandler handler = WSSecurityHandler.getCurrentHandler();
                 lastPrincipalFound = verifyXMLSignature((Element) elem,
                         crypto, returnCert, returnElements, signatureValue);
                 if (lastPrincipalFound instanceof WSUsernameTokenPrincipal) {
                     WSUsernameTokenPrincipal p = (WSUsernameTokenPrincipal) lastPrincipalFound;
-                    checkUser(p.getName(), p.getPassword());
+                    handler.checkUser(p.getName(), p.getPassword());
                 } else {
-                    checkUser(returnCert[0].getSubjectX500Principal().getName(), returnCert[0]);
+                    handler.checkUser(returnCert[0].getSubjectX500Principal().getName(), returnCert[0]);
                 }
             } catch (GeneralSecurityException e) {
                 throw new WSSecurityException("Unable to authenticate user", e);
@@ -425,6 +431,7 @@
         } finally {
             reqData.clear();
             currentSubject.set(null);
+            currentHandler.set(null);
         }
     }
 
@@ -508,6 +515,7 @@
         finally {
             reqData.clear();
             reqData = null;
+            currentHandler.set(null);
         }
     }
 
@@ -560,6 +568,7 @@
     
     protected void init(Context context) {
         currentSubject.set(null);
+        currentHandler.set(this);
         if (context.getProperty(Context.AUTHENTICATION_SERVICE) != null) {
             setAuthenticationService((AuthenticationService) context.getProperty(Context.AUTHENTICATION_SERVICE));
         }