You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2015/06/25 13:37:17 UTC
tomee git commit: TOMEE-1608 adding Logout command for remote initial
context
Repository: tomee
Updated Branches:
refs/heads/master c040c48b5 -> d65920c46
TOMEE-1608 adding Logout command for remote initial context
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/d65920c4
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/d65920c4
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/d65920c4
Branch: refs/heads/master
Commit: d65920c463679eefc5977fb42dc54fc852fb1a1b
Parents: c040c48
Author: Romain Manni-Bucau <rm...@apache.org>
Authored: Thu Jun 25 13:37:01 2015 +0200
Committer: Romain Manni-Bucau <rm...@apache.org>
Committed: Thu Jun 25 13:37:01 2015 +0200
----------------------------------------------------------------------
.../org/apache/openejb/client/JNDIContext.java | 58 +++++++---
.../apache/openejb/client/LogoutRequest.java | 68 ++++++++++++
.../apache/openejb/client/LogoutResponse.java | 111 +++++++++++++++++++
.../org/apache/openejb/client/RequestType.java | 1 +
.../org/apache/openejb/client/Response.java | 6 +-
.../apache/openejb/client/ResponseCodes.java | 3 +
.../openejb/server/ejbd/AuthRequestHandler.java | 3 -
.../apache/openejb/server/ejbd/EjbDaemon.java | 16 +++
.../server/ejbd/LogoutRequestHandler.java | 95 ++++++++++++++++
.../openejb/SecurityServiceDoesntLeakTest.java | 95 ++++++++++++++++
.../src/test/resources/login.config | 6 +
11 files changed, 438 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/d65920c4/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java b/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
index a38cac6..2e2cfef 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContext.java
@@ -20,24 +20,6 @@ import org.apache.openejb.client.event.RemoteInitialContextCreated;
import org.apache.openejb.client.serializer.EJBDSerializer;
import org.omg.CORBA.ORB;
-import javax.naming.AuthenticationException;
-import javax.naming.Binding;
-import javax.naming.CompoundName;
-import javax.naming.ConfigurationException;
-import javax.naming.Context;
-import javax.naming.InvalidNameException;
-import javax.naming.Name;
-import javax.naming.NameClassPair;
-import javax.naming.NameNotFoundException;
-import javax.naming.NameParser;
-import javax.naming.NamingEnumeration;
-import javax.naming.NamingException;
-import javax.naming.OperationNotSupportedException;
-import javax.naming.Reference;
-import javax.naming.ServiceUnavailableException;
-import javax.naming.spi.InitialContextFactory;
-import javax.naming.spi.NamingManager;
-import javax.sql.DataSource;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.net.ConnectException;
@@ -59,6 +41,24 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Level;
import java.util.logging.Logger;
+import javax.naming.AuthenticationException;
+import javax.naming.Binding;
+import javax.naming.CompoundName;
+import javax.naming.ConfigurationException;
+import javax.naming.Context;
+import javax.naming.InvalidNameException;
+import javax.naming.Name;
+import javax.naming.NameClassPair;
+import javax.naming.NameNotFoundException;
+import javax.naming.NameParser;
+import javax.naming.NamingEnumeration;
+import javax.naming.NamingException;
+import javax.naming.OperationNotSupportedException;
+import javax.naming.Reference;
+import javax.naming.ServiceUnavailableException;
+import javax.naming.spi.InitialContextFactory;
+import javax.naming.spi.NamingManager;
+import javax.sql.DataSource;
/**
* @version $Rev$ $Date$
@@ -717,6 +717,28 @@ public class JNDIContext implements InitialContextFactory, Context {
@Override
public void close() throws NamingException {
waitEndOfTasks(executorService);
+ if (authenticationInfo == null && client != null && client.getClientIdentity() != null) {
+ logout();
+ client.setClientIdentity(null);
+ }
+ }
+
+ private void logout() throws AuthenticationException {
+ final LogoutRequest request = new LogoutRequest(client.getClientIdentity());
+
+ final LogoutResponse response;
+ try {
+ response = LogoutResponse.class.cast(Client.request(request, new LogoutResponse(), server));
+ } catch (final RemoteException e) {
+ throw new AuthenticationException(e.getLocalizedMessage());
+ }
+
+ switch (response.getResponseCode()) {
+ case ResponseCodes.AUTH_DENIED:
+ throw AuthenticationException.class.cast(new AuthenticationException("Can't logout").initCause(response.getDeniedCause()));
+ case ResponseCodes.LOGOUT_SUCCESS:
+ default:
+ }
}
private static void waitEndOfTasks(final ExecutorService executor) {
http://git-wip-us.apache.org/repos/asf/tomee/blob/d65920c4/server/openejb-client/src/main/java/org/apache/openejb/client/LogoutRequest.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/LogoutRequest.java b/server/openejb-client/src/main/java/org/apache/openejb/client/LogoutRequest.java
new file mode 100644
index 0000000..77a9175
--- /dev/null
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/LogoutRequest.java
@@ -0,0 +1,68 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.client;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+public class LogoutRequest implements Request {
+ private static final long serialVersionUID = 1L;
+
+ private transient Object securityIdentity;
+ private transient ProtocolMetaData metaData;
+
+ public LogoutRequest() {
+ // no-op
+ }
+
+ public LogoutRequest(final Object securityIdentity) {
+ this.securityIdentity = securityIdentity;
+ }
+
+ @Override
+ public void setMetaData(final ProtocolMetaData metaData) {
+ this.metaData = metaData;
+ }
+
+ @Override
+ public RequestType getRequestType() {
+ return RequestType.LOGOUT_REQUEST;
+ }
+
+ public Object getSecurityIdentity() {
+ return securityIdentity;
+ }
+
+ @Override
+ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
+ in.readByte(); // version, future use
+ securityIdentity = in.readObject();
+ }
+
+ @Override
+ public void writeExternal(final ObjectOutput out) throws IOException {
+ // write out the version of the serialized data for future use
+ out.writeByte(1);
+ out.writeObject(securityIdentity);
+ }
+
+ public String toString() {
+ return String.valueOf(securityIdentity);
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/tomee/blob/d65920c4/server/openejb-client/src/main/java/org/apache/openejb/client/LogoutResponse.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/LogoutResponse.java b/server/openejb-client/src/main/java/org/apache/openejb/client/LogoutResponse.java
new file mode 100644
index 0000000..51c5040
--- /dev/null
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/LogoutResponse.java
@@ -0,0 +1,111 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.client;
+
+import java.io.IOException;
+import java.io.ObjectInput;
+import java.io.ObjectOutput;
+
+public class LogoutResponse implements Response {
+ private static final long serialVersionUID = 7293643855614467349L;
+
+ private transient int responseCode = -1;
+ private transient Throwable deniedCause;
+ private transient ProtocolMetaData metaData;
+
+ public LogoutResponse() {
+ }
+
+ public LogoutResponse(final int code) {
+ this.responseCode = code;
+ }
+
+ @Override
+ public void setMetaData(final ProtocolMetaData metaData) {
+ this.metaData = metaData;
+ }
+
+ public Throwable getDeniedCause() {
+ return deniedCause;
+ }
+
+ public void setDeniedCause(final Throwable deniedCause) {
+ this.deniedCause = deniedCause;
+ }
+
+ public int getResponseCode() {
+ return responseCode;
+ }
+
+ public void setResponseCode(final int responseCode) {
+ this.responseCode = responseCode;
+ }
+
+ @Override
+ public void readExternal(final ObjectInput in) throws IOException, ClassNotFoundException {
+ in.readByte(); // version, future use
+ responseCode = in.readByte();
+ switch (responseCode) {
+ case ResponseCodes.LOGOUT_SUCCESS:
+ deniedCause = null;
+ break;
+ case ResponseCodes.LOGOUT_FAILED:
+ final ThrowableArtifact ta = new ThrowableArtifact();
+ ta.setMetaData(metaData);
+ ta.readExternal(in);
+ deniedCause = ta.getThrowable();
+ break;
+ }
+ }
+
+ @Override
+ public void writeExternal(final ObjectOutput out) throws IOException {
+ // write out the version of the serialized data for future use
+ out.writeByte(1);
+
+ out.writeByte((byte) responseCode);
+ switch (responseCode) {
+ case ResponseCodes.LOGOUT_FAILED:
+ final ThrowableArtifact ta = new ThrowableArtifact(deniedCause);
+ ta.setMetaData(metaData);
+ ta.writeExternal(out);
+ break;
+ case ResponseCodes.LOGOUT_SUCCESS:
+ default:
+ }
+ }
+
+ @Override
+ public String toString() {
+ final StringBuilder sb = new StringBuilder(50);
+
+ switch (responseCode) {
+ case ResponseCodes.LOGOUT_SUCCESS: {
+ sb.append("LOGOUT_SUCCESS");
+ break;
+ }
+ case ResponseCodes.LOGOUT_FAILED: {
+ sb.append("LOGOUT_FAILED:");
+ sb.append(null != deniedCause ? deniedCause.toString() : "Unknown denial");
+ break;
+ }
+ }
+
+ return sb.toString();
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/tomee/blob/d65920c4/server/openejb-client/src/main/java/org/apache/openejb/client/RequestType.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/RequestType.java b/server/openejb-client/src/main/java/org/apache/openejb/client/RequestType.java
index 9293906..c4091a6 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/RequestType.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/RequestType.java
@@ -29,6 +29,7 @@ public enum RequestType {
JNDI_REQUEST((byte) 1),
AUTH_REQUEST((byte) 2),
CLUSTER_REQUEST((byte) 3),
+ LOGOUT_REQUEST((byte) 4),
STOP_REQUEST_Quit((byte) 'Q'),
STOP_REQUEST_quit((byte) 'q'),
STOP_REQUEST_Stop((byte) 'S'),
http://git-wip-us.apache.org/repos/asf/tomee/blob/d65920c4/server/openejb-client/src/main/java/org/apache/openejb/client/Response.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/Response.java b/server/openejb-client/src/main/java/org/apache/openejb/client/Response.java
index 473d036..a6004c2 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/Response.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/Response.java
@@ -28,13 +28,13 @@ public interface Response extends Externalizable {
*
* @param metaData ProtocolMetaData
*/
- public void setMetaData(final ProtocolMetaData metaData);
+ void setMetaData(final ProtocolMetaData metaData);
@Override
- public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
+ void readExternal(ObjectInput in) throws IOException, ClassNotFoundException;
@Override
- public void writeExternal(ObjectOutput out) throws IOException;
+ void writeExternal(ObjectOutput out) throws IOException;
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/d65920c4/server/openejb-client/src/main/java/org/apache/openejb/client/ResponseCodes.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/ResponseCodes.java b/server/openejb-client/src/main/java/org/apache/openejb/client/ResponseCodes.java
index 6e28aac..d45bf78 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/ResponseCodes.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/ResponseCodes.java
@@ -24,6 +24,8 @@ public class ResponseCodes {
public static final int AUTH_GRANTED = 1;
public static final int AUTH_REDIRECT = 2;
public static final int AUTH_DENIED = 3;
+ public static final int LOGOUT_SUCCESS = 27;
+ public static final int LOGOUT_FAILED = 28;
public static final int EJB_OK = 4;
public static final int EJB_OK_CREATE = 5;
public static final int EJB_OK_FOUND = 6;
@@ -47,5 +49,6 @@ public class ResponseCodes {
public static final int JNDI_RESOURCE = 24;
public static final int JNDI_WEBSERVICE = 25;
public static final int JNDI_REFERENCE = 26;
+ // LOGOUT codes: 27-28
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/d65920c4/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/AuthRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/AuthRequestHandler.java b/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/AuthRequestHandler.java
index 1e3fb72..8336f2c 100644
--- a/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/AuthRequestHandler.java
+++ b/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/AuthRequestHandler.java
@@ -26,14 +26,11 @@ import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.spi.SecurityService;
import org.apache.openejb.util.LogCategory;
import org.apache.openejb.util.Logger;
-import org.apache.openejb.util.Messages;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
class AuthRequestHandler extends RequestHandler {
-
- Messages _messages = new Messages("org.apache.openejb.server.util.resources");
private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_SERVER_REMOTE.createChild("auth"), "org.apache.openejb.server.util.resources");
private static final boolean debug = logger.isDebugEnabled();
http://git-wip-us.apache.org/repos/asf/tomee/blob/d65920c4/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java
----------------------------------------------------------------------
diff --git a/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java b/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java
index bd1628f..29a8018 100644
--- a/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java
+++ b/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbDaemon.java
@@ -60,6 +60,7 @@ public class EjbDaemon implements org.apache.openejb.spi.ApplicationServer {
private RequestHandler ejbHandler;
private RequestHandler jndiHandler;
private RequestHandler authHandler;
+ private RequestHandler logoutHandler;
private ClusterRequestHandler clusterHandler;
private ContainerSystem containerSystem;
@@ -78,6 +79,7 @@ public class EjbDaemon implements org.apache.openejb.spi.ApplicationServer {
ejbHandler = new EjbRequestHandler(this);
jndiHandler = new JndiRequestHandler(this);
authHandler = new AuthRequestHandler(this);
+ logoutHandler = new LogoutRequestHandler(this);
clusterHandler = new ClusterRequestHandler(this);
gzip = "true".equalsIgnoreCase(props.getProperty("gzip", "false"));
@@ -243,6 +245,9 @@ public class EjbDaemon implements org.apache.openejb.spi.ApplicationServer {
case AUTH_REQUEST:
response = processAuthRequest(ois, clientProtocol);
break;
+ case LOGOUT_REQUEST:
+ response = processLogoutRequest(ois, clientProtocol);
+ break;
default:
logger.error("\"" + requestType + " " + clientProtocol.getSpec() + "\" FAIL \"Unknown request type " + requestType);
return;
@@ -272,6 +277,9 @@ public class EjbDaemon implements org.apache.openejb.spi.ApplicationServer {
case AUTH_REQUEST:
processAuthResponse(response, oos, clientProtocol);
break;
+ case LOGOUT_REQUEST:
+ processLogoutResponse(response, oos, clientProtocol);
+ break;
default:
//Should never get here...
logger.error("\"" + requestType + " " + clientProtocol.getSpec() + "\" FAIL \"Unknown response type " + requestType);
@@ -350,6 +358,10 @@ public class EjbDaemon implements org.apache.openejb.spi.ApplicationServer {
return authHandler.processRequest(in, metaData);
}
+ public Response processLogoutRequest(final ObjectInputStream in, final ProtocolMetaData metaData) throws Exception {
+ return logoutHandler.processRequest(in, metaData);
+ }
+
public void processEjbResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception {
ejbHandler.processResponse(response, out, metaData);
}
@@ -362,6 +374,10 @@ public class EjbDaemon implements org.apache.openejb.spi.ApplicationServer {
authHandler.processResponse(response, out, metaData);
}
+ public void processLogoutResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception {
+ logoutHandler.processResponse(response, out, metaData);
+ }
+
@Override
public javax.ejb.EJBMetaData getEJBMetaData(final ProxyInfo info) {
return clientObjectFactory.getEJBMetaData(info);
http://git-wip-us.apache.org/repos/asf/tomee/blob/d65920c4/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/LogoutRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/LogoutRequestHandler.java b/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/LogoutRequestHandler.java
new file mode 100644
index 0000000..29668ac
--- /dev/null
+++ b/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/LogoutRequestHandler.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb.server.ejbd;
+
+import org.apache.openejb.client.AuthenticationResponse;
+import org.apache.openejb.client.LogoutRequest;
+import org.apache.openejb.client.LogoutResponse;
+import org.apache.openejb.client.ProtocolMetaData;
+import org.apache.openejb.client.Response;
+import org.apache.openejb.client.ResponseCodes;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.SecurityService;
+import org.apache.openejb.util.LogCategory;
+import org.apache.openejb.util.Logger;
+
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+
+class LogoutRequestHandler extends RequestHandler {
+ private static final Logger logger = Logger.getInstance(LogCategory.OPENEJB_SERVER_REMOTE.createChild("auth"), "org.apache.openejb.server.util.resources");
+ private static final boolean debug = logger.isDebugEnabled();
+
+ protected LogoutRequestHandler(final EjbDaemon daemon) {
+ super(daemon);
+ }
+
+ @Override
+ public String getName() {
+ return "Logout";
+ }
+
+ @Override
+ public Logger getLogger() {
+ return logger;
+ }
+
+ @Override
+ public Response processRequest(final ObjectInputStream in, final ProtocolMetaData metaData) throws Exception {
+ final LogoutRequest req = new LogoutRequest();
+ req.setMetaData(metaData);
+
+ final LogoutResponse res = new LogoutResponse();
+ res.setMetaData(metaData);
+
+ try {
+ req.readExternal(in);
+
+ SystemInstance.get().getComponent(SecurityService.class).logout(req.getSecurityIdentity());
+
+ res.setResponseCode(ResponseCodes.LOGOUT_SUCCESS);
+ } catch (final Throwable t) {
+ res.setResponseCode(ResponseCodes.LOGOUT_FAILED);
+ res.setDeniedCause(t);
+ } finally {
+ if (debug) {
+ try {
+ logger.debug("LOGOUT REQUEST: " + req + " -- RESPONSE: " + res);
+ } catch (Exception e) {
+ //Ignore
+ }
+ }
+ }
+
+ return res;
+ }
+
+ @Override
+ public void processResponse(final Response response, final ObjectOutputStream out, final ProtocolMetaData metaData) throws Exception {
+ if (LogoutResponse.class.isInstance(response)) {
+ final LogoutResponse res = LogoutResponse.class.cast(response);
+ res.setMetaData(metaData);
+ try {
+ res.writeExternal(out);
+ } catch (final Exception e) {
+ logger.fatal("Could not write AuthenticationResponse to output stream", e);
+ }
+ } else {
+ logger.error("AuthRequestHandler cannot process an instance of: " + response.getClass().getName());
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tomee/blob/d65920c4/server/openejb-ejbd/src/test/java/org/apache/openejb/SecurityServiceDoesntLeakTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-ejbd/src/test/java/org/apache/openejb/SecurityServiceDoesntLeakTest.java b/server/openejb-ejbd/src/test/java/org/apache/openejb/SecurityServiceDoesntLeakTest.java
new file mode 100644
index 0000000..a8926d7
--- /dev/null
+++ b/server/openejb-ejbd/src/test/java/org/apache/openejb/SecurityServiceDoesntLeakTest.java
@@ -0,0 +1,95 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.apache.openejb;
+
+import org.apache.openejb.client.RemoteInitialContextFactory;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.SecurityService;
+import org.apache.openejb.testing.Classes;
+import org.apache.openejb.testing.ContainerProperties;
+import org.apache.openejb.testing.EnableServices;
+import org.apache.openejb.testing.RandomPort;
+import org.apache.openejb.testing.SimpleLog;
+import org.apache.openejb.testng.PropertiesBuilder;
+import org.apache.openejb.util.reflection.Reflections;
+import org.junit.AfterClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import java.util.Map;
+import java.util.Properties;
+import javax.ejb.Singleton;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+@SimpleLog
+@EnableServices("ejbd")
+@Classes(innerClassesAsBean = true)
+@RunWith(ApplicationComposer.class)
+public class SecurityServiceDoesntLeakTest {
+ @RandomPort("ejbd")
+ private int port;
+
+ @Test
+ public void run() throws NamingException {
+ final SecurityService ss = SystemInstance.get().getComponent(SecurityService.class);
+ assertNotNull(ss);
+
+ final Map<Object, Object> identities = (Map<Object, Object>) Reflections.get(ss, "identities");
+ assertEquals(0, identities.size());
+
+ final Properties p = new PropertiesBuilder()
+ .p("java.naming.factory.initial", RemoteInitialContextFactory.class.getName())
+ .p("java.naming.provider.url", "ejbd://localhost:" + port)
+ .p("java.naming.security.principal", "foo")
+ .p("java.naming.security.credentials", "bar")
+ .p("openejb.authentication.realmName", "PropertiesLogin")
+ .build();
+ final Context ctx = new InitialContext(p);
+
+ final CallMeRemotely handle = CallMeRemotely.class.cast(
+ ctx.lookup("java:global/openejb/CallMe!org.apache.openejb.SecurityServiceDoesntLeakTest$CallMeRemotely"));
+ assertNotNull(handle);
+ assertEquals("remote!", handle.remote());
+ assertEquals(1, identities.size());
+
+ ctx.close();
+ assertEquals(0, identities.size());
+ }
+
+ @AfterClass
+ public static void resetJAAS() {
+ System.clearProperty("java.security.auth.login.config");
+ }
+
+ @Singleton
+ public static class CallMe implements CallMeRemotely {
+ @Override
+ public String remote() {
+ return "remote!";
+ }
+ }
+
+ public interface CallMeRemotely {
+ String remote();
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/d65920c4/server/openejb-ejbd/src/test/resources/login.config
----------------------------------------------------------------------
diff --git a/server/openejb-ejbd/src/test/resources/login.config b/server/openejb-ejbd/src/test/resources/login.config
index b7009f3..2c3841b 100644
--- a/server/openejb-ejbd/src/test/resources/login.config
+++ b/server/openejb-ejbd/src/test/resources/login.config
@@ -1,3 +1,9 @@
LM {
org.apache.openejb.AuthentWithRequestTest$MyLoginModule required;
};
+PropertiesLogin {
+ org.apache.openejb.core.security.jaas.PropertiesLoginModule required
+ Debug=true
+ UsersFile="users.properties"
+ GroupsFile="groups.properties";
+};