You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2012/04/11 21:58:00 UTC

svn commit: r1324964 - in /camel/branches/camel-2.9.x: ./ components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/

Author: hadrian
Date: Wed Apr 11 19:57:59 2012
New Revision: 1324964

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

........
  r1310244 | davsclaus | 2012-04-06 04:56:19 -0400 (Fri, 06 Apr 2012) | 1 line
  
  Polished
........

Modified:
    camel/branches/camel-2.9.x/   (props changed)
    camel/branches/camel-2.9.x/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityPolicy.java
    camel/branches/camel-2.9.x/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityTokenInjector.java
    camel/branches/camel-2.9.x/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthenticationTest.java
    camel/branches/camel-2.9.x/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthorizationTest.java

Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.9.x/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityPolicy.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityPolicy.java?rev=1324964&r1=1324963&r2=1324964&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityPolicy.java (original)
+++ camel/branches/camel-2.9.x/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityPolicy.java Wed Apr 11 19:57:59 2012
@@ -31,6 +31,7 @@ import org.apache.camel.spi.Authorizatio
 import org.apache.camel.spi.RouteContext;
 import org.apache.camel.util.AsyncProcessorConverterHelper;
 import org.apache.camel.util.AsyncProcessorHelper;
+import org.apache.camel.util.IOHelper;
 import org.apache.shiro.SecurityUtils;
 import org.apache.shiro.authc.AuthenticationException;
 import org.apache.shiro.authc.IncorrectCredentialsException;
@@ -165,12 +166,15 @@ public class ShiroSecurityPolicy impleme
                 
                 ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(decryptedToken.getBytes());
                 ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
-                ShiroSecurityToken securityToken = (ShiroSecurityToken)objectInputStream.readObject();
-                objectInputStream.close();
-                byteArrayInputStream.close();
-                
+                ShiroSecurityToken securityToken;
+                try {
+                    securityToken = (ShiroSecurityToken)objectInputStream.readObject();
+                } finally {
+                    IOHelper.close(objectInputStream, byteArrayInputStream);
+                }
+
                 Subject currentUser = SecurityUtils.getSubject();
-                
+
                 // Authenticate user if not authenticated
                 try {
                     authenticateUser(currentUser, securityToken);
@@ -180,10 +184,8 @@ public class ShiroSecurityPolicy impleme
                 } finally {
                     if (alwaysReauthenticate) {
                         currentUser.logout();
-                        currentUser = null;
                     }
                 }
-
             }
         };
     }

Modified: camel/branches/camel-2.9.x/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityTokenInjector.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityTokenInjector.java?rev=1324964&r1=1324963&r2=1324964&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityTokenInjector.java (original)
+++ camel/branches/camel-2.9.x/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityTokenInjector.java Wed Apr 11 19:57:59 2012
@@ -17,11 +17,13 @@
 package org.apache.camel.component.shiro.security;
 
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.ObjectOutput;
 import java.io.ObjectOutputStream;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.util.IOHelper;
 import org.apache.shiro.crypto.AesCipherService;
 import org.apache.shiro.crypto.CipherService;
 import org.apache.shiro.util.ByteSource;
@@ -55,14 +57,15 @@ public class ShiroSecurityTokenInjector 
     }
 
     public ByteSource encrypt() throws Exception {
-        ByteArrayOutputStream stream = new  ByteArrayOutputStream();
+        ByteArrayOutputStream stream = new ByteArrayOutputStream();
         ObjectOutput serialStream = new ObjectOutputStream(stream);
-        serialStream.writeObject(securityToken);
-        ByteSource byteSource = cipherService.encrypt(stream.toByteArray(), passPhrase);
-        serialStream.close();
-        stream.close();
-        
-        return byteSource;
+        try {
+            serialStream.writeObject(securityToken);
+            return cipherService.encrypt(stream.toByteArray(), passPhrase);
+        } finally {
+            close(serialStream);
+            IOHelper.close(stream);
+        }
     }
 
     public void process(Exchange exchange) throws Exception {
@@ -92,5 +95,13 @@ public class ShiroSecurityTokenInjector 
     public void setCipherService(CipherService cipherService) {
         this.cipherService = cipherService;
     }
-    
+
+    private static void close(ObjectOutput output) {
+        try {
+            output.close();
+        } catch (IOException e) {
+            // ignore
+        }
+    }
+
 }

Modified: camel/branches/camel-2.9.x/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthenticationTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthenticationTest.java?rev=1324964&r1=1324963&r2=1324964&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthenticationTest.java (original)
+++ camel/branches/camel-2.9.x/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthenticationTest.java Wed Apr 11 19:57:59 2012
@@ -16,13 +16,12 @@
  */
 package org.apache.camel.component.shiro.security;
 
-import javax.naming.AuthenticationException;
-
 import org.apache.camel.EndpointInject;
 import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.shiro.authc.AuthenticationException;
 import org.apache.shiro.authc.IncorrectCredentialsException;
 import org.apache.shiro.authc.LockedAccountException;
 import org.apache.shiro.authc.UnknownAccountException;
@@ -77,18 +76,13 @@ public class ShiroAuthenticationTest ext
         
         return new RouteBuilder() {
             public void configure() {
-                onException(UnknownAccountException.class).
-                    to("mock:authenticationException");
-                onException(IncorrectCredentialsException.class).
-                    to("mock:authenticationException");
-                onException(LockedAccountException.class).
-                    to("mock:authenticationException");
-                onException(AuthenticationException.class).
+                onException(UnknownAccountException.class, IncorrectCredentialsException.class,
+                        LockedAccountException.class, AuthenticationException.class).
                     to("mock:authenticationException");
-                
+
                 from("direct:secureEndpoint").
-                    to("log:incoming payload").
                     policy(securityPolicy).
+                    to("log:incoming payload").
                     to("mock:success");
             }
         };
@@ -97,8 +91,7 @@ public class ShiroAuthenticationTest ext
     
     private static class TestShiroSecurityTokenInjector extends ShiroSecurityTokenInjector {
 
-        public TestShiroSecurityTokenInjector(
-                ShiroSecurityToken shiroSecurityToken, byte[] bytes) {
+        public TestShiroSecurityTokenInjector(ShiroSecurityToken shiroSecurityToken, byte[] bytes) {
             super(shiroSecurityToken, bytes);
         }
         

Modified: camel/branches/camel-2.9.x/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthorizationTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthorizationTest.java?rev=1324964&r1=1324963&r2=1324964&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthorizationTest.java (original)
+++ camel/branches/camel-2.9.x/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthorizationTest.java Wed Apr 11 19:57:59 2012
@@ -104,8 +104,8 @@ public class ShiroAuthorizationTest exte
                     to("mock:authorizationException");
                 
                 from("direct:secureEndpoint").
-                    to("log:incoming payload").
                     policy(securityPolicy).
+                    to("log:incoming payload").
                     to("mock:success");
             }
         };
@@ -114,8 +114,7 @@ public class ShiroAuthorizationTest exte
     
     private static class TestShiroSecurityTokenInjector extends ShiroSecurityTokenInjector {
 
-        public TestShiroSecurityTokenInjector(
-                ShiroSecurityToken shiroSecurityToken, byte[] bytes) {
+        public TestShiroSecurityTokenInjector(ShiroSecurityToken shiroSecurityToken, byte[] bytes) {
             super(shiroSecurityToken, bytes);
         }