You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2008/07/02 18:59:10 UTC

svn commit: r673442 - in /cxf/branches/2.0.x-fixes: ./ rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/ systests/src/test/java/org/apache/cxf/systest/ws/security/

Author: dkulp
Date: Wed Jul  2 09:59:09 2008
New Revision: 673442

URL: http://svn.apache.org/viewvc?rev=673442&view=rev
Log:
Merged revisions 673437 via svnmerge from 
https://svn.apache.org/repos/asf/cxf/trunk

........
  r673437 | dkulp | 2008-07-02 12:46:07 -0400 (Wed, 02 Jul 2008) | 2 lines
  
  [CXF-1680] Make wss4j provided principals available to the security context
........

Modified:
    cxf/branches/2.0.x-fixes/   (props changed)
    cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
    cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/GreeterImpl.java
    cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java

Propchange: cxf/branches/2.0.x-fixes/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java?rev=673442&r1=673441&r2=673442&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java (original)
+++ cxf/branches/2.0.x-fixes/rt/ws/security/src/main/java/org/apache/cxf/ws/security/wss4j/WSS4JInInterceptor.java Wed Jul  2 09:59:09 2008
@@ -18,6 +18,7 @@
  */
 package org.apache.cxf.ws.security.wss4j;
 
+import java.security.Principal;
 import java.security.cert.X509Certificate;
 import java.util.List;
 import java.util.Map;
@@ -40,8 +41,10 @@
 import org.apache.cxf.binding.soap.saaj.SAAJInInterceptor;
 import org.apache.cxf.common.i18n.Message;
 import org.apache.cxf.common.logging.LogUtils;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.interceptor.Fault;
 import org.apache.cxf.phase.Phase;
+import org.apache.cxf.security.SecurityContext;
 import org.apache.cxf.staxutils.StaxUtils;
 import org.apache.ws.security.WSConstants;
 import org.apache.ws.security.WSSConfig;
@@ -167,7 +170,6 @@
                     throw new WSSecurityException(WSSecurityException.INVALID_SECURITY);
                 }
             }
-
             if (reqData.getWssConfig().isEnableSignatureConfirmation()) {
                 checkSignatureConfirmation(reqData, wsResult);
             }
@@ -281,6 +283,22 @@
             i++;
         }
         msg.setContent(XMLStreamReader.class, reader);
+        
+        for (WSSecurityEngineResult o : CastUtils.cast(wsResult, WSSecurityEngineResult.class)) {
+            final Principal p = (Principal)o.get(WSSecurityEngineResult.TAG_PRINCIPAL);
+            if (p != null) {
+                SecurityContext c = new SecurityContext() {
+                    public Principal getUserPrincipal() {
+                        return p;
+                    }
+                    public boolean isUserInRole(String role) {
+                        return false;
+                    }
+                };
+                msg.put(SecurityContext.class, c);
+                break;
+            }
+        }
     }
 
     private String getAction(SoapMessage msg, SoapVersion version) {

Modified: cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/GreeterImpl.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/GreeterImpl.java?rev=673442&r1=673441&r2=673442&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/GreeterImpl.java (original)
+++ cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/GreeterImpl.java Wed Jul  2 09:59:09 2008
@@ -19,6 +19,10 @@
 
 package org.apache.cxf.systest.ws.security;
 
+import java.security.Principal;
+
+import javax.xml.ws.WebServiceContext;
+
 
 @javax.jws.WebService(
     serviceName = "SOAPServiceWSSecurity", 
@@ -29,10 +33,31 @@
 )
 public class GreeterImpl 
     extends org.apache.hello_world_soap_http.GreeterImpl {
+    
+    private static Principal user;
+    
+    public static Principal getUser() {
+        return user;
+    }
 
     public String greetMe(String me) {
+        WebServiceContext ctx = super.getContext();
+        Principal p = ctx.getUserPrincipal();
+        if (p != null) {
+            user = p;
+        }        
+        
         System.out.println("\n\n*** GreetMe called with: " + me + "***\n\n");
         return "Hello " + me;
     }
     
+    public String sayHi() {
+        WebServiceContext ctx = super.getContext();
+        Principal p = ctx.getUserPrincipal();
+        if (p != null) {
+            user = p;
+        }
+        return super.sayHi();
+    }
+    
 }

Modified: cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java
URL: http://svn.apache.org/viewvc/cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java?rev=673442&r1=673441&r2=673442&view=diff
==============================================================================
--- cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java (original)
+++ cxf/branches/2.0.x-fixes/systests/src/test/java/org/apache/cxf/systest/ws/security/WSSecurityClientTest.java Wed Jul  2 09:59:09 2008
@@ -124,6 +124,10 @@
         );
         result = source2String(dispatcher.invoke(new StreamSource(is)));
         assertTrue(result.indexOf("Bonjour") != -1);
+        //make sure the principal was set
+        assertNotNull(GreeterImpl.getUser());
+        assertEquals("alice", GreeterImpl.getUser().getName());
+        
         //
         // Sending no security headers should result in a Fault
         //