camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1310244 - in /camel/trunk/components/camel-shiro/src: main/java/org/apache/camel/component/shiro/security/ test/java/org/apache/camel/component/shiro/security/
Date Fri, 06 Apr 2012 08:56:19 GMT
Author: davsclaus
Date: Fri Apr  6 08:56:19 2012
New Revision: 1310244

URL: http://svn.apache.org/viewvc?rev=1310244&view=rev
Log:
Polished

Modified:
    camel/trunk/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityPolicy.java
    camel/trunk/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityTokenInjector.java
    camel/trunk/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthenticationTest.java
    camel/trunk/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthorizationTest.java

Modified: camel/trunk/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityPolicy.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityPolicy.java?rev=1310244&r1=1310243&r2=1310244&view=diff
==============================================================================
--- camel/trunk/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityPolicy.java
(original)
+++ camel/trunk/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityPolicy.java
Fri Apr  6 08:56:19 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/trunk/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityTokenInjector.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityTokenInjector.java?rev=1310244&r1=1310243&r2=1310244&view=diff
==============================================================================
--- camel/trunk/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityTokenInjector.java
(original)
+++ camel/trunk/components/camel-shiro/src/main/java/org/apache/camel/component/shiro/security/ShiroSecurityTokenInjector.java
Fri Apr  6 08:56:19 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/trunk/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthenticationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthenticationTest.java?rev=1310244&r1=1310243&r2=1310244&view=diff
==============================================================================
--- camel/trunk/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthenticationTest.java
(original)
+++ camel/trunk/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthenticationTest.java
Fri Apr  6 08:56:19 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/trunk/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthorizationTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthorizationTest.java?rev=1310244&r1=1310243&r2=1310244&view=diff
==============================================================================
--- camel/trunk/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthorizationTest.java
(original)
+++ camel/trunk/components/camel-shiro/src/test/java/org/apache/camel/component/shiro/security/ShiroAuthorizationTest.java
Fri Apr  6 08:56:19 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);
         }
         



Mime
View raw message