Diff
Added: branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/AbstractProtocolTest.java (0 => 2653)
--- branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/AbstractProtocolTest.java (rev 0)
+++ branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/AbstractProtocolTest.java 2006-05-12 02:08:12 UTC (rev 2653)
@@ -0,0 +1,44 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openejb.client;
+
+import junit.framework.TestCase;
+
+import java.io.Externalizable;
+import java.io.IOException;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+
+/**
+ * @version $Revision$ $Date$
+ */
+public class AbstractProtocolTest extends TestCase {
+ protected void externalize(Externalizable original, Externalizable copy) throws IOException, ClassNotFoundException {
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(baos);
+
+ original.writeExternal(out);
+ out.close();
+
+ ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
+ ObjectInputStream in = new ObjectInputStream(bais);
+
+ copy.readExternal(in);
+ }
+}
Modified: branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/AuthenticationResponse.java (2652 => 2653)
--- branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/AuthenticationResponse.java 2006-05-10 17:09:41 UTC (rev 2652)
+++ branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/AuthenticationResponse.java 2006-05-12 02:08:12 UTC (rev 2653)
@@ -55,6 +55,7 @@
public class AuthenticationResponse implements Response {
private transient int responseCode = -1;
+ private transient ClientMetaData identity;
private transient ServerMetaData server;
public AuthenticationResponse(){
@@ -68,6 +69,10 @@
return responseCode;
}
+ public ClientMetaData getIdentity(){
+ return identity;
+ }
+
public ServerMetaData getServer(){
return server;
}
@@ -76,6 +81,10 @@
this.responseCode = responseCode;
}
+ public void setIdentity(ClientMetaData identity){
+ this.identity = identity;
+ }
+
public void setServer(ServerMetaData server){
this.server = server;
}
@@ -95,7 +104,13 @@
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
responseCode = in.readByte();
switch (responseCode) {
+ case AUTH_GRANTED:
+ identity = new ClientMetaData();
+ identity.readExternal(in);
+ break;
case AUTH_REDIRECT:
+ identity = new ClientMetaData();
+ identity.readExternal(in);
server = new ServerMetaData();
server.readExternal( in );
break;
@@ -122,7 +137,11 @@
public void writeExternal(ObjectOutput out) throws IOException {
out.writeByte((byte)responseCode);
switch (responseCode) {
+ case AUTH_GRANTED:
+ identity.writeExternal(out);
+ break;
case AUTH_REDIRECT:
+ identity.writeExternal(out);
server.writeExternal( out );
break;
case AUTH_DENIED:
Modified: branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/ProtocolMetaData.java (2652 => 2653)
--- branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/ProtocolMetaData.java 2006-05-10 17:09:41 UTC (rev 2652)
+++ branches/v2_1/openejb2/modules/core/src/java/org/openejb/client/ProtocolMetaData.java 2006-05-12 02:08:12 UTC (rev 2653)
@@ -48,6 +48,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.io.Externalizable;
import java.util.regex.Matcher;
/**
Modified: branches/v2_1/openejb2/modules/core/src/java/org/openejb/server/ejbd/AuthRequestHandler.java (2652 => 2653)
--- branches/v2_1/openejb2/modules/core/src/java/org/openejb/server/ejbd/AuthRequestHandler.java 2006-05-10 17:09:41 UTC (rev 2652)
+++ branches/v2_1/openejb2/modules/core/src/java/org/openejb/server/ejbd/AuthRequestHandler.java 2006-05-12 02:08:12 UTC (rev 2653)
@@ -68,8 +68,10 @@
ClientMetaData client = new ClientMetaData();
- client.setClientIdentity(new String((String) req.getPrinciple()));
+ Object clientIdentity = req.getPrinciple() == null ? "GUEST": req.getPrinciple();
+ client.setClientIdentity( clientIdentity );
+ res.setIdentity( client );
res.setResponseCode(AUTH_GRANTED);
res.writeExternal(out);
Added: branches/v2_1/openejb2/modules/core/src/test/org/openejb/client/AuthenticationRequestTest.java (0 => 2653)
--- branches/v2_1/openejb2/modules/core/src/test/org/openejb/client/AuthenticationRequestTest.java (rev 0)
+++ branches/v2_1/openejb2/modules/core/src/test/org/openejb/client/AuthenticationRequestTest.java 2006-05-12 02:08:12 UTC (rev 2653)
@@ -0,0 +1,56 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openejb.client;
+
+import junit.framework.TestCase;
+
+import javax.naming.Context;
+import javax.naming.NamingEnumeration;
+import javax.naming.Binding;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ObjectInputStream;
+import java.io.Externalizable;
+import java.io.IOException;
+
+public class AuthenticationRequestTest extends AbstractProtocolTest {
+
+ public void testExternalize1() throws Exception {
+ AuthenticationRequest request = new AuthenticationRequest(null, null);
+ AuthenticationRequest copy = new AuthenticationRequest();
+
+ externalize(request, copy);
+
+ assertEquals("reqType", request.getRequestType(), copy.getRequestType());
+ assertEquals("credentials", request.getCredentials(), copy.getCredentials());
+ assertEquals("principle", request.getPrinciple(), copy.getPrinciple());
+ }
+
+ public void testExternalize2() throws Exception {
+ AuthenticationRequest request = new AuthenticationRequest("myuser", "mypass");
+ AuthenticationRequest copy = new AuthenticationRequest();
+
+ externalize(request, copy);
+
+ assertEquals("reqType", request.getRequestType(), copy.getRequestType());
+ assertEquals("credentials", request.getCredentials(), copy.getCredentials());
+ assertEquals("principle", request.getPrinciple(), copy.getPrinciple());
+ }
+}
Added: branches/v2_1/openejb2/modules/core/src/test/org/openejb/client/AuthenticationResponseTest.java (0 => 2653)
--- branches/v2_1/openejb2/modules/core/src/test/org/openejb/client/AuthenticationResponseTest.java (rev 0)
+++ branches/v2_1/openejb2/modules/core/src/test/org/openejb/client/AuthenticationResponseTest.java 2006-05-12 02:08:12 UTC (rev 2653)
@@ -0,0 +1,44 @@
+/**
+ *
+ * Copyright 2006 The Apache Software Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.openejb.client;
+
+public class AuthenticationResponseTest extends AbstractProtocolTest {
+
+ public void testExternalize1() throws Exception {
+ AuthenticationResponse response = new AuthenticationResponse(ResponseCodes.AUTH_DENIED);
+ AuthenticationResponse copy = new AuthenticationResponse();
+
+ externalize(response, copy);
+
+ assertEquals("resType", response.getResponseCode(), copy.getResponseCode());
+ }
+
+ public void testExternalize2() throws Exception {
+ AuthenticationResponse response = new AuthenticationResponse(ResponseCodes.AUTH_REDIRECT);
+ response.setServer(new ServerMetaData("localhost", 123));
+ response.setIdentity(new ClientMetaData("FOO.SECURITY.TOKEN"));
+
+ AuthenticationResponse copy = new AuthenticationResponse();
+
+ externalize(response, copy);
+
+ assertEquals("resType", response.getResponseCode(), copy.getResponseCode());
+ assertNotNull("server", copy.getServer());
+ assertEquals("server.address", response.getServer().getAddress(), copy.getServer().getAddress());
+ assertEquals("server.port", response.getServer().getPort(), copy.getServer().getPort());
+ }
+}
Modified: branches/v2_1/openejb2/modules/core/src/test/org/openejb/client/JNDIRequestTest.java (2652 => 2653)
--- branches/v2_1/openejb2/modules/core/src/test/org/openejb/client/JNDIRequestTest.java 2006-05-10 17:09:41 UTC (rev 2652)
+++ branches/v2_1/openejb2/modules/core/src/test/org/openejb/client/JNDIRequestTest.java 2006-05-12 02:08:12 UTC (rev 2653)
@@ -48,7 +48,7 @@
import junit.framework.TestCase;
-public class JNDIRequestTest extends TestCase {
+public class JNDIRequestTest extends AbstractProtocolTest {
JNDIRequest jndiRequest;
public void testExternalize() throws Exception {
@@ -75,16 +75,4 @@
}
- private void externalize(Externalizable original, Externalizable copy) throws IOException, ClassNotFoundException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(baos);
-
- original.writeExternal(out);
- out.close();
-
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- ObjectInputStream in = new ObjectInputStream(bais);
-
- copy.readExternal(in);
- }
}
\ No newline at end of file
Modified: branches/v2_1/openejb2/modules/core/src/test/org/openejb/client/JNDIResponseTest.java (2652 => 2653)
--- branches/v2_1/openejb2/modules/core/src/test/org/openejb/client/JNDIResponseTest.java 2006-05-10 17:09:41 UTC (rev 2652)
+++ branches/v2_1/openejb2/modules/core/src/test/org/openejb/client/JNDIResponseTest.java 2006-05-12 02:08:12 UTC (rev 2653)
@@ -56,7 +56,7 @@
import junit.framework.TestCase;
-public class JNDIResponseTest extends TestCase {
+public class JNDIResponseTest extends AbstractProtocolTest {
private Context context;
public void setUp() throws Exception {
@@ -76,20 +76,13 @@
response.setResponseCode(ResponseCodes.JNDI_CONTEXT_TREE);
response.setResult(context);
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- ObjectOutputStream out = new ObjectOutputStream(baos);
- response.writeExternal(out);
- out.close();
+ JNDIResponse copy = new JNDIResponse();
- ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
- ObjectInputStream in = new ObjectInputStream(bais);
+ externalize(response, copy);
- response = new JNDIResponse();
- response.readExternal(in);
+ assertEquals("Response codes are not equal", copy.getResponseCode(),ResponseCodes.JNDI_CONTEXT_TREE);
+ Object result = copy.getResult();
- assertEquals("Response codes are not equal",response.getResponseCode(),ResponseCodes.JNDI_CONTEXT_TREE);
- Object result = response.getResult();
-
assertTrue("Result not instance of Context", result instanceof Context);
compare(context, (Context)result);
}