tomee-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject tomee git commit: TOMEE-1952 throw denied exception when logged in the request for ejbd more properly
Date Tue, 04 Oct 2016 15:09:02 GMT
Repository: tomee
Updated Branches:
  refs/heads/master f86f5a355 -> 2493f404f


TOMEE-1952 throw denied exception when logged in the request for ejbd more properly


Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/2493f404
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/2493f404
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/2493f404

Branch: refs/heads/master
Commit: 2493f404f443025ddcfb6707de46b07b61ce4ec0
Parents: f86f5a3
Author: rmannibucau <rmannibucau@apache.org>
Authored: Tue Oct 4 17:08:51 2016 +0200
Committer: rmannibucau <rmannibucau@apache.org>
Committed: Tue Oct 4 17:08:51 2016 +0200

----------------------------------------------------------------------
 .../apache/openejb/client/EJBObjectHandler.java |  5 +++
 .../org/apache/openejb/client/EJBResponse.java  |  3 ++
 .../apache/openejb/AuthentWithRequestTest.java  | 44 ++++++++++++++------
 3 files changed, 40 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tomee/blob/2493f404/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
b/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
index 7923b70..cac4399 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/EJBObjectHandler.java
@@ -307,6 +307,11 @@ public abstract class EJBObjectHandler extends EJBInvocationHandler {
                 throw new ApplicationException((ThrowableArtifact) getResult(res));
             case ResponseCodes.EJB_OK:
                 return getResult(res);
+            case ResponseCodes.AUTH_DENIED:
+                final Object result = res.getResult();
+                if (ThrowableArtifact.class.isInstance(result)) {
+                    throw ThrowableArtifact.class.cast(result).getThrowable();
+                } // else it be a remote exception
             default:
                 throw new RemoteException("Received invalid response code from server: "
+ res.getResponseCode());
         }

http://git-wip-us.apache.org/repos/asf/tomee/blob/2493f404/server/openejb-client/src/main/java/org/apache/openejb/client/EJBResponse.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/EJBResponse.java
b/server/openejb-client/src/main/java/org/apache/openejb/client/EJBResponse.java
index 04c8c29..46959eb 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/EJBResponse.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/EJBResponse.java
@@ -110,6 +110,9 @@ public class EJBResponse implements ClusterableResponse {
             case ResponseCodes.EJB_SYS_EXCEPTION:
                 s = new StringBuffer("EJB_SYS_EXCEPTION");
                 break;
+            case ResponseCodes.AUTH_DENIED:
+                s = new StringBuffer("AUTH_DENIED");
+                break;
             default:
                 s = new StringBuffer("UNKNOWN_RESPONSE");
         }

http://git-wip-us.apache.org/repos/asf/tomee/blob/2493f404/server/openejb-ejbd/src/test/java/org/apache/openejb/AuthentWithRequestTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-ejbd/src/test/java/org/apache/openejb/AuthentWithRequestTest.java
b/server/openejb-ejbd/src/test/java/org/apache/openejb/AuthentWithRequestTest.java
index 70d834d..4d282f7 100644
--- a/server/openejb-ejbd/src/test/java/org/apache/openejb/AuthentWithRequestTest.java
+++ b/server/openejb-ejbd/src/test/java/org/apache/openejb/AuthentWithRequestTest.java
@@ -33,6 +33,7 @@ import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
 
+import javax.ejb.EJBException;
 import javax.ejb.Remote;
 import javax.ejb.Stateless;
 import javax.naming.Context;
@@ -49,6 +50,7 @@ import java.util.Properties;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
 
 public class AuthentWithRequestTest {
 
@@ -82,19 +84,37 @@ public class AuthentWithRequestTest {
         assembler.createApplication(config.configureApplication(ejbJar));
 
         try {
+            { // ok case
+                final Context context = new InitialContext(new PropertiesBuilder()
+                        .p(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName())
+                        .p(Context.PROVIDER_URL, "ejbd://127.0.0.1:" + port)
+                        .p(JNDIContext.AUTHENTICATE_WITH_THE_REQUEST, "true")
+                        .p("java.naming.security.principal", "foo")
+                        .p("java.naming.security.credentials", "bar")
+                        .p("openejb.authentication.realmName", "LM")
+                        .build());
+                final AnInterfaceRemote client = AnInterfaceRemote.class.cast(context.lookup("RemoteWithSecurityRemote"));
+                assertNotNull(client);
+
+                assertEquals("foo", client.call());
+            }
 
-            final Context context = new InitialContext(new PropertiesBuilder()
-                .p(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName())
-                .p(Context.PROVIDER_URL, "ejbd://127.0.0.1:" + port)
-                .p(JNDIContext.AUTHENTICATE_WITH_THE_REQUEST, "true")
-                .p("java.naming.security.principal", "foo")
-                .p("java.naming.security.credentials", "bar")
-                .p("openejb.authentication.realmName", "LM")
-                .build());
-            final AnInterfaceRemote client = AnInterfaceRemote.class.cast(context.lookup("RemoteWithSecurityRemote"));
-            assertNotNull(client);
-
-            assertEquals("foo", client.call());
+            {// now the failing case
+                final Context context = new InitialContext(new PropertiesBuilder()
+                        .p(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName())
+                        .p(Context.PROVIDER_URL, "ejbd://127.0.0.1:" + port)
+                        .p(JNDIContext.AUTHENTICATE_WITH_THE_REQUEST, "true")
+                        .p("java.naming.security.principal", "wrong")
+                        .p("java.naming.security.credentials", "wrong")
+                        .p("openejb.authentication.realmName", "LM")
+                        .build());
+                final AnInterfaceRemote client = AnInterfaceRemote.class.cast(context.lookup("RemoteWithSecurityRemote"));
+                try {
+                    client.call();
+                } catch (final EJBException e) {
+                    assertTrue(LoginException.class.isInstance(e.getCause()));
+                }
+            }
         } finally {
             serviceDaemon.stop();
             OpenEJB.destroy();


Mime
View raw message