You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by jg...@apache.org on 2016/11/28 23:22:22 UTC
[01/14] tomee git commit: Adding Http Authentication - thanks
@exabrial
Repository: tomee
Updated Branches:
refs/heads/tomee-1.7.x 819b00bce -> e0397f495
Adding Http Authentication - thanks @exabrial
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/57a4dec3
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/57a4dec3
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/57a4dec3
Branch: refs/heads/tomee-1.7.x
Commit: 57a4dec342df40d448b422dee6a3698af57c69c7
Parents: 819b00b
Author: Jonathan Gallimore <jg...@tomitribe.com>
Authored: Tue Nov 1 21:27:17 2016 +0000
Committer: Jonathan Gallimore <jg...@tomitribe.com>
Committed: Tue Nov 1 21:27:17 2016 +0000
----------------------------------------------------------------------
.../java/org/apache/openejb/client/Client.java | 120 +++++---
.../openejb/client/HttpConnectionFactory.java | 22 +-
.../org/apache/openejb/client/JNDIContext.java | 300 ++++++++++---------
.../apache/openejb/client/JNDIContextAuth.java | 79 +++++
.../catalina/remote/TomEERemoteWebapp.java | 16 +
5 files changed, 347 insertions(+), 190 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/57a4dec3/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java b/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
index 4cc352a..71c2c76 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
@@ -16,15 +16,7 @@
*/
package org.apache.openejb.client;
-import org.apache.openejb.client.event.ClientVersion;
-import org.apache.openejb.client.event.ClusterMetaDataUpdated;
-import org.apache.openejb.client.event.ObserverAdded;
-import org.apache.openejb.client.event.RequestFailed;
-import org.apache.openejb.client.event.RetryConditionAdded;
-import org.apache.openejb.client.event.RetryConditionRemoved;
-import org.apache.openejb.client.event.RetryingRequest;
-import org.apache.openejb.client.event.ServerAdded;
-import org.apache.openejb.client.event.ServerRemoved;
+import static org.apache.openejb.client.Exceptions.newIOException;
import java.io.EOFException;
import java.io.IOException;
@@ -46,7 +38,16 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
-import static org.apache.openejb.client.Exceptions.newIOException;
+import org.apache.openejb.client.HttpConnectionFactory.HttpConnection;
+import org.apache.openejb.client.event.ClientVersion;
+import org.apache.openejb.client.event.ClusterMetaDataUpdated;
+import org.apache.openejb.client.event.ObserverAdded;
+import org.apache.openejb.client.event.RequestFailed;
+import org.apache.openejb.client.event.RetryConditionAdded;
+import org.apache.openejb.client.event.RetryConditionRemoved;
+import org.apache.openejb.client.event.RetryingRequest;
+import org.apache.openejb.client.event.ServerAdded;
+import org.apache.openejb.client.event.ServerRemoved;
public class Client {
@@ -137,14 +138,15 @@ public class Client {
}
public static Response request(final Request req, final Response res, final ServerMetaData server) throws RemoteException {
- try {
- return client.processRequest(req, res, server);
- } finally {
- failed.remove();
- }
+ return request(req, res, server, null);
}
protected Response processRequest(final Request req, final Response res, final ServerMetaData server) throws RemoteException {
+ return processRequest(req, res, server, null);
+ }
+
+ protected Response processRequest(final Request req, final Response res, final ServerMetaData server,
+ JNDIContextAuth jndiContextAuth) throws RemoteException {
if (server == null) {
throw new IllegalArgumentException("Server instance cannot be null");
@@ -153,12 +155,11 @@ public class Client {
final long start = System.nanoTime();
final ClusterMetaData cluster = getClusterMetaData(server);
- //Determine which protocol to use for request writes
+ // Determine which protocol to use for request writes
final ProtocolMetaData protocolRequest = (null != COMPATIBLE_META_DATA ? COMPATIBLE_META_DATA : PROTOCOL_META_DATA);
/*----------------------------*/
/* Get a connection to server */
- /*----------------------------*/
final Connection conn;
try {
@@ -167,12 +168,15 @@ public class Client {
throw new RemoteException("Unable to connect", e);
}
+ if (jndiContextAuth != null && conn instanceof HttpConnection) {
+ ((HttpConnection) conn).setAuthenticationHeader(jndiContextAuth);
+ }
+
OutputStream out = null;
InputStream in = null;
try {
-
/*----------------------------------*/
/* Get output streams */
/*----------------------------------*/
@@ -185,7 +189,7 @@ public class Client {
}
/*----------------------------------*/
- /* Write the protocol magic */
+ /* Write the protocol magic */
/*----------------------------------*/
try {
protocolRequest.writeExternal(out);
@@ -256,7 +260,7 @@ public class Client {
}
/*----------------------------------*/
- /* Get input streams */
+ /* Get input streams */
/*----------------------------------*/
try {
@@ -267,7 +271,7 @@ public class Client {
throw newIOException("Cannot open input stream to server: ", e);
}
- //Determine the server response protocol for reading
+ // Determine the server response protocol for reading
final ProtocolMetaData protocolResponse = new ProtocolMetaData();
try {
@@ -275,11 +279,14 @@ public class Client {
} catch (final EOFException e) {
- throw newIOException("Prematurely reached the end of the stream. " + protocolResponse.getSpec() + " : " + e.getMessage(), e);
+ String message = "Prematurely reached the end of the stream. " + protocolResponse.getSpec() + " : " + e.getMessage();
+ throw newIOException(message, e);
} catch (final IOException e) {
- throw newIOException("Cannot determine server protocol version: Received " + protocolResponse.getSpec() + " : " + e.getMessage(), e);
+ String message = "Cannot determine server protocol version: Received " + protocolResponse.getSpec() + " : "
+ + e.getMessage();
+ throw newIOException(message, e);
}
final ObjectInput objectIn;
@@ -288,7 +295,8 @@ public class Client {
objectIn = new EjbObjectInputStream(in);
} catch (final IOException e) {
- throw newIOException("Cannot open object input stream to server (" + protocolResponse.getSpec() + ") : " + e.getMessage(), e);
+ String message = "Cannot open object input stream to server (" + protocolResponse.getSpec() + ") : " + e.getMessage();
+ throw newIOException(message, e);
}
/*----------------------------------*/
@@ -299,22 +307,26 @@ public class Client {
clusterResponse.setMetaData(protocolResponse);
clusterResponse.readExternal(objectIn);
switch (clusterResponse.getResponseCode()) {
- case UPDATE: {
- setClusterMetaData(server, clusterResponse.getUpdatedMetaData());
- }
+ case UPDATE: {
+ setClusterMetaData(server, clusterResponse.getUpdatedMetaData());
+ }
break;
- case FAILURE: {
- throw clusterResponse.getFailure();
- }
+ case FAILURE: {
+ throw clusterResponse.getFailure();
+ }
}
} catch (final ClassNotFoundException e) {
- throw new RemoteException("Cannot read the cluster response from the server. The class for an object being returned is not located in this system:", e);
+ String message = "Cannot read the cluster response from the server. The class for an object being returned is not located in this system:";
+ throw new RemoteException(message, e);
} catch (final IOException e) {
- throw newIOException("Cannot read the cluster response from the server (" + protocolResponse.getSpec() + ") : " + e.getMessage(), e);
+ String message = "Cannot read the cluster response from the server (" + protocolResponse.getSpec() + ") : "
+ + e.getMessage();
+ throw newIOException(message, e);
} catch (final Throwable e) {
- throw new RemoteException("Error reading cluster response from server (" + protocolResponse.getSpec() + ") : " + e.getMessage(), e);
+ String message = "Error reading cluster response from server (" + protocolResponse.getSpec() + ") : " + e.getMessage();
+ throw new RemoteException(message, e);
}
/*----------------------------------*/
@@ -324,13 +336,16 @@ public class Client {
res.setMetaData(protocolResponse);
res.readExternal(objectIn);
} catch (final ClassNotFoundException e) {
- throw new RemoteException("Cannot read the response from the server. The class for an object being returned is not located in this system:", e);
+ String message = "Cannot read the response from the server. The class for an object being returned is not located in this system:";
+ throw new RemoteException(message, e);
} catch (final IOException e) {
- throw newIOException("Cannot read the response from the server (" + protocolResponse.getSpec() + ") : " + e.getMessage(), e);
+ String message = "Cannot read the response from the server (" + protocolResponse.getSpec() + ") : " + e.getMessage();
+ throw newIOException(message, e);
} catch (final Throwable e) {
- throw new RemoteException("Error reading response from server (" + protocolResponse.getSpec() + ") : " + e.getMessage(), e);
+ String message = "Error reading response from server (" + protocolResponse.getSpec() + ") : " + e.getMessage();
+ throw new RemoteException(message, e);
}
if (retryConditions.size() > 0) {
@@ -338,18 +353,19 @@ public class Client {
final EJBResponse ejbResponse = (EJBResponse) res;
if (ejbResponse.getResult() instanceof ThrowableArtifact) {
final ThrowableArtifact artifact = (ThrowableArtifact) ejbResponse.getResult();
- //noinspection ThrowableResultOfMethodCallIgnored
+ // noinspection ThrowableResultOfMethodCallIgnored
if (retryConditions.contains(artifact.getThrowable().getClass())) {
throw new RetryException(res);
- // if (? < maxConditionRetry) {
- // throw new RetryException(res);
- // } else {
- // if (FINER) {
- // logger.log(Level.FINER, "Giving up on " + artifact.getThrowable().getClass().getName().toString());
- // }
- // }
+ // if (? < maxConditionRetry) {
+ // throw new RetryException(res);
+ // } else {
+ // if (FINER) {
+ // logger.log(Level.FINER, "Giving up on " +
+ // artifact.getThrowable().getClass().getName().toString());
+ // }
+ // }
}
}
}
@@ -357,7 +373,8 @@ public class Client {
if (FINEST) {
final long time = System.nanoTime() - start;
- final String message = String.format("Invocation %sns - %s - Request(%s) - Response(%s)", time, conn.getURI(), req, res);
+ final String message = String.format("Invocation %sns - %s - Request(%s) - Response(%s)", time, conn.getURI(), req,
+ res);
logger.log(Level.FINEST, message);
}
@@ -380,7 +397,7 @@ public class Client {
Client.fireEvent(new RetryingRequest(req, server));
- processRequest(req, res, server);
+ processRequest(req, res, server, jndiContextAuth);
} catch (final RemoteFailoverException re) {
throw re;
} catch (final RemoteException re) {
@@ -408,6 +425,15 @@ public class Client {
return res;
}
+ public static Response request(final Request req, final Response res, final ServerMetaData server, JNDIContextAuth jndiContextAuth)
+ throws RemoteException {
+ try {
+ return client.processRequest(req, res, server, jndiContextAuth);
+ } finally {
+ failed.remove();
+ }
+ }
+
public static Set<URI> getFailed() {
Set<URI> set = failed.get();
if (set == null) {
@@ -426,7 +452,7 @@ public class Client {
return getContext(server).getClusterMetaData();
}
- //openejb.client.connection.strategy
+ // openejb.client.connection.strategy
private boolean getRetry() {
return retry = Boolean.valueOf(System.getProperty("openejb.client.requestretry", retry + ""));
http://git-wip-us.apache.org/repos/asf/tomee/blob/57a4dec3/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
index 78b1928..4551305 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
@@ -16,8 +16,6 @@
*/
package org.apache.openejb.client;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSocketFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -33,6 +31,9 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
/**
* @version $Revision$ $Date$
*/
@@ -49,7 +50,7 @@ public class HttpConnectionFactory implements ConnectionFactory {
}
try {
return new HttpConnection(uri, socketFactoryMap, buffer);
- } finally { // auto adjusting buffer caching, queue avoids leaks (!= ThreadLocal)
+ } finally { // auto adjusting buffer caching, queue avoids leaks (!=ThreadLocal)
drainBuffers.add(buffer);
}
}
@@ -61,14 +62,15 @@ public class HttpConnectionFactory implements ConnectionFactory {
private OutputStream outputStream;
private final URI uri;
- public HttpConnection(final URI uri, final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap,
- final byte[] buffer) throws IOException {
+ public HttpConnection(final URI uri, final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap, final byte[] buffer)
+ throws IOException {
this.uri = uri;
this.buffer = buffer;
final URL url = uri.toURL();
final Map<String, String> params;
try {
+ // TODO username:password
params = MulticastConnectionFactory.URIs.parseParamters(uri);
} catch (final URISyntaxException e) {
throw new IllegalArgumentException("Invalid uri " + uri.toString(), e);
@@ -118,7 +120,7 @@ public class HttpConnectionFactory implements ConnectionFactory {
try {
close();
} catch (final Exception e) {
- //Ignore
+ // Ignore
}
}
@@ -132,7 +134,8 @@ public class HttpConnectionFactory implements ConnectionFactory {
IOException exception = null;
if (inputStream != null) {
// consume anything left in the buffer
- try {// use a buffer cause it is faster, check HttpInputStreamImpl
+ try {// use a buffer cause it is faster, check
+ // HttpInputStreamImpl
while (inputStream.read(buffer) > -1) {
// no-op
}
@@ -179,6 +182,9 @@ public class HttpConnectionFactory implements ConnectionFactory {
}
return inputStream;
}
- }
+ public void setAuthenticationHeader(JNDIContextAuth jndiContextAuth) {
+ jndiContextAuth.setAuthenticationHeader(httpURLConnection);
+ }
+ }
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/57a4dec3/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 852ebae..b97b636 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
@@ -16,28 +16,6 @@
*/
package org.apache.openejb.client;
-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;
@@ -61,6 +39,29 @@ 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;
+
+import org.apache.openejb.client.event.RemoteInitialContextCreated;
+import org.apache.openejb.client.serializer.EJBDSerializer;
+import org.omg.CORBA.ORB;
+
/**
* @version $Rev$ $Date$
*/
@@ -76,6 +77,7 @@ public class JNDIContext implements InitialContextFactory, Context {
public static final String POOL_THREAD_NUMBER = "openejb.client.invoker.threads";
public static final String AUTHENTICATION_REALM_NAME = "openejb.authentication.realmName";
public static final String IDENTITY_TIMEOUT = "tomee.authentication.identity.timeout";
+ public static final String HTTP_AUTH_DISABLE = "openejb.client.http.auth.disable";
private final AtomicBoolean isShutdown = new AtomicBoolean(false);
private String tail = "/";
@@ -84,6 +86,9 @@ public class JNDIContext implements InitialContextFactory, Context {
private Hashtable env;
private String moduleId;
private ClientInstance clientIdentity;
+ // TODO read HTTP_AUTH_DISABLE on creation
+ private boolean disableHttpAuth = false;
+ private JNDIContextAuth jndiContextAuth;
private static final ThreadPoolExecutor GLOBAL_CLIENT_POOL = newExecutor(10, null);
@@ -108,7 +113,8 @@ public class JNDIContext implements InitialContextFactory, Context {
private AuthenticationInfo authenticationInfo = null;
- //TODO figure out how to configure and manage the thread pool on the client side, this will do for now...
+ // TODO figure out how to configure and manage the thread pool on the client
+ // side, this will do for now...
private transient int threads;
private transient LinkedBlockingQueue<Runnable> blockingQueue;
@@ -136,15 +142,21 @@ public class JNDIContext implements InitialContextFactory, Context {
public static ThreadPoolExecutor newExecutor(final int threads, final BlockingQueue<Runnable> blockingQueue) {
/**
- This thread pool starts with 3 core threads and can grow to the limit defined by 'threads'.
- If a pool thread is idle for more than 1 minute it will be discarded, unless the core size is reached.
- It can accept up to the number of processes defined by 'queue'.
- If the queue is full then an attempt is made to add the process to the queue for 10 seconds.
- Failure to add to the queue in this time will either result in a logged rejection, or if 'block'
- is true then a final attempt is made to run the process in the current thread (the service thread).
+ * This thread pool starts with 3 core threads and can grow to the limit
+ * defined by 'threads'. If a pool thread is idle for more than 1 minute
+ * it will be discarded, unless the core size is reached. It can accept
+ * up to the number of processes defined by 'queue'. If the queue is
+ * full then an attempt is made to add the process to the queue for 10
+ * seconds. Failure to add to the queue in this time will either result
+ * in a logged rejection, or if 'block' is true then a final attempt is
+ * made to run the process in the current thread (the service thread).
*/
- final ThreadPoolExecutor executorService = new ThreadPoolExecutor(3, (threads < 3 ? 3 : threads), 1, TimeUnit.MINUTES, blockingQueue == null ? new LinkedBlockingDeque<Runnable>(Integer.parseInt(getProperty(null, POOL_QUEUE_SIZE, "2"))) : blockingQueue);
+ final ThreadPoolExecutor executorService = new ThreadPoolExecutor(3, (threads < 3 ? 3 : threads), 1,
+ TimeUnit.MINUTES,
+ blockingQueue == null
+ ? new LinkedBlockingDeque<Runnable>(Integer.parseInt(getProperty(null, POOL_QUEUE_SIZE, "2")))
+ : blockingQueue);
executorService.setThreadFactory(new ThreadFactory() {
private final AtomicInteger i = new AtomicInteger(0);
@@ -156,7 +168,8 @@ public class JNDIContext implements InitialContextFactory, Context {
t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(final Thread t, final Throwable e) {
- Logger.getLogger(EJBObjectHandler.class.getName()).log(Level.SEVERE, "Uncaught error in: " + t.getName(), e);
+ Logger.getLogger(EJBObjectHandler.class.getName()).log(Level.SEVERE,
+ "Uncaught error in: " + t.getName(), e);
}
});
@@ -183,7 +196,7 @@ public class JNDIContext implements InitialContextFactory, Context {
try {
offer = tpe.getQueue().offer(r, 10, TimeUnit.SECONDS);
} catch (final InterruptedException e) {
- //Ignore
+ // Ignore
}
if (!offer) {
@@ -213,7 +226,11 @@ public class JNDIContext implements InitialContextFactory, Context {
req.setServerHash(server.buildHash());
final JNDIResponse response = new JNDIResponse();
- Client.request(req, response, server);
+ if (authenticationInfo != null && !disableHttpAuth){
+ Client.request(req, response, server, jndiContextAuth);
+ } else {
+ Client.request(req, response, server, null);
+ }
if (null != response.getServer()) {
server.merge(response.getServer());
}
@@ -221,7 +238,7 @@ public class JNDIContext implements InitialContextFactory, Context {
}
protected AuthenticationResponse requestAuthorization(final AuthenticationRequest req) throws RemoteException {
- return (AuthenticationResponse) Client.request(req, new AuthenticationResponse(), server);
+ return (AuthenticationResponse) Client.request(req, new AuthenticationResponse(), server, jndiContextAuth);
}
@Override
@@ -232,11 +249,12 @@ public class JNDIContext implements InitialContextFactory, Context {
env = (Hashtable) environment.clone();
}
- final String userID = (String) env.get(Context.SECURITY_PRINCIPAL);
- final String psswrd = (String) env.get(Context.SECURITY_CREDENTIALS);
+ jndiContextAuth = new JNDIContextAuth((String) env.get(Context.SECURITY_PRINCIPAL),
+ ((String) env.get(Context.SECURITY_CREDENTIALS)));
String providerUrl = (String) env.get(Context.PROVIDER_URL);
- final boolean authWithRequest = "true".equalsIgnoreCase(String.class.cast(env.get(AUTHENTICATE_WITH_THE_REQUEST)));
+ final boolean authWithRequest = "true"
+ .equalsIgnoreCase(String.class.cast(env.get(AUTHENTICATE_WITH_THE_REQUEST)));
moduleId = (String) env.get("openejb.client.moduleId");
final URI location;
@@ -244,12 +262,9 @@ public class JNDIContext implements InitialContextFactory, Context {
providerUrl = addMissingParts(providerUrl);
location = new URI(providerUrl);
} catch (final URISyntaxException e) {
- throw (ConfigurationException) new ConfigurationException("Property value for " +
- Context.PROVIDER_URL +
- " invalid: " +
- providerUrl +
- " - " +
- e.getMessage()).initCause(e);
+ throw (ConfigurationException) new ConfigurationException(
+ "Property value for " + Context.PROVIDER_URL + " invalid: " + providerUrl + " - " + e.getMessage())
+ .initCause(e);
}
this.server = new ServerMetaData(location);
@@ -261,12 +276,14 @@ public class JNDIContext implements InitialContextFactory, Context {
Client.fireEvent(new RemoteInitialContextCreated(location));
- //TODO: Either aggressively initiate authentication or wait for the server to send us an authentication challenge.
- if (userID != null) {
+ // TODO: Either aggressively initiate authentication or wait for the
+ // server to send us an authentication challenge.
+ if (jndiContextAuth.username != null) {
if (!authWithRequest) {
- authenticate(userID, psswrd, false);
+ authenticate(jndiContextAuth.username, String.valueOf(jndiContextAuth.password), false);
} else {
- authenticationInfo = new AuthenticationInfo(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)), userID, psswrd.toCharArray(), getTimeout(env));
+ authenticationInfo = new AuthenticationInfo(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)),
+ jndiContextAuth.username, jndiContextAuth.password, getTimeout(env));
}
}
if (client == null) {
@@ -286,7 +303,8 @@ public class JNDIContext implements InitialContextFactory, Context {
final String serializer = (String) env.get(SERIALIZER);
if (serializer != null) {
try {
- client.setSerializer(EJBDSerializer.class.cast(Thread.currentThread().getContextClassLoader().loadClass(serializer).newInstance()));
+ client.setSerializer(EJBDSerializer.class
+ .cast(Thread.currentThread().getContextClassLoader().loadClass(serializer).newInstance()));
} catch (final Exception e) {
// no-op
}
@@ -297,7 +315,7 @@ public class JNDIContext implements InitialContextFactory, Context {
final Object o = env.get(IDENTITY_TIMEOUT);
if (null != o) {
final Long l = Long.class.cast(o);
- //noinspection ConstantConditions
+ // noinspection ConstantConditions
if (null != l) {
return l;
}
@@ -317,9 +335,11 @@ public class JNDIContext implements InitialContextFactory, Context {
/**
* Add missing parts - expected only part of the required providerUrl
* <p/>
- * TODO: Move the check to a place where it really belongs - ConnectionManager, ConnectionFactory or such
- * This method (class in general) doesn't really know what is required as far as connection details go
- * Assuming that java.net.URI or java.net.URL are going to be used is overly stated
+ * TODO: Move the check to a place where it really belongs -
+ * ConnectionManager, ConnectionFactory or such This method (class in
+ * general) doesn't really know what is required as far as connection
+ * details go Assuming that java.net.URI or java.net.URL are going to be
+ * used is overly stated
*/
String addMissingParts(String providerUrl) throws URISyntaxException {
@@ -332,7 +352,8 @@ public class JNDIContext implements InitialContextFactory, Context {
final int colonIndex = providerUrl.indexOf(":");
final int slashesIndex = providerUrl.indexOf("//");
- if (colonIndex == -1 && slashesIndex == -1) { // hostname or ip address only
+ if (colonIndex == -1 && slashesIndex == -1) { // hostname or ip
+ // address only
providerUrl = "ejbd://" + providerUrl + ":" + port;
} else if (colonIndex == -1) {
final URI providerUri = new URI(providerUrl);
@@ -347,9 +368,11 @@ public class JNDIContext implements InitialContextFactory, Context {
return providerUrl;
}
- public void authenticate(final String userID, final String psswrd, final boolean logout) throws AuthenticationException {
+ public void authenticate(final String userID, final String psswrd, final boolean logout)
+ throws AuthenticationException {
- final AuthenticationRequest req = new AuthenticationRequest(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)), userID, psswrd, getTimeout(env));
+ final AuthenticationRequest req = new AuthenticationRequest(
+ String.class.cast(env.get(AUTHENTICATION_REALM_NAME)), userID, psswrd, getTimeout(env));
if (logout) {
req.setLogoutIdentity(null != client ? client.getClientIdentity() : null);
@@ -363,22 +386,24 @@ public class JNDIContext implements InitialContextFactory, Context {
}
switch (res.getResponseCode()) {
- case ResponseCodes.AUTH_GRANTED:
- client = logout ? new ClientMetaData() : res.getIdentity();
- break;
- case ResponseCodes.AUTH_REDIRECT:
- client = logout ? new ClientMetaData() : res.getIdentity();
- server = res.getServer();
- break;
- case ResponseCodes.AUTH_DENIED:
- throw (AuthenticationException) new AuthenticationException("This principle is not authorized.").initCause(res.getDeniedCause());
+ case ResponseCodes.AUTH_GRANTED:
+ client = logout ? new ClientMetaData() : res.getIdentity();
+ break;
+ case ResponseCodes.AUTH_REDIRECT:
+ client = logout ? new ClientMetaData() : res.getIdentity();
+ server = res.getServer();
+ break;
+ case ResponseCodes.AUTH_DENIED:
+ throw (AuthenticationException) new AuthenticationException("This principle is not authorized.")
+ .initCause(res.getDeniedCause());
}
seedClientSerializer();
}
public EJBHomeProxy createEJBHomeProxy(final EJBMetaDataImpl ejbData) {
- final EJBHomeHandler handler = EJBHomeHandler.createEJBHomeHandler(executor(), ejbData, server, client, authenticationInfo);
+ final EJBHomeHandler handler = EJBHomeHandler.createEJBHomeHandler(executor(), ejbData, server, client,
+ authenticationInfo);
final EJBHomeProxy proxy = handler.createEJBHomeProxy();
handler.ejb.ejbHomeProxy = proxy;
@@ -390,7 +415,8 @@ public class JNDIContext implements InitialContextFactory, Context {
final EJBMetaDataImpl ejb = (EJBMetaDataImpl) result;
final Object primaryKey = ejb.getPrimaryKey();
- final EJBObjectHandler handler = EJBObjectHandler.createEJBObjectHandler(executor(), ejb, server, client, primaryKey, authenticationInfo);
+ final EJBObjectHandler handler = EJBObjectHandler.createEJBObjectHandler(executor(), ejb, server, client,
+ primaryKey, authenticationInfo);
return handler.createEJBObjectProxy();
}
@@ -430,72 +456,74 @@ public class JNDIContext implements InitialContextFactory, Context {
} catch (Exception e) {
if (e instanceof RemoteException && e.getCause() instanceof ConnectException) {
e = (Exception) e.getCause();
- throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot lookup '" + name + "'.").initCause(e);
+ throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot lookup '" + name + "'.")
+ .initCause(e);
}
throw (NamingException) new NamingException("Cannot lookup '" + name + "'.").initCause(e);
}
switch (res.getResponseCode()) {
- case ResponseCodes.JNDI_EJBHOME:
- return createEJBHomeProxy((EJBMetaDataImpl) res.getResult());
+ case ResponseCodes.JNDI_EJBHOME:
+ return createEJBHomeProxy((EJBMetaDataImpl) res.getResult());
- case ResponseCodes.JNDI_BUSINESS_OBJECT:
- return createBusinessObject(res.getResult());
+ case ResponseCodes.JNDI_BUSINESS_OBJECT:
+ return createBusinessObject(res.getResult());
- case ResponseCodes.JNDI_OK:
- return res.getResult();
+ case ResponseCodes.JNDI_OK:
+ return res.getResult();
- case ResponseCodes.JNDI_INJECTIONS:
- return res.getResult();
+ case ResponseCodes.JNDI_INJECTIONS:
+ return res.getResult();
- case ResponseCodes.JNDI_CONTEXT:
- final JNDIContext subCtx = new JNDIContext(this);
- if (!name.endsWith("/")) {
- name += '/';
- }
- subCtx.tail = name;
- return subCtx;
+ case ResponseCodes.JNDI_CONTEXT:
+ final JNDIContext subCtx = new JNDIContext(this);
+ if (!name.endsWith("/")) {
+ name += '/';
+ }
+ subCtx.tail = name;
+ return subCtx;
- case ResponseCodes.JNDI_DATA_SOURCE:
- return createDataSource((DataSourceMetaData) res.getResult());
+ case ResponseCodes.JNDI_DATA_SOURCE:
+ return createDataSource((DataSourceMetaData) res.getResult());
- case ResponseCodes.JNDI_WEBSERVICE:
- return createWebservice((WsMetaData) res.getResult());
+ case ResponseCodes.JNDI_WEBSERVICE:
+ return createWebservice((WsMetaData) res.getResult());
- case ResponseCodes.JNDI_RESOURCE:
- final String type = (String) res.getResult();
- value = System.getProperty("Resource/" + type);
- if (value == null) {
- return null;
- }
- return parseEntry(prop, value);
+ case ResponseCodes.JNDI_RESOURCE:
+ final String type = (String) res.getResult();
+ value = System.getProperty("Resource/" + type);
+ if (value == null) {
+ return null;
+ }
+ return parseEntry(prop, value);
- case ResponseCodes.JNDI_REFERENCE:
- final Reference ref = (Reference) res.getResult();
- try {
- return NamingManager.getObjectInstance(ref, getNameParser(name).parse(name), this, env);
- } catch (final Exception e) {
- throw (NamingException) new NamingException("Could not dereference " + ref).initCause(e);
- }
+ case ResponseCodes.JNDI_REFERENCE:
+ final Reference ref = (Reference) res.getResult();
+ try {
+ return NamingManager.getObjectInstance(ref, getNameParser(name).parse(name), this, env);
+ } catch (final Exception e) {
+ throw (NamingException) new NamingException("Could not dereference " + ref).initCause(e);
+ }
- case ResponseCodes.JNDI_NOT_FOUND:
- throw new NameNotFoundException(name + " does not exist in the system. Check that the app was successfully deployed.");
+ case ResponseCodes.JNDI_NOT_FOUND:
+ throw new NameNotFoundException(
+ name + " does not exist in the system. Check that the app was successfully deployed.");
- case ResponseCodes.JNDI_NAMING_EXCEPTION:
- final Throwable throwable = ((ThrowableArtifact) res.getResult()).getThrowable();
- if (throwable instanceof NamingException) {
- throw (NamingException) throwable;
- }
- throw (NamingException) new NamingException().initCause(throwable);
+ case ResponseCodes.JNDI_NAMING_EXCEPTION:
+ final Throwable throwable = ((ThrowableArtifact) res.getResult()).getThrowable();
+ if (throwable instanceof NamingException) {
+ throw (NamingException) throwable;
+ }
+ throw (NamingException) new NamingException().initCause(throwable);
- case ResponseCodes.JNDI_RUNTIME_EXCEPTION:
- throw (RuntimeException) res.getResult();
+ case ResponseCodes.JNDI_RUNTIME_EXCEPTION:
+ throw (RuntimeException) res.getResult();
- case ResponseCodes.JNDI_ERROR:
- throw (Error) res.getResult();
+ case ResponseCodes.JNDI_ERROR:
+ throw (Error) res.getResult();
- default:
- throw new ClientRuntimeException("Invalid response from server: " + res.getResponseCode());
+ default:
+ throw new ClientRuntimeException("Invalid response from server: " + res.getResponseCode());
}
}
@@ -528,7 +556,8 @@ public class JNDIContext implements InitialContextFactory, Context {
throw new UnsupportedOperationException("Unsupported Naming URI scheme '" + scheme + "'");
}
} catch (final URISyntaxException e) {
- throw (NamingException) new NamingException("Unparsable jndi entry '" + name + "=" + value + "'. Exception: " + e.getMessage()).initCause(e);
+ throw (NamingException) new NamingException(
+ "Unparsable jndi entry '" + name + "=" + value + "'. Exception: " + e.getMessage()).initCause(e);
}
}
@@ -596,34 +625,35 @@ public class JNDIContext implements InitialContextFactory, Context {
} catch (Exception e) {
if (e instanceof RemoteException && e.getCause() instanceof ConnectException) {
e = (Exception) e.getCause();
- throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot list '" + name + "'.").initCause(e);
+ throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot list '" + name + "'.")
+ .initCause(e);
}
throw (NamingException) new NamingException("Cannot list '" + name + "'.").initCause(e);
}
switch (res.getResponseCode()) {
- case ResponseCodes.JNDI_OK:
- return null;
+ case ResponseCodes.JNDI_OK:
+ return null;
- case ResponseCodes.JNDI_ENUMERATION:
- return (NamingEnumeration) res.getResult();
+ case ResponseCodes.JNDI_ENUMERATION:
+ return (NamingEnumeration) res.getResult();
- case ResponseCodes.JNDI_NOT_FOUND:
- throw new NameNotFoundException(name);
+ case ResponseCodes.JNDI_NOT_FOUND:
+ throw new NameNotFoundException(name);
- case ResponseCodes.JNDI_NAMING_EXCEPTION:
- final Throwable throwable = ((ThrowableArtifact) res.getResult()).getThrowable();
- if (throwable instanceof NamingException) {
- throw (NamingException) throwable;
- }
- throw (NamingException) new NamingException().initCause(throwable);
+ case ResponseCodes.JNDI_NAMING_EXCEPTION:
+ final Throwable throwable = ((ThrowableArtifact) res.getResult()).getThrowable();
+ if (throwable instanceof NamingException) {
+ throw (NamingException) throwable;
+ }
+ throw (NamingException) new NamingException().initCause(throwable);
- case ResponseCodes.JNDI_ERROR:
- throw (Error) res.getResult();
+ case ResponseCodes.JNDI_ERROR:
+ throw (Error) res.getResult();
- default:
- throw new ClientRuntimeException("Invalid response from server :" + res.getResponseCode());
+ default:
+ throw new ClientRuntimeException("Invalid response from server :" + res.getResponseCode());
}
}
@@ -675,7 +705,8 @@ public class JNDIContext implements InitialContextFactory, Context {
try {
super.setObject(context.lookup(getName()));
} catch (final NamingException e) {
- throw failed = new ClientRuntimeException("Failed to lazily fetch the binding '" + getName() + "'", e);
+ throw failed = new ClientRuntimeException("Failed to lazily fetch the binding '" + getName() + "'",
+ e);
}
}
return super.getObject();
@@ -761,7 +792,7 @@ public class JNDIContext implements InitialContextFactory, Context {
try {
this.authenticate(userID, psswrd, logout);
} catch (final Exception ignore) {
- //no-op
+ // no-op
}
}
}
@@ -904,4 +935,3 @@ public class JNDIContext implements InitialContextFactory, Context {
}
}
}
-
http://git-wip-us.apache.org/repos/asf/tomee/blob/57a4dec3/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContextAuth.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContextAuth.java b/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContextAuth.java
new file mode 100644
index 0000000..6fb7f98
--- /dev/null
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContextAuth.java
@@ -0,0 +1,79 @@
+package org.apache.openejb.client;
+
+import static javax.xml.bind.DatatypeConverter.printBase64Binary;
+
+import java.io.Serializable;
+import java.net.HttpURLConnection;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+
+public class JNDIContextAuth implements Serializable {
+ private static final long serialVersionUID = 1L;
+ public final String username;
+ public final char[] password;
+
+ public JNDIContextAuth(String username, String password) {
+ this.username = username;
+ if (password != null) {
+ this.password = password.toCharArray();
+ } else {
+ this.password = new char[0];
+ }
+ checkConstraints();
+ }
+
+ public void checkConstraints() {
+ if (username == null) {
+ throw new IllegalArgumentException("username cannot be null, don't use this class if you don't have a username");
+ }
+ }
+
+ public void setAuthenticationHeader(HttpURLConnection httpURLConnection) {
+ httpURLConnection.setRequestProperty("Authorization", "Basic " + toEncodedString());
+ }
+
+ public String toEncodedString() {
+ byte[] message = (username + ":" + String.valueOf(password)).getBytes(StandardCharsets.UTF_8);
+ String encoded = printBase64Binary(message);
+ return encoded;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + Arrays.hashCode(password);
+ result = prime * result + ((username == null) ? 0 : username.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (!(obj instanceof JNDIContextAuth)) {
+ return false;
+ }
+ JNDIContextAuth other = (JNDIContextAuth) obj;
+ if (!Arrays.equals(password, other.password)) {
+ return false;
+ }
+ if (username == null) {
+ if (other.username != null) {
+ return false;
+ }
+ } else if (!username.equals(other.username)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return "JNDIContextAuth [username=" + username + ", password=" + Arrays.toString(password) + "]";
+ }
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/57a4dec3/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
index 4a2bde9..006db5e 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
@@ -25,12 +25,17 @@ import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.server.httpd.ServerServlet;
import org.apache.tomee.catalina.IgnoredStandardContext;
import org.apache.tomee.catalina.OpenEJBValve;
+import org.apache.catalina.deploy.LoginConfig;
+import org.apache.catalina.deploy.SecurityCollection;
+import org.apache.catalina.deploy.SecurityConstraint;
import java.beans.PropertyChangeListener;
public class TomEERemoteWebapp extends IgnoredStandardContext {
private static final String CONTEXT_NAME = SystemInstance.get().getProperty("tomee.remote.support.context", "/tomee");
private static final String MAPPING = SystemInstance.get().getProperty("tomee.remote.support.mapping", "/ejb");
+ private static final String BASIC_AUTH_ROLE_NAME = SystemInstance.get().getProperty("tomee.remote.support.basicAuthRoleName", null);
+
public TomEERemoteWebapp() {
setDocBase("");
@@ -39,6 +44,17 @@ public class TomEERemoteWebapp extends IgnoredStandardContext {
setName(CONTEXT_NAME);
setPath(CONTEXT_NAME);
setLoader(new ServerClassLoaderLoader(this));
+ if (BASIC_AUTH_ROLE_NAME != null) {
+ LoginConfig config = new LoginConfig();
+ config.setAuthMethod("BASIC");
+ SecurityConstraint constraint = new SecurityConstraint();
+ SecurityCollection collection = new SecurityCollection();
+ collection.addPattern("/*");
+ constraint.addCollection(collection);
+ constraint.addAuthRole(BASIC_AUTH_ROLE_NAME);
+ addConstraint(constraint);
+ setLoginConfig(config);
+ }
addValve(new OpenEJBValve()); // ensure security context is resetted (ThreadLocal) for each request
}
[06/14] tomee git commit: cleanup more diff noise
Posted by jg...@apache.org.
cleanup more diff noise
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/68c0e0d8
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/68c0e0d8
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/68c0e0d8
Branch: refs/heads/tomee-1.7.x
Commit: 68c0e0d83b9cb3ed43790aece03d9fcc650ba6d2
Parents: 6e60951
Author: Jonathan S. Fisher <jf...@tomitribe.com>
Authored: Fri Nov 4 15:57:06 2016 -0500
Committer: Jonathan S. Fisher <jf...@tomitribe.com>
Committed: Fri Nov 4 15:57:06 2016 -0500
----------------------------------------------------------------------
.../main/java/org/apache/openejb/client/HttpConnectionFactory.java | 2 +-
.../src/main/java/org/apache/openejb/client/JNDIContext.java | 1 +
.../src/main/java/org/apache/openejb/client/ServerMetaData.java | 2 +-
3 files changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/68c0e0d8/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
index 70c2e20..240dc23 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
@@ -64,7 +64,7 @@ public class HttpConnectionFactory implements ConnectionFactory {
private final URI uri;
public HttpConnection(final URI uri, final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap,
- final byte[] buffer) throws IOException {
+ final byte[] buffer) throws IOException {
this.uri = uri;
this.buffer = buffer;
final URL url = uri.toURL();
http://git-wip-us.apache.org/repos/asf/tomee/blob/68c0e0d8/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 46b9732..120be87 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
@@ -224,6 +224,7 @@ public class JNDIContext implements InitialContextFactory, Context {
return (AuthenticationResponse) Client.request(req, new AuthenticationResponse(), server);
}
+ @Override
public Context getInitialContext(final Hashtable environment) throws NamingException {
if (environment == null) {
throw new NamingException("Invalid argument, hashtable cannot be null.");
http://git-wip-us.apache.org/repos/asf/tomee/blob/68c0e0d8/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
index b94a584..f913ca4 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
@@ -35,7 +35,7 @@ public class ServerMetaData implements Externalizable {
private transient URI[] locations;
private transient URI location;
private transient ProtocolMetaData metaData;
-
+
public ServerMetaData() {
}
[05/14] tomee git commit: cleanup diff noise
Posted by jg...@apache.org.
cleanup diff noise
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/6e60951c
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/6e60951c
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/6e60951c
Branch: refs/heads/tomee-1.7.x
Commit: 6e60951c1aa2a8642e7f59d5c7de7cee1b349193
Parents: 61b355a
Author: Jonathan S. Fisher <jf...@tomitribe.com>
Authored: Fri Nov 4 15:54:57 2016 -0500
Committer: Jonathan S. Fisher <jf...@tomitribe.com>
Committed: Fri Nov 4 15:54:57 2016 -0500
----------------------------------------------------------------------
.../openejb/client/HttpConnectionFactory.java | 12 +++++-------
.../org/apache/openejb/client/JNDIContext.java | 18 ++++++++++++++----
.../org/apache/openejb/client/ServerMetaData.java | 3 +++
3 files changed, 22 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e60951c/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
index 9cb86bd..70c2e20 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
@@ -51,7 +51,7 @@ public class HttpConnectionFactory implements ConnectionFactory {
}
try {
return new HttpConnection(uri, socketFactoryMap, buffer);
- } finally { // auto adjusting buffer caching, queue avoids leaks (!=ThreadLocal)
+ } finally { // auto adjusting buffer caching, queue avoids leaks (!= ThreadLocal)
drainBuffers.add(buffer);
}
}
@@ -63,15 +63,14 @@ public class HttpConnectionFactory implements ConnectionFactory {
private OutputStream outputStream;
private final URI uri;
- public HttpConnection(final URI uri, final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap, final byte[] buffer)
- throws IOException {
+ public HttpConnection(final URI uri, final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap,
+ final byte[] buffer) throws IOException {
this.uri = uri;
this.buffer = buffer;
final URL url = uri.toURL();
final Map<String, String> params;
try {
- // TODO username:password
params = MulticastConnectionFactory.URIs.parseParamters(uri);
} catch (final URISyntaxException e) {
throw new IllegalArgumentException("Invalid uri " + uri.toString(), e);
@@ -127,7 +126,7 @@ public class HttpConnectionFactory implements ConnectionFactory {
try {
close();
} catch (final Exception e) {
- // Ignore
+ //Ignore
}
}
@@ -141,8 +140,7 @@ public class HttpConnectionFactory implements ConnectionFactory {
IOException exception = null;
if (inputStream != null) {
// consume anything left in the buffer
- try {// use a buffer cause it is faster, check
- // HttpInputStreamImpl
+ try {// use a buffer cause it is faster, check HttpInputStreamImpl
while (inputStream.read(buffer) > -1) {
// no-op
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e60951c/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 afc5ed9..46b9732 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
@@ -234,8 +234,7 @@ public class JNDIContext implements InitialContextFactory, Context {
String providerUrl = (String) env.get(Context.PROVIDER_URL);
- final boolean authWithRequest = "true"
- .equalsIgnoreCase(String.class.cast(env.get(AUTHENTICATE_WITH_THE_REQUEST)));
+ final boolean authWithRequest = "true".equalsIgnoreCase(String.class.cast(env.get(AUTHENTICATE_WITH_THE_REQUEST)));
moduleId = (String) env.get("openejb.client.moduleId");
final URI location;
@@ -268,8 +267,8 @@ public class JNDIContext implements InitialContextFactory, Context {
if (!authWithRequest) {
authenticate(securityPrincipal, securityCredentials, false);
} else {
- authenticationInfo = new AuthenticationInfo(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)),
- securityPrincipal, securityCredentials.toCharArray(), getTimeout(env));
+ authenticationInfo = new AuthenticationInfo(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)), securityPrincipal,
+ securityCredentials.toCharArray(), getTimeout(env));
}
}
if (client == null) {
@@ -285,6 +284,17 @@ public class JNDIContext implements InitialContextFactory, Context {
return this;
}
+ private void seedClientSerializer() {
+ final String serializer = (String) env.get(SERIALIZER);
+ if (serializer != null) {
+ try {
+ client.setSerializer(EJBDSerializer.class.cast(Thread.currentThread().getContextClassLoader().loadClass(serializer).newInstance()));
+ } catch (final Exception e) {
+ // no-op
+ }
+ }
+ }
+
private long getTimeout(final Hashtable env) {
final Object o = env.get(IDENTITY_TIMEOUT);
if (null != o) {
http://git-wip-us.apache.org/repos/asf/tomee/blob/6e60951c/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
index 60c9c92..b94a584 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
@@ -35,6 +35,9 @@ public class ServerMetaData implements Externalizable {
private transient URI[] locations;
private transient URI location;
private transient ProtocolMetaData metaData;
+
+ public ServerMetaData() {
+ }
public ServerMetaData(final URI... locations) {
this.locations = locations;
[03/14] tomee git commit: reset to previous state
Posted by jg...@apache.org.
reset to previous state
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/3fa5d916
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/3fa5d916
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/3fa5d916
Branch: refs/heads/tomee-1.7.x
Commit: 3fa5d9167a5c83b624b8f1e84eabc5ee68f9de6a
Parents: ca5545a
Author: Jonathan S. Fisher <jf...@tomitribe.com>
Authored: Fri Nov 4 15:44:59 2016 -0500
Committer: Jonathan S. Fisher <jf...@tomitribe.com>
Committed: Fri Nov 4 15:44:59 2016 -0500
----------------------------------------------------------------------
.../openejb/client/HttpConnectionFactory.java | 27 +-
.../org/apache/openejb/client/JNDIContext.java | 298 +++++++++----------
.../apache/openejb/client/ServerMetaData.java | 46 +--
.../openejb/client/ServerMetaDataTest.java | 1 +
4 files changed, 148 insertions(+), 224 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/3fa5d916/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
index 9cb86bd..78b1928 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
@@ -15,7 +15,9 @@
* limitations under the License.
*/
package org.apache.openejb.client;
-import static javax.xml.bind.DatatypeConverter.printBase64Binary;
+
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -23,7 +25,6 @@ import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
-import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
@@ -32,9 +33,6 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSocketFactory;
-
/**
* @version $Revision$ $Date$
*/
@@ -51,7 +49,7 @@ public class HttpConnectionFactory implements ConnectionFactory {
}
try {
return new HttpConnection(uri, socketFactoryMap, buffer);
- } finally { // auto adjusting buffer caching, queue avoids leaks (!=ThreadLocal)
+ } finally { // auto adjusting buffer caching, queue avoids leaks (!= ThreadLocal)
drainBuffers.add(buffer);
}
}
@@ -63,15 +61,14 @@ public class HttpConnectionFactory implements ConnectionFactory {
private OutputStream outputStream;
private final URI uri;
- public HttpConnection(final URI uri, final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap, final byte[] buffer)
- throws IOException {
+ public HttpConnection(final URI uri, final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap,
+ final byte[] buffer) throws IOException {
this.uri = uri;
this.buffer = buffer;
final URL url = uri.toURL();
final Map<String, String> params;
try {
- // TODO username:password
params = MulticastConnectionFactory.URIs.parseParamters(uri);
} catch (final URISyntaxException e) {
throw new IllegalArgumentException("Invalid uri " + uri.toString(), e);
@@ -93,12 +90,6 @@ public class HttpConnectionFactory implements ConnectionFactory {
httpURLConnection.setReadTimeout(Integer.parseInt(params.get("readTimeout")));
}
- if (uri.getUserInfo() != null) {
- String authorization = "Basic "
- + printBase64Binary((url.getUserInfo()).getBytes(StandardCharsets.UTF_8));
- httpURLConnection.setRequestProperty("Authorization", authorization);
- }
-
if (params.containsKey("sslKeyStore") || params.containsKey("sslTrustStore")) {
try {
SSLSocketFactory sslSocketFactory = socketFactoryMap.get(uri);
@@ -127,7 +118,7 @@ public class HttpConnectionFactory implements ConnectionFactory {
try {
close();
} catch (final Exception e) {
- // Ignore
+ //Ignore
}
}
@@ -141,8 +132,7 @@ public class HttpConnectionFactory implements ConnectionFactory {
IOException exception = null;
if (inputStream != null) {
// consume anything left in the buffer
- try {// use a buffer cause it is faster, check
- // HttpInputStreamImpl
+ try {// use a buffer cause it is faster, check HttpInputStreamImpl
while (inputStream.read(buffer) > -1) {
// no-op
}
@@ -190,4 +180,5 @@ public class HttpConnectionFactory implements ConnectionFactory {
return inputStream;
}
}
+
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/3fa5d916/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 94dd9c3..852ebae 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
@@ -16,6 +16,28 @@
*/
package org.apache.openejb.client;
+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;
@@ -39,29 +61,6 @@ 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;
-
-import org.apache.openejb.client.event.RemoteInitialContextCreated;
-import org.apache.openejb.client.serializer.EJBDSerializer;
-import org.omg.CORBA.ORB;
-
/**
* @version $Rev$ $Date$
*/
@@ -77,7 +76,6 @@ public class JNDIContext implements InitialContextFactory, Context {
public static final String POOL_THREAD_NUMBER = "openejb.client.invoker.threads";
public static final String AUTHENTICATION_REALM_NAME = "openejb.authentication.realmName";
public static final String IDENTITY_TIMEOUT = "tomee.authentication.identity.timeout";
- public static final String HTTP_AUTH_DISABLE = "openejb.client.http.auth.disable";
private final AtomicBoolean isShutdown = new AtomicBoolean(false);
private String tail = "/";
@@ -86,8 +84,6 @@ public class JNDIContext implements InitialContextFactory, Context {
private Hashtable env;
private String moduleId;
private ClientInstance clientIdentity;
- // TODO read HTTP_AUTH_DISABLE on creation
- private boolean disableHttpAuth = false;
private static final ThreadPoolExecutor GLOBAL_CLIENT_POOL = newExecutor(10, null);
@@ -112,8 +108,7 @@ public class JNDIContext implements InitialContextFactory, Context {
private AuthenticationInfo authenticationInfo = null;
- // TODO figure out how to configure and manage the thread pool on the client
- // side, this will do for now...
+ //TODO figure out how to configure and manage the thread pool on the client side, this will do for now...
private transient int threads;
private transient LinkedBlockingQueue<Runnable> blockingQueue;
@@ -141,21 +136,15 @@ public class JNDIContext implements InitialContextFactory, Context {
public static ThreadPoolExecutor newExecutor(final int threads, final BlockingQueue<Runnable> blockingQueue) {
/**
- * This thread pool starts with 3 core threads and can grow to the limit
- * defined by 'threads'. If a pool thread is idle for more than 1 minute
- * it will be discarded, unless the core size is reached. It can accept
- * up to the number of processes defined by 'queue'. If the queue is
- * full then an attempt is made to add the process to the queue for 10
- * seconds. Failure to add to the queue in this time will either result
- * in a logged rejection, or if 'block' is true then a final attempt is
- * made to run the process in the current thread (the service thread).
+ This thread pool starts with 3 core threads and can grow to the limit defined by 'threads'.
+ If a pool thread is idle for more than 1 minute it will be discarded, unless the core size is reached.
+ It can accept up to the number of processes defined by 'queue'.
+ If the queue is full then an attempt is made to add the process to the queue for 10 seconds.
+ Failure to add to the queue in this time will either result in a logged rejection, or if 'block'
+ is true then a final attempt is made to run the process in the current thread (the service thread).
*/
- final ThreadPoolExecutor executorService = new ThreadPoolExecutor(3, (threads < 3 ? 3 : threads), 1,
- TimeUnit.MINUTES,
- blockingQueue == null
- ? new LinkedBlockingDeque<Runnable>(Integer.parseInt(getProperty(null, POOL_QUEUE_SIZE, "2")))
- : blockingQueue);
+ final ThreadPoolExecutor executorService = new ThreadPoolExecutor(3, (threads < 3 ? 3 : threads), 1, TimeUnit.MINUTES, blockingQueue == null ? new LinkedBlockingDeque<Runnable>(Integer.parseInt(getProperty(null, POOL_QUEUE_SIZE, "2"))) : blockingQueue);
executorService.setThreadFactory(new ThreadFactory() {
private final AtomicInteger i = new AtomicInteger(0);
@@ -167,8 +156,7 @@ public class JNDIContext implements InitialContextFactory, Context {
t.setUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(final Thread t, final Throwable e) {
- Logger.getLogger(EJBObjectHandler.class.getName()).log(Level.SEVERE,
- "Uncaught error in: " + t.getName(), e);
+ Logger.getLogger(EJBObjectHandler.class.getName()).log(Level.SEVERE, "Uncaught error in: " + t.getName(), e);
}
});
@@ -195,7 +183,7 @@ public class JNDIContext implements InitialContextFactory, Context {
try {
offer = tpe.getQueue().offer(r, 10, TimeUnit.SECONDS);
} catch (final InterruptedException e) {
- // Ignore
+ //Ignore
}
if (!offer) {
@@ -232,7 +220,6 @@ public class JNDIContext implements InitialContextFactory, Context {
return response;
}
-
protected AuthenticationResponse requestAuthorization(final AuthenticationRequest req) throws RemoteException {
return (AuthenticationResponse) Client.request(req, new AuthenticationResponse(), server);
}
@@ -245,11 +232,11 @@ public class JNDIContext implements InitialContextFactory, Context {
env = (Hashtable) environment.clone();
}
-
+ final String userID = (String) env.get(Context.SECURITY_PRINCIPAL);
+ final String psswrd = (String) env.get(Context.SECURITY_CREDENTIALS);
String providerUrl = (String) env.get(Context.PROVIDER_URL);
- final boolean authWithRequest = "true"
- .equalsIgnoreCase(String.class.cast(env.get(AUTHENTICATE_WITH_THE_REQUEST)));
+ final boolean authWithRequest = "true".equalsIgnoreCase(String.class.cast(env.get(AUTHENTICATE_WITH_THE_REQUEST)));
moduleId = (String) env.get("openejb.client.moduleId");
final URI location;
@@ -257,16 +244,14 @@ public class JNDIContext implements InitialContextFactory, Context {
providerUrl = addMissingParts(providerUrl);
location = new URI(providerUrl);
} catch (final URISyntaxException e) {
- throw (ConfigurationException) new ConfigurationException(
- "Property value for " + Context.PROVIDER_URL + " invalid: " + providerUrl + " - " + e.getMessage())
- .initCause(e);
+ throw (ConfigurationException) new ConfigurationException("Property value for " +
+ Context.PROVIDER_URL +
+ " invalid: " +
+ providerUrl +
+ " - " +
+ e.getMessage()).initCause(e);
}
this.server = new ServerMetaData(location);
- String securityPrincipal = (String) env.get(Context.SECURITY_PRINCIPAL);
- String securityCredentials = (String) env.get(Context.SECURITY_CREDENTIALS);
- if (securityPrincipal != null) {
- server = new ServerMetaData(server, securityPrincipal, securityCredentials);
- }
final Client.Context context = Client.getContext(this.server);
context.getProperties().putAll(environment);
@@ -276,14 +261,12 @@ public class JNDIContext implements InitialContextFactory, Context {
Client.fireEvent(new RemoteInitialContextCreated(location));
- // TODO: Either aggressively initiate authentication or wait for the
- // server to send us an authentication challenge.
- if (securityPrincipal != null) {
+ //TODO: Either aggressively initiate authentication or wait for the server to send us an authentication challenge.
+ if (userID != null) {
if (!authWithRequest) {
- authenticate(securityPrincipal, securityCredentials, false);
+ authenticate(userID, psswrd, false);
} else {
- authenticationInfo = new AuthenticationInfo(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)),
- securityPrincipal, securityCredentials.toCharArray(), getTimeout(env));
+ authenticationInfo = new AuthenticationInfo(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)), userID, psswrd.toCharArray(), getTimeout(env));
}
}
if (client == null) {
@@ -303,8 +286,7 @@ public class JNDIContext implements InitialContextFactory, Context {
final String serializer = (String) env.get(SERIALIZER);
if (serializer != null) {
try {
- client.setSerializer(EJBDSerializer.class
- .cast(Thread.currentThread().getContextClassLoader().loadClass(serializer).newInstance()));
+ client.setSerializer(EJBDSerializer.class.cast(Thread.currentThread().getContextClassLoader().loadClass(serializer).newInstance()));
} catch (final Exception e) {
// no-op
}
@@ -315,7 +297,7 @@ public class JNDIContext implements InitialContextFactory, Context {
final Object o = env.get(IDENTITY_TIMEOUT);
if (null != o) {
final Long l = Long.class.cast(o);
- // noinspection ConstantConditions
+ //noinspection ConstantConditions
if (null != l) {
return l;
}
@@ -335,11 +317,9 @@ public class JNDIContext implements InitialContextFactory, Context {
/**
* Add missing parts - expected only part of the required providerUrl
* <p/>
- * TODO: Move the check to a place where it really belongs -
- * ConnectionManager, ConnectionFactory or such This method (class in
- * general) doesn't really know what is required as far as connection
- * details go Assuming that java.net.URI or java.net.URL are going to be
- * used is overly stated
+ * TODO: Move the check to a place where it really belongs - ConnectionManager, ConnectionFactory or such
+ * This method (class in general) doesn't really know what is required as far as connection details go
+ * Assuming that java.net.URI or java.net.URL are going to be used is overly stated
*/
String addMissingParts(String providerUrl) throws URISyntaxException {
@@ -352,8 +332,7 @@ public class JNDIContext implements InitialContextFactory, Context {
final int colonIndex = providerUrl.indexOf(":");
final int slashesIndex = providerUrl.indexOf("//");
- if (colonIndex == -1 && slashesIndex == -1) { // hostname or ip
- // address only
+ if (colonIndex == -1 && slashesIndex == -1) { // hostname or ip address only
providerUrl = "ejbd://" + providerUrl + ":" + port;
} else if (colonIndex == -1) {
final URI providerUri = new URI(providerUrl);
@@ -368,11 +347,9 @@ public class JNDIContext implements InitialContextFactory, Context {
return providerUrl;
}
- public void authenticate(final String userID, final String psswrd, final boolean logout)
- throws AuthenticationException {
-//TODO needs http auth
- final AuthenticationRequest req = new AuthenticationRequest(
- String.class.cast(env.get(AUTHENTICATION_REALM_NAME)), userID, psswrd, getTimeout(env));
+ public void authenticate(final String userID, final String psswrd, final boolean logout) throws AuthenticationException {
+
+ final AuthenticationRequest req = new AuthenticationRequest(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)), userID, psswrd, getTimeout(env));
if (logout) {
req.setLogoutIdentity(null != client ? client.getClientIdentity() : null);
@@ -386,24 +363,22 @@ public class JNDIContext implements InitialContextFactory, Context {
}
switch (res.getResponseCode()) {
- case ResponseCodes.AUTH_GRANTED:
- client = logout ? new ClientMetaData() : res.getIdentity();
- break;
- case ResponseCodes.AUTH_REDIRECT:
- client = logout ? new ClientMetaData() : res.getIdentity();
- server = res.getServer();
- break;
- case ResponseCodes.AUTH_DENIED:
- throw (AuthenticationException) new AuthenticationException("This principle is not authorized.")
- .initCause(res.getDeniedCause());
+ case ResponseCodes.AUTH_GRANTED:
+ client = logout ? new ClientMetaData() : res.getIdentity();
+ break;
+ case ResponseCodes.AUTH_REDIRECT:
+ client = logout ? new ClientMetaData() : res.getIdentity();
+ server = res.getServer();
+ break;
+ case ResponseCodes.AUTH_DENIED:
+ throw (AuthenticationException) new AuthenticationException("This principle is not authorized.").initCause(res.getDeniedCause());
}
seedClientSerializer();
}
public EJBHomeProxy createEJBHomeProxy(final EJBMetaDataImpl ejbData) {
- final EJBHomeHandler handler = EJBHomeHandler.createEJBHomeHandler(executor(), ejbData, server, client,
- authenticationInfo);
+ final EJBHomeHandler handler = EJBHomeHandler.createEJBHomeHandler(executor(), ejbData, server, client, authenticationInfo);
final EJBHomeProxy proxy = handler.createEJBHomeProxy();
handler.ejb.ejbHomeProxy = proxy;
@@ -415,8 +390,7 @@ public class JNDIContext implements InitialContextFactory, Context {
final EJBMetaDataImpl ejb = (EJBMetaDataImpl) result;
final Object primaryKey = ejb.getPrimaryKey();
- final EJBObjectHandler handler = EJBObjectHandler.createEJBObjectHandler(executor(), ejb, server, client,
- primaryKey, authenticationInfo);
+ final EJBObjectHandler handler = EJBObjectHandler.createEJBObjectHandler(executor(), ejb, server, client, primaryKey, authenticationInfo);
return handler.createEJBObjectProxy();
}
@@ -456,74 +430,72 @@ public class JNDIContext implements InitialContextFactory, Context {
} catch (Exception e) {
if (e instanceof RemoteException && e.getCause() instanceof ConnectException) {
e = (Exception) e.getCause();
- throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot lookup '" + name + "'.")
- .initCause(e);
+ throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot lookup '" + name + "'.").initCause(e);
}
throw (NamingException) new NamingException("Cannot lookup '" + name + "'.").initCause(e);
}
switch (res.getResponseCode()) {
- case ResponseCodes.JNDI_EJBHOME:
- return createEJBHomeProxy((EJBMetaDataImpl) res.getResult());
+ case ResponseCodes.JNDI_EJBHOME:
+ return createEJBHomeProxy((EJBMetaDataImpl) res.getResult());
- case ResponseCodes.JNDI_BUSINESS_OBJECT:
- return createBusinessObject(res.getResult());
+ case ResponseCodes.JNDI_BUSINESS_OBJECT:
+ return createBusinessObject(res.getResult());
- case ResponseCodes.JNDI_OK:
- return res.getResult();
+ case ResponseCodes.JNDI_OK:
+ return res.getResult();
- case ResponseCodes.JNDI_INJECTIONS:
- return res.getResult();
+ case ResponseCodes.JNDI_INJECTIONS:
+ return res.getResult();
- case ResponseCodes.JNDI_CONTEXT:
- final JNDIContext subCtx = new JNDIContext(this);
- if (!name.endsWith("/")) {
- name += '/';
- }
- subCtx.tail = name;
- return subCtx;
+ case ResponseCodes.JNDI_CONTEXT:
+ final JNDIContext subCtx = new JNDIContext(this);
+ if (!name.endsWith("/")) {
+ name += '/';
+ }
+ subCtx.tail = name;
+ return subCtx;
- case ResponseCodes.JNDI_DATA_SOURCE:
- return createDataSource((DataSourceMetaData) res.getResult());
+ case ResponseCodes.JNDI_DATA_SOURCE:
+ return createDataSource((DataSourceMetaData) res.getResult());
- case ResponseCodes.JNDI_WEBSERVICE:
- return createWebservice((WsMetaData) res.getResult());
+ case ResponseCodes.JNDI_WEBSERVICE:
+ return createWebservice((WsMetaData) res.getResult());
- case ResponseCodes.JNDI_RESOURCE:
- final String type = (String) res.getResult();
- value = System.getProperty("Resource/" + type);
- if (value == null) {
- return null;
- }
- return parseEntry(prop, value);
+ case ResponseCodes.JNDI_RESOURCE:
+ final String type = (String) res.getResult();
+ value = System.getProperty("Resource/" + type);
+ if (value == null) {
+ return null;
+ }
+ return parseEntry(prop, value);
- case ResponseCodes.JNDI_REFERENCE:
- final Reference ref = (Reference) res.getResult();
- try {
- return NamingManager.getObjectInstance(ref, getNameParser(name).parse(name), this, env);
- } catch (final Exception e) {
- throw (NamingException) new NamingException("Could not dereference " + ref).initCause(e);
- }
+ case ResponseCodes.JNDI_REFERENCE:
+ final Reference ref = (Reference) res.getResult();
+ try {
+ return NamingManager.getObjectInstance(ref, getNameParser(name).parse(name), this, env);
+ } catch (final Exception e) {
+ throw (NamingException) new NamingException("Could not dereference " + ref).initCause(e);
+ }
- case ResponseCodes.JNDI_NOT_FOUND:
- throw new NameNotFoundException(
- name + " does not exist in the system. Check that the app was successfully deployed.");
+ case ResponseCodes.JNDI_NOT_FOUND:
+ throw new NameNotFoundException(name + " does not exist in the system. Check that the app was successfully deployed.");
- case ResponseCodes.JNDI_NAMING_EXCEPTION:
- final Throwable throwable = ((ThrowableArtifact) res.getResult()).getThrowable();
- if (throwable instanceof NamingException) {
- throw (NamingException) throwable;
- }
- throw (NamingException) new NamingException().initCause(throwable);
+ case ResponseCodes.JNDI_NAMING_EXCEPTION:
+ final Throwable throwable = ((ThrowableArtifact) res.getResult()).getThrowable();
+ if (throwable instanceof NamingException) {
+ throw (NamingException) throwable;
+ }
+ throw (NamingException) new NamingException().initCause(throwable);
- case ResponseCodes.JNDI_RUNTIME_EXCEPTION:
- throw (RuntimeException) res.getResult();
+ case ResponseCodes.JNDI_RUNTIME_EXCEPTION:
+ throw (RuntimeException) res.getResult();
- case ResponseCodes.JNDI_ERROR:
- throw (Error) res.getResult();
+ case ResponseCodes.JNDI_ERROR:
+ throw (Error) res.getResult();
- default:
- throw new ClientRuntimeException("Invalid response from server: " + res.getResponseCode());
+ default:
+ throw new ClientRuntimeException("Invalid response from server: " + res.getResponseCode());
}
}
@@ -556,8 +528,7 @@ public class JNDIContext implements InitialContextFactory, Context {
throw new UnsupportedOperationException("Unsupported Naming URI scheme '" + scheme + "'");
}
} catch (final URISyntaxException e) {
- throw (NamingException) new NamingException(
- "Unparsable jndi entry '" + name + "=" + value + "'. Exception: " + e.getMessage()).initCause(e);
+ throw (NamingException) new NamingException("Unparsable jndi entry '" + name + "=" + value + "'. Exception: " + e.getMessage()).initCause(e);
}
}
@@ -625,35 +596,34 @@ public class JNDIContext implements InitialContextFactory, Context {
} catch (Exception e) {
if (e instanceof RemoteException && e.getCause() instanceof ConnectException) {
e = (Exception) e.getCause();
- throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot list '" + name + "'.")
- .initCause(e);
+ throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot list '" + name + "'.").initCause(e);
}
throw (NamingException) new NamingException("Cannot list '" + name + "'.").initCause(e);
}
switch (res.getResponseCode()) {
- case ResponseCodes.JNDI_OK:
- return null;
+ case ResponseCodes.JNDI_OK:
+ return null;
- case ResponseCodes.JNDI_ENUMERATION:
- return (NamingEnumeration) res.getResult();
+ case ResponseCodes.JNDI_ENUMERATION:
+ return (NamingEnumeration) res.getResult();
- case ResponseCodes.JNDI_NOT_FOUND:
- throw new NameNotFoundException(name);
+ case ResponseCodes.JNDI_NOT_FOUND:
+ throw new NameNotFoundException(name);
- case ResponseCodes.JNDI_NAMING_EXCEPTION:
- final Throwable throwable = ((ThrowableArtifact) res.getResult()).getThrowable();
- if (throwable instanceof NamingException) {
- throw (NamingException) throwable;
- }
- throw (NamingException) new NamingException().initCause(throwable);
+ case ResponseCodes.JNDI_NAMING_EXCEPTION:
+ final Throwable throwable = ((ThrowableArtifact) res.getResult()).getThrowable();
+ if (throwable instanceof NamingException) {
+ throw (NamingException) throwable;
+ }
+ throw (NamingException) new NamingException().initCause(throwable);
- case ResponseCodes.JNDI_ERROR:
- throw (Error) res.getResult();
+ case ResponseCodes.JNDI_ERROR:
+ throw (Error) res.getResult();
- default:
- throw new ClientRuntimeException("Invalid response from server :" + res.getResponseCode());
+ default:
+ throw new ClientRuntimeException("Invalid response from server :" + res.getResponseCode());
}
}
@@ -705,8 +675,7 @@ public class JNDIContext implements InitialContextFactory, Context {
try {
super.setObject(context.lookup(getName()));
} catch (final NamingException e) {
- throw failed = new ClientRuntimeException("Failed to lazily fetch the binding '" + getName() + "'",
- e);
+ throw failed = new ClientRuntimeException("Failed to lazily fetch the binding '" + getName() + "'", e);
}
}
return super.getObject();
@@ -792,7 +761,7 @@ public class JNDIContext implements InitialContextFactory, Context {
try {
this.authenticate(userID, psswrd, logout);
} catch (final Exception ignore) {
- // no-op
+ //no-op
}
}
}
@@ -935,3 +904,4 @@ public class JNDIContext implements InitialContextFactory, Context {
}
}
}
+
http://git-wip-us.apache.org/repos/asf/tomee/blob/3fa5d916/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
index 60c9c92..bb9e36d 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
@@ -21,62 +21,23 @@ import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.net.URI;
-import java.net.URISyntaxException;
-import java.util.ArrayList;
import java.util.Arrays;
-import java.util.List;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
public class ServerMetaData implements Externalizable {
private static final long serialVersionUID = -915541900332460068L;
- private static final transient Pattern urlPattern = Pattern.compile("http(?s):\\/\\/(.+):(.+)@.*");
private transient URI[] locations;
private transient URI location;
private transient ProtocolMetaData metaData;
+ public ServerMetaData() {
+ }
+
public ServerMetaData(final URI... locations) {
this.locations = locations;
location = locations[0];
}
- public ServerMetaData(ServerMetaData server, String securityPrincipal, String securityCredentials) {
- List<URI> locationList = new ArrayList<URI>(server.locations.length);
- for (URI uri : server.locations) {
- uri = addUserToURI(securityPrincipal, securityPrincipal, uri);
- locationList.add(uri);
- }
- locations = locationList.toArray(new URI[server.locations.length]);
- location = addUserToURI(securityPrincipal, securityPrincipal, server.location);
- this.metaData = server.metaData;
- }
-
- private URI addUserToURI(String securityPrincipal, String securityCredentials, URI uri) {
- String uriString = uri.toString();
- Matcher matcher = urlPattern.matcher(uriString);
- if (!matcher.matches()) {
- String restOfUrl = null;
- String scheme = null;
- if (uriString.startsWith("http://")) {
- restOfUrl = uriString.substring("http://".length());
- scheme = "http://";
- } else if (uriString.startsWith("https://")) {
- restOfUrl = uriString.substring("https://".length());
- scheme = "https://";
- }
- if (restOfUrl != null) {
- try {
- uri = new URI(scheme + securityPrincipal + ":" + (securityCredentials == null ? "" : securityCredentials) + "@"
- + restOfUrl);
- } catch (URISyntaxException e) {
- throw new RuntimeException(e);
- }
- }
- }
- return uri;
- }
-
public void setMetaData(final ProtocolMetaData metaData) {
this.metaData = metaData;
}
@@ -139,3 +100,4 @@ public class ServerMetaData implements Externalizable {
return (location != null ? location.hashCode() : 0);
}
}
+
http://git-wip-us.apache.org/repos/asf/tomee/blob/3fa5d916/server/openejb-client/src/test/java/org/apache/openejb/client/ServerMetaDataTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/test/java/org/apache/openejb/client/ServerMetaDataTest.java b/server/openejb-client/src/test/java/org/apache/openejb/client/ServerMetaDataTest.java
index b578695..365deff 100644
--- a/server/openejb-client/src/test/java/org/apache/openejb/client/ServerMetaDataTest.java
+++ b/server/openejb-client/src/test/java/org/apache/openejb/client/ServerMetaDataTest.java
@@ -29,4 +29,5 @@ public class ServerMetaDataTest extends TestCase {
final ServerMetaData server2 = new ServerMetaData(uri2, uri1);
assertEquals(server1.buildHash(), server2.buildHash());
}
+
}
[04/14] tomee git commit: recommit files for cleaner diff
Posted by jg...@apache.org.
recommit files for cleaner diff
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/61b355a6
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/61b355a6
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/61b355a6
Branch: refs/heads/tomee-1.7.x
Commit: 61b355a67ba2f3ea89c41d3fd476d77a5ec99191
Parents: 3fa5d91
Author: Jonathan S. Fisher <jf...@tomitribe.com>
Authored: Fri Nov 4 15:46:42 2016 -0500
Committer: Jonathan S. Fisher <jf...@tomitribe.com>
Committed: Fri Nov 4 15:46:42 2016 -0500
----------------------------------------------------------------------
.../openejb/client/HttpConnectionFactory.java | 27 ++++++++----
.../org/apache/openejb/client/JNDIContext.java | 42 ++++++++----------
.../apache/openejb/client/ServerMetaData.java | 46 ++++++++++++++++++--
3 files changed, 77 insertions(+), 38 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/61b355a6/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
index 78b1928..9cb86bd 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
@@ -15,9 +15,7 @@
* limitations under the License.
*/
package org.apache.openejb.client;
-
-import javax.net.ssl.HttpsURLConnection;
-import javax.net.ssl.SSLSocketFactory;
+import static javax.xml.bind.DatatypeConverter.printBase64Binary;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -25,6 +23,7 @@ import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
@@ -33,6 +32,9 @@ import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
+import javax.net.ssl.HttpsURLConnection;
+import javax.net.ssl.SSLSocketFactory;
+
/**
* @version $Revision$ $Date$
*/
@@ -49,7 +51,7 @@ public class HttpConnectionFactory implements ConnectionFactory {
}
try {
return new HttpConnection(uri, socketFactoryMap, buffer);
- } finally { // auto adjusting buffer caching, queue avoids leaks (!= ThreadLocal)
+ } finally { // auto adjusting buffer caching, queue avoids leaks (!=ThreadLocal)
drainBuffers.add(buffer);
}
}
@@ -61,14 +63,15 @@ public class HttpConnectionFactory implements ConnectionFactory {
private OutputStream outputStream;
private final URI uri;
- public HttpConnection(final URI uri, final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap,
- final byte[] buffer) throws IOException {
+ public HttpConnection(final URI uri, final ConcurrentMap<URI, SSLSocketFactory> socketFactoryMap, final byte[] buffer)
+ throws IOException {
this.uri = uri;
this.buffer = buffer;
final URL url = uri.toURL();
final Map<String, String> params;
try {
+ // TODO username:password
params = MulticastConnectionFactory.URIs.parseParamters(uri);
} catch (final URISyntaxException e) {
throw new IllegalArgumentException("Invalid uri " + uri.toString(), e);
@@ -90,6 +93,12 @@ public class HttpConnectionFactory implements ConnectionFactory {
httpURLConnection.setReadTimeout(Integer.parseInt(params.get("readTimeout")));
}
+ if (uri.getUserInfo() != null) {
+ String authorization = "Basic "
+ + printBase64Binary((url.getUserInfo()).getBytes(StandardCharsets.UTF_8));
+ httpURLConnection.setRequestProperty("Authorization", authorization);
+ }
+
if (params.containsKey("sslKeyStore") || params.containsKey("sslTrustStore")) {
try {
SSLSocketFactory sslSocketFactory = socketFactoryMap.get(uri);
@@ -118,7 +127,7 @@ public class HttpConnectionFactory implements ConnectionFactory {
try {
close();
} catch (final Exception e) {
- //Ignore
+ // Ignore
}
}
@@ -132,7 +141,8 @@ public class HttpConnectionFactory implements ConnectionFactory {
IOException exception = null;
if (inputStream != null) {
// consume anything left in the buffer
- try {// use a buffer cause it is faster, check HttpInputStreamImpl
+ try {// use a buffer cause it is faster, check
+ // HttpInputStreamImpl
while (inputStream.read(buffer) > -1) {
// no-op
}
@@ -180,5 +190,4 @@ public class HttpConnectionFactory implements ConnectionFactory {
return inputStream;
}
}
-
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/61b355a6/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 852ebae..afc5ed9 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
@@ -224,7 +224,6 @@ public class JNDIContext implements InitialContextFactory, Context {
return (AuthenticationResponse) Client.request(req, new AuthenticationResponse(), server);
}
- @Override
public Context getInitialContext(final Hashtable environment) throws NamingException {
if (environment == null) {
throw new NamingException("Invalid argument, hashtable cannot be null.");
@@ -232,11 +231,11 @@ public class JNDIContext implements InitialContextFactory, Context {
env = (Hashtable) environment.clone();
}
- final String userID = (String) env.get(Context.SECURITY_PRINCIPAL);
- final String psswrd = (String) env.get(Context.SECURITY_CREDENTIALS);
+
String providerUrl = (String) env.get(Context.PROVIDER_URL);
- final boolean authWithRequest = "true".equalsIgnoreCase(String.class.cast(env.get(AUTHENTICATE_WITH_THE_REQUEST)));
+ final boolean authWithRequest = "true"
+ .equalsIgnoreCase(String.class.cast(env.get(AUTHENTICATE_WITH_THE_REQUEST)));
moduleId = (String) env.get("openejb.client.moduleId");
final URI location;
@@ -244,14 +243,16 @@ public class JNDIContext implements InitialContextFactory, Context {
providerUrl = addMissingParts(providerUrl);
location = new URI(providerUrl);
} catch (final URISyntaxException e) {
- throw (ConfigurationException) new ConfigurationException("Property value for " +
- Context.PROVIDER_URL +
- " invalid: " +
- providerUrl +
- " - " +
- e.getMessage()).initCause(e);
+ throw (ConfigurationException) new ConfigurationException(
+ "Property value for " + Context.PROVIDER_URL + " invalid: " + providerUrl + " - " + e.getMessage())
+ .initCause(e);
}
this.server = new ServerMetaData(location);
+ String securityPrincipal = (String) env.get(Context.SECURITY_PRINCIPAL);
+ String securityCredentials = (String) env.get(Context.SECURITY_CREDENTIALS);
+ if (securityPrincipal != null) {
+ server = new ServerMetaData(server, securityPrincipal, securityCredentials);
+ }
final Client.Context context = Client.getContext(this.server);
context.getProperties().putAll(environment);
@@ -261,12 +262,14 @@ public class JNDIContext implements InitialContextFactory, Context {
Client.fireEvent(new RemoteInitialContextCreated(location));
- //TODO: Either aggressively initiate authentication or wait for the server to send us an authentication challenge.
- if (userID != null) {
+ // TODO: Either aggressively initiate authentication or wait for the
+ // server to send us an authentication challenge.
+ if (securityPrincipal != null) {
if (!authWithRequest) {
- authenticate(userID, psswrd, false);
+ authenticate(securityPrincipal, securityCredentials, false);
} else {
- authenticationInfo = new AuthenticationInfo(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)), userID, psswrd.toCharArray(), getTimeout(env));
+ authenticationInfo = new AuthenticationInfo(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)),
+ securityPrincipal, securityCredentials.toCharArray(), getTimeout(env));
}
}
if (client == null) {
@@ -282,17 +285,6 @@ public class JNDIContext implements InitialContextFactory, Context {
return this;
}
- private void seedClientSerializer() {
- final String serializer = (String) env.get(SERIALIZER);
- if (serializer != null) {
- try {
- client.setSerializer(EJBDSerializer.class.cast(Thread.currentThread().getContextClassLoader().loadClass(serializer).newInstance()));
- } catch (final Exception e) {
- // no-op
- }
- }
- }
-
private long getTimeout(final Hashtable env) {
final Object o = env.get(IDENTITY_TIMEOUT);
if (null != o) {
http://git-wip-us.apache.org/repos/asf/tomee/blob/61b355a6/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
index bb9e36d..60c9c92 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
@@ -21,23 +21,62 @@ import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class ServerMetaData implements Externalizable {
private static final long serialVersionUID = -915541900332460068L;
+ private static final transient Pattern urlPattern = Pattern.compile("http(?s):\\/\\/(.+):(.+)@.*");
private transient URI[] locations;
private transient URI location;
private transient ProtocolMetaData metaData;
- public ServerMetaData() {
- }
-
public ServerMetaData(final URI... locations) {
this.locations = locations;
location = locations[0];
}
+ public ServerMetaData(ServerMetaData server, String securityPrincipal, String securityCredentials) {
+ List<URI> locationList = new ArrayList<URI>(server.locations.length);
+ for (URI uri : server.locations) {
+ uri = addUserToURI(securityPrincipal, securityPrincipal, uri);
+ locationList.add(uri);
+ }
+ locations = locationList.toArray(new URI[server.locations.length]);
+ location = addUserToURI(securityPrincipal, securityPrincipal, server.location);
+ this.metaData = server.metaData;
+ }
+
+ private URI addUserToURI(String securityPrincipal, String securityCredentials, URI uri) {
+ String uriString = uri.toString();
+ Matcher matcher = urlPattern.matcher(uriString);
+ if (!matcher.matches()) {
+ String restOfUrl = null;
+ String scheme = null;
+ if (uriString.startsWith("http://")) {
+ restOfUrl = uriString.substring("http://".length());
+ scheme = "http://";
+ } else if (uriString.startsWith("https://")) {
+ restOfUrl = uriString.substring("https://".length());
+ scheme = "https://";
+ }
+ if (restOfUrl != null) {
+ try {
+ uri = new URI(scheme + securityPrincipal + ":" + (securityCredentials == null ? "" : securityCredentials) + "@"
+ + restOfUrl);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ return uri;
+ }
+
public void setMetaData(final ProtocolMetaData metaData) {
this.metaData = metaData;
}
@@ -100,4 +139,3 @@ public class ServerMetaData implements Externalizable {
return (location != null ? location.hashCode() : 0);
}
}
-
[14/14] tomee git commit: Added more tests to check EJB Remote http
Basic Authentication.
Posted by jg...@apache.org.
Added more tests to check EJB Remote http Basic Authentication.
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/e0397f49
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/e0397f49
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/e0397f49
Branch: refs/heads/tomee-1.7.x
Commit: e0397f495e711f5f95dbb8dba5986fbeb7feea5a
Parents: 2663c6f
Author: Roberto Cortez <ra...@yahoo.com>
Authored: Thu Nov 17 01:43:35 2016 +0000
Committer: Roberto Cortez <ra...@yahoo.com>
Committed: Thu Nov 17 01:43:35 2016 +0000
----------------------------------------------------------------------
.../arquillian/tests/security/BusinessBean.java | 9 ++-
.../tests/security/BusinessRemote.java | 2 +
.../TomEEEjbServletAuthorizationHeaderTest.java | 66 ++++++++++++++++++--
.../src/test/resources/arquillian.xml | 4 +-
4 files changed, 73 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/e0397f49/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java
index 5a101bf..41d4ee4 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java
@@ -17,6 +17,7 @@
package org.apache.openejb.arquillian.tests.security;
import javax.annotation.Resource;
+import javax.annotation.security.RolesAllowed;
import javax.ejb.Lock;
import javax.ejb.LockType;
import javax.ejb.SessionContext;
@@ -31,15 +32,21 @@ public class BusinessBean implements BusinessRemote {
private SessionContext ctx;
@Override
+ @RolesAllowed("tomee-admin")
public String echo(final String input) {
return input;
}
@Override
+ @RolesAllowed("forbidden")
+ public void forbidden() {
+ }
+
+ @Override
public String getPrincipal() {
Principal callerPrincipal = ctx.getCallerPrincipal();
if (callerPrincipal == null) {
- return "null";
+ return "guest";
}
return callerPrincipal.getName();
http://git-wip-us.apache.org/repos/asf/tomee/blob/e0397f49/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java
index e81f634..ab57961 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java
@@ -23,5 +23,7 @@ public interface BusinessRemote {
String echo(String input);
+ void forbidden();
+
String getPrincipal();
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/e0397f49/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
index 9e6a141..78371a9 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
@@ -26,22 +26,24 @@ import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor;
-import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
+import javax.ejb.EJBAccessException;
import javax.naming.AuthenticationException;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.net.URL;
import java.util.Properties;
+import static org.junit.Assert.assertEquals;
+
@RunWith(Arquillian.class)
@RunAsClient
public class TomEEEjbServletAuthorizationHeaderTest extends TestSetup {
-
- public static final String TEST_NAME = TomEEEjbServletAuthorizationHeaderTest.class.getSimpleName();
+ private static final String REMOTE_NAME = "global/TomEEEjbServletAuthorizationHeaderTest/BusinessBean!" +
+ "org.apache.openejb.arquillian.tests.security.BusinessRemote";
@ArquillianResource
private URL url;
@@ -57,8 +59,9 @@ public class TomEEEjbServletAuthorizationHeaderTest extends TestSetup {
p.setProperty("tomee.ejb.authentication.basic.password", "password");
final InitialContext context = new InitialContext(p);
- final BusinessRemote bean = (BusinessRemote) context.lookup("global/TomEEEjbServletAuthorizationHeaderTest/BusinessBean!org.apache.openejb.arquillian.tests.security.BusinessRemote");
- Assert.assertEquals("test", bean.echo("test"));
+ final BusinessRemote bean = (BusinessRemote) context.lookup(REMOTE_NAME);
+ assertEquals("test", bean.echo("test"));
+ assertEquals("tomee", bean.getPrincipal());
}
@Test(expected = AuthenticationException.class)
@@ -72,7 +75,58 @@ public class TomEEEjbServletAuthorizationHeaderTest extends TestSetup {
p.setProperty("tomee.ejb.authentication.basic.password", "wrong");
final InitialContext context = new InitialContext(p);
- context.lookup("global/TomEEEjbServletAuthorizationHeaderTest/BusinessBean!org.apache.openejb.arquillian.tests.security.BusinessRemote");
+ context.lookup(REMOTE_NAME);
+ }
+
+ @Test
+ public void testAuthenticateWithPrincipal() throws Exception {
+ final String ejbUrl = this.url.toExternalForm() + "ejb";
+
+ final Properties p = new Properties();
+ p.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+ p.setProperty(Context.PROVIDER_URL, ejbUrl);
+ p.setProperty("tomee.ejb.authentication.basic.login", "tomee");
+ p.setProperty("tomee.ejb.authentication.basic.password", "password");
+ p.setProperty(Context.SECURITY_PRINCIPAL, "admin");
+ p.setProperty(Context.SECURITY_CREDENTIALS, "admin");
+ final InitialContext context = new InitialContext(p);
+
+ final BusinessRemote bean = (BusinessRemote) context.lookup(REMOTE_NAME);
+ assertEquals("test", bean.echo("test"));
+ assertEquals("admin", bean.getPrincipal());
+ }
+
+ @Test(expected = AuthenticationException.class)
+ public void testFailedPrincipalAuthentication() throws Exception {
+ final String ejbUrl = this.url.toExternalForm() + "ejb";
+
+ final Properties p = new Properties();
+ p.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+ p.setProperty(Context.PROVIDER_URL, ejbUrl);
+ p.setProperty("tomee.ejb.authentication.basic.login", "tomee");
+ p.setProperty("tomee.ejb.authentication.basic.password", "password");
+ p.setProperty(Context.SECURITY_PRINCIPAL, "admin");
+ p.setProperty(Context.SECURITY_CREDENTIALS, "wrong");
+ final InitialContext context = new InitialContext(p);
+
+ context.lookup(REMOTE_NAME);
+ }
+
+ @Test(expected = EJBAccessException.class)
+ public void testAuthenticateWithPrincipalForbiddenCall() throws Exception {
+ final String ejbUrl = this.url.toExternalForm() + "ejb";
+
+ final Properties p = new Properties();
+ p.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+ p.setProperty(Context.PROVIDER_URL, ejbUrl);
+ p.setProperty("tomee.ejb.authentication.basic.login", "tomee");
+ p.setProperty("tomee.ejb.authentication.basic.password", "password");
+ p.setProperty(Context.SECURITY_PRINCIPAL, "admin");
+ p.setProperty(Context.SECURITY_CREDENTIALS, "admin");
+ final InitialContext context = new InitialContext(p);
+
+ final BusinessRemote bean = (BusinessRemote) context.lookup(REMOTE_NAME);
+ bean.forbidden();
}
@Deployment(testable = false)
http://git-wip-us.apache.org/repos/asf/tomee/blob/e0397f49/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
index 70bb894..c5f5733 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
@@ -35,9 +35,11 @@
</property>
<property name="users">
tomee=password
+ admin=admin
</property>
<property name="roles">
tomee=tomee-admin
+ admin=tomee-admin
</property>
</configuration>
</container>
@@ -76,4 +78,4 @@
</property>
</configuration>
</container>
-</arquillian>
\ No newline at end of file
+</arquillian>
[10/14] tomee git commit: A trial for how this might work
Posted by jg...@apache.org.
A trial for how this might work
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/e260aee1
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/e260aee1
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/e260aee1
Branch: refs/heads/tomee-1.7.x
Commit: e260aee125706eb383de789ff07f0f093a7b72bb
Parents: eddd711
Author: Jonathan Gallimore <jg...@Jons-MacBook-Pro.local>
Authored: Mon Nov 7 10:36:51 2016 +0000
Committer: Jonathan Gallimore <jg...@Jons-MacBook-Pro.local>
Committed: Mon Nov 7 10:36:51 2016 +0000
----------------------------------------------------------------------
.../apache/openejb/server/ejbd/EjbRequestHandler.java | 14 ++++++++++++++
1 file changed, 14 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/e260aee1/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java
----------------------------------------------------------------------
diff --git a/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java b/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java
index 1fda2cb..71896c0 100644
--- a/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java
+++ b/server/openejb-ejbd/src/main/java/org/apache/openejb/server/ejbd/EjbRequestHandler.java
@@ -103,11 +103,17 @@ class EjbRequestHandler extends RequestHandler {
final SecurityService securityService = SystemInstance.get().getComponent(SecurityService.class);
boolean failed = false;
final CallContext call;
+ Object oldClientIdentity = null;
+
try {
try {
final Object clientIdentity = req.getClientIdentity();
if (clientIdentity != null) {//noinspection unchecked
+ if (securityService.getCallerPrincipal() != null) {
+ oldClientIdentity = securityService.disassociate();
+ }
+
securityService.associate(clientIdentity);
}
} catch (final LoginException t) {
@@ -158,6 +164,10 @@ class EjbRequestHandler extends RequestHandler {
} finally {
if (failed) {
securityService.disassociate();
+
+ if (oldClientIdentity != null) {
+ securityService.associate(oldClientIdentity);
+ }
}
}
@@ -268,6 +278,10 @@ class EjbRequestHandler extends RequestHandler {
try {
//noinspection unchecked
securityService.logout(securityToken);
+
+ if (oldClientIdentity != null) {
+ securityService.associate(oldClientIdentity);
+ }
} catch (final LoginException e) {
// no-op
}
[13/14] tomee git commit: Added properties to check Authentication
Basic credentials.
Posted by jg...@apache.org.
Added properties to check Authentication Basic credentials.
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/2663c6f5
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/2663c6f5
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/2663c6f5
Branch: refs/heads/tomee-1.7.x
Commit: 2663c6f510cac3a3e8baeed95051a3f022c8fdf0
Parents: 03e6963
Author: Roberto Cortez <ra...@yahoo.com>
Authored: Thu Nov 17 01:03:49 2016 +0000
Committer: Roberto Cortez <ra...@yahoo.com>
Committed: Thu Nov 17 01:03:49 2016 +0000
----------------------------------------------------------------------
.../TomEEEjbServletAuthorizationHeaderTest.java | 19 +++++++++++++++++--
.../java/org/apache/openejb/client/Client.java | 7 +++++++
.../openejb/client/HttpConnectionFactory.java | 4 ++++
.../org/apache/openejb/client/JNDIContext.java | 18 ++++++++++++++++++
4 files changed, 46 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/2663c6f5/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
index 0b1534c..9e6a141 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
@@ -30,6 +30,7 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
+import javax.naming.AuthenticationException;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.net.URL;
@@ -52,14 +53,28 @@ public class TomEEEjbServletAuthorizationHeaderTest extends TestSetup {
final Properties p = new Properties();
p.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
p.setProperty(Context.PROVIDER_URL, ejbUrl);
- p.setProperty(Context.SECURITY_PRINCIPAL, "tomee");
- p.setProperty(Context.SECURITY_CREDENTIALS, "password");
+ p.setProperty("tomee.ejb.authentication.basic.login", "tomee");
+ p.setProperty("tomee.ejb.authentication.basic.password", "password");
final InitialContext context = new InitialContext(p);
final BusinessRemote bean = (BusinessRemote) context.lookup("global/TomEEEjbServletAuthorizationHeaderTest/BusinessBean!org.apache.openejb.arquillian.tests.security.BusinessRemote");
Assert.assertEquals("test", bean.echo("test"));
}
+ @Test(expected = AuthenticationException.class)
+ public void testFailedAuthentication() throws Exception {
+ final String ejbUrl = this.url.toExternalForm() + "ejb";
+
+ final Properties p = new Properties();
+ p.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+ p.setProperty(Context.PROVIDER_URL, ejbUrl);
+ p.setProperty("tomee.ejb.authentication.basic.login", "tomee");
+ p.setProperty("tomee.ejb.authentication.basic.password", "wrong");
+ final InitialContext context = new InitialContext(p);
+
+ context.lookup("global/TomEEEjbServletAuthorizationHeaderTest/BusinessBean!org.apache.openejb.arquillian.tests.security.BusinessRemote");
+ }
+
@Deployment(testable = false)
public static WebArchive getArchive() {
return new TomEEEjbServletAuthorizationHeaderTest().createDeployment(TestRun.class, BusinessBean.class);
http://git-wip-us.apache.org/repos/asf/tomee/blob/2663c6f5/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java b/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
index 4cc352a..f3f2533 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
@@ -26,6 +26,7 @@ import org.apache.openejb.client.event.RetryingRequest;
import org.apache.openejb.client.event.ServerAdded;
import org.apache.openejb.client.event.ServerRemoved;
+import javax.naming.AuthenticationException;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
@@ -260,6 +261,12 @@ public class Client {
/*----------------------------------*/
try {
+ if (conn instanceof HttpConnectionFactory.HttpConnection) {
+ final HttpConnectionFactory.HttpConnection httpConn = (HttpConnectionFactory.HttpConnection) conn;
+ if (httpConn.getResponseCode() == 401) {
+ throw new AuthenticationException();
+ }
+ }
in = conn.getInputStream();
http://git-wip-us.apache.org/repos/asf/tomee/blob/2663c6f5/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
index 240dc23..a019fbc 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
@@ -187,5 +187,9 @@ public class HttpConnectionFactory implements ConnectionFactory {
}
return inputStream;
}
+
+ public int getResponseCode() throws IOException {
+ return httpURLConnection.getResponseCode();
+ }
}
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/2663c6f5/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 852ebae..3306619 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
@@ -76,6 +76,8 @@ public class JNDIContext implements InitialContextFactory, Context {
public static final String POOL_THREAD_NUMBER = "openejb.client.invoker.threads";
public static final String AUTHENTICATION_REALM_NAME = "openejb.authentication.realmName";
public static final String IDENTITY_TIMEOUT = "tomee.authentication.identity.timeout";
+ public static final String BASIC_AUTH_LOGIN = "tomee.ejb.authentication.basic.login";
+ public static final String BASIC_AUTH_PASSWORD = "tomee.ejb.authentication.basic.password";
private final AtomicBoolean isShutdown = new AtomicBoolean(false);
private String tail = "/";
@@ -253,6 +255,12 @@ public class JNDIContext implements InitialContextFactory, Context {
}
this.server = new ServerMetaData(location);
+ final String basicAuthLogin = (String) env.get(BASIC_AUTH_LOGIN);
+ final String basicAuthPassword = (String) env.get(BASIC_AUTH_PASSWORD);
+ if (basicAuthLogin != null) {
+ this.server = new ServerMetaData(server, basicAuthLogin, basicAuthPassword);
+ }
+
final Client.Context context = Client.getContext(this.server);
context.getProperties().putAll(environment);
@@ -432,6 +440,16 @@ public class JNDIContext implements InitialContextFactory, Context {
e = (Exception) e.getCause();
throw (ServiceUnavailableException) new ServiceUnavailableException("Cannot lookup '" + name + "'.").initCause(e);
}
+
+ if (e instanceof RemoteException && e.getCause() instanceof AuthenticationException) {
+ throw (AuthenticationException) new AuthenticationException(
+ "Cannot Basic Auth into server. Please use " +
+ BASIC_AUTH_LOGIN +
+ " and " +
+ BASIC_AUTH_PASSWORD +
+ " to set up credentials.").initCause(e);
+ }
+
throw (NamingException) new NamingException("Cannot lookup '" + name + "'.").initCause(e);
}
[12/14] tomee git commit: Cleanup and reverted changes for
Authentication Header implementation with the least amount of code changes.
Posted by jg...@apache.org.
Cleanup and reverted changes for Authentication Header implementation with the least amount of code changes.
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/03e69634
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/03e69634
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/03e69634
Branch: refs/heads/tomee-1.7.x
Commit: 03e69634614db9c72a13dcab174864794f12c0d5
Parents: 62e0e31
Author: Roberto Cortez <ra...@yahoo.com>
Authored: Thu Nov 17 00:20:51 2016 +0000
Committer: Roberto Cortez <ra...@yahoo.com>
Committed: Thu Nov 17 00:20:51 2016 +0000
----------------------------------------------------------------------
.../org/apache/openejb/client/JNDIContext.java | 27 +++++++++-----------
.../catalina/remote/TomEERemoteWebapp.java | 4 ---
2 files changed, 12 insertions(+), 19 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/03e69634/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 120be87..852ebae 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
@@ -232,7 +232,8 @@ public class JNDIContext implements InitialContextFactory, Context {
env = (Hashtable) environment.clone();
}
-
+ final String userID = (String) env.get(Context.SECURITY_PRINCIPAL);
+ final String psswrd = (String) env.get(Context.SECURITY_CREDENTIALS);
String providerUrl = (String) env.get(Context.PROVIDER_URL);
final boolean authWithRequest = "true".equalsIgnoreCase(String.class.cast(env.get(AUTHENTICATE_WITH_THE_REQUEST)));
@@ -243,16 +244,14 @@ public class JNDIContext implements InitialContextFactory, Context {
providerUrl = addMissingParts(providerUrl);
location = new URI(providerUrl);
} catch (final URISyntaxException e) {
- throw (ConfigurationException) new ConfigurationException(
- "Property value for " + Context.PROVIDER_URL + " invalid: " + providerUrl + " - " + e.getMessage())
- .initCause(e);
+ throw (ConfigurationException) new ConfigurationException("Property value for " +
+ Context.PROVIDER_URL +
+ " invalid: " +
+ providerUrl +
+ " - " +
+ e.getMessage()).initCause(e);
}
this.server = new ServerMetaData(location);
- String securityPrincipal = (String) env.get(Context.SECURITY_PRINCIPAL);
- String securityCredentials = (String) env.get(Context.SECURITY_CREDENTIALS);
- if (securityPrincipal != null) {
- server = new ServerMetaData(server, securityPrincipal, securityCredentials);
- }
final Client.Context context = Client.getContext(this.server);
context.getProperties().putAll(environment);
@@ -262,14 +261,12 @@ public class JNDIContext implements InitialContextFactory, Context {
Client.fireEvent(new RemoteInitialContextCreated(location));
- // TODO: Either aggressively initiate authentication or wait for the
- // server to send us an authentication challenge.
- if (securityPrincipal != null) {
+ //TODO: Either aggressively initiate authentication or wait for the server to send us an authentication challenge.
+ if (userID != null) {
if (!authWithRequest) {
- authenticate(securityPrincipal, securityCredentials, false);
+ authenticate(userID, psswrd, false);
} else {
- authenticationInfo = new AuthenticationInfo(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)), securityPrincipal,
- securityCredentials.toCharArray(), getTimeout(env));
+ authenticationInfo = new AuthenticationInfo(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)), userID, psswrd.toCharArray(), getTimeout(env));
}
}
if (client == null) {
http://git-wip-us.apache.org/repos/asf/tomee/blob/03e69634/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
index bf7baeb..4a2bde9 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
@@ -25,16 +25,12 @@ import org.apache.openejb.loader.SystemInstance;
import org.apache.openejb.server.httpd.ServerServlet;
import org.apache.tomee.catalina.IgnoredStandardContext;
import org.apache.tomee.catalina.OpenEJBValve;
-import org.apache.catalina.deploy.LoginConfig;
-import org.apache.catalina.deploy.SecurityCollection;
-import org.apache.catalina.deploy.SecurityConstraint;
import java.beans.PropertyChangeListener;
public class TomEERemoteWebapp extends IgnoredStandardContext {
private static final String CONTEXT_NAME = SystemInstance.get().getProperty("tomee.remote.support.context", "/tomee");
private static final String MAPPING = SystemInstance.get().getProperty("tomee.remote.support.mapping", "/ejb");
-
public TomEERemoteWebapp() {
setDocBase("");
[11/14] tomee git commit: Merge pull request #1 from
jgallimore/auth-fixes
Posted by jg...@apache.org.
Merge pull request #1 from jgallimore/auth-fixes
Add test for authorization header usage. Fix bug where username being\u2026
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/62e0e314
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/62e0e314
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/62e0e314
Branch: refs/heads/tomee-1.7.x
Commit: 62e0e314235b9545767c884211e5b014e0132228
Parents: 7b41ae5 e260aee
Author: Jonathan S. Fisher <ex...@gmail.com>
Authored: Mon Nov 7 08:23:59 2016 -0600
Committer: GitHub <no...@github.com>
Committed: Mon Nov 7 08:23:59 2016 -0600
----------------------------------------------------------------------
.../arquillian/tests/security/BusinessBean.java | 48 +++++++++++
.../tests/security/BusinessRemote.java | 27 ++++++
.../TomEEEjbServletAuthorizationHeaderTest.java | 91 ++++++++++++++++++++
.../src/test/resources/arquillian.xml | 6 ++
.../src/test/tomee/conf/tomcat-users.xml | 30 +++++++
.../apache/openejb/client/ServerMetaData.java | 2 +-
.../openejb/server/ejbd/EjbRequestHandler.java | 14 +++
7 files changed, 217 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
[08/14] tomee git commit: Add test for authorization header usage.
Fix bug where username being used instead of credential
Posted by jg...@apache.org.
Add test for authorization header usage. Fix bug where username being used instead of credential
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/3d2b2451
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/3d2b2451
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/3d2b2451
Branch: refs/heads/tomee-1.7.x
Commit: 3d2b24512e24c1a8aef6c2763f08a33d73bf446d
Parents: 7b41ae5
Author: Jonathan Gallimore <jg...@Jons-MacBook-Pro.local>
Authored: Mon Nov 7 00:27:45 2016 +0000
Committer: Jonathan Gallimore <jg...@Jons-MacBook-Pro.local>
Committed: Mon Nov 7 00:27:45 2016 +0000
----------------------------------------------------------------------
.../arquillian/tests/security/BusinessBean.java | 48 +++++++++
.../tests/security/BusinessRemote.java | 27 +++++
.../TomEEEjbServletAuthorizationHeaderTest.java | 101 +++++++++++++++++++
.../src/test/resources/arquillian.xml | 6 ++
.../src/test/tomee/conf/tomcat-users.xml | 30 ++++++
.../apache/openejb/client/ServerMetaData.java | 2 +-
6 files changed, 213 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/3d2b2451/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java
new file mode 100644
index 0000000..5a101bf
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessBean.java
@@ -0,0 +1,48 @@
+/**
+ * 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.arquillian.tests.security;
+
+import javax.annotation.Resource;
+import javax.ejb.Lock;
+import javax.ejb.LockType;
+import javax.ejb.SessionContext;
+import javax.ejb.Singleton;
+import java.security.Principal;
+
+@Singleton
+@Lock(LockType.READ)
+public class BusinessBean implements BusinessRemote {
+
+ @Resource
+ private SessionContext ctx;
+
+ @Override
+ public String echo(final String input) {
+ return input;
+ }
+
+ @Override
+ public String getPrincipal() {
+ Principal callerPrincipal = ctx.getCallerPrincipal();
+ if (callerPrincipal == null) {
+ return "null";
+ }
+
+ return callerPrincipal.getName();
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/3d2b2451/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java
new file mode 100644
index 0000000..e81f634
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/BusinessRemote.java
@@ -0,0 +1,27 @@
+/**
+ * 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.arquillian.tests.security;
+
+import javax.ejb.Remote;
+
+@Remote
+public interface BusinessRemote {
+
+ String echo(String input);
+
+ String getPrincipal();
+}
http://git-wip-us.apache.org/repos/asf/tomee/blob/3d2b2451/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
new file mode 100644
index 0000000..a42b1c0
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
@@ -0,0 +1,101 @@
+/**
+ * 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.arquillian.tests.security;
+
+import org.apache.openejb.arquillian.tests.TestRun;
+import org.apache.openejb.arquillian.tests.TestSetup;
+import org.apache.openejb.client.RemoteInitialContextFactory;
+import org.apache.openejb.server.httpd.ServerServlet;
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.container.test.api.RunAsClient;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.test.api.ArquillianResource;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import java.io.ByteArrayOutputStream;
+import java.net.URL;
+import java.nio.charset.StandardCharsets;
+import java.util.Properties;
+
+
+@RunWith(Arquillian.class)
+@RunAsClient
+public class TomEEEjbServletAuthorizationHeaderTest extends TestSetup {
+
+ public static final String TEST_NAME = TomEEEjbServletAuthorizationHeaderTest.class.getSimpleName();
+
+ @ArquillianResource
+ private URL url;
+
+ @Test
+ public void testAuthenticate() throws Exception {
+ final String ejbUrl = this.url.toExternalForm() + "ejb";
+
+ final Properties p = new Properties();
+ p.setProperty(Context.INITIAL_CONTEXT_FACTORY, RemoteInitialContextFactory.class.getName());
+ p.setProperty(Context.PROVIDER_URL, ejbUrl);
+ p.setProperty(Context.SECURITY_PRINCIPAL, "tomee");
+ p.setProperty(Context.SECURITY_CREDENTIALS, "password");
+ final InitialContext context = new InitialContext(p);
+
+ final BusinessRemote bean = (BusinessRemote) context.lookup("global/TomEEEjbServletAuthorizationHeaderTest/BusinessBean!org.apache.openejb.arquillian.tests.security.BusinessRemote");
+ Assert.assertEquals("test", bean.echo("test"));
+ }
+
+ @Deployment(testable = false)
+ public static WebArchive getArchive() {
+ return new TomEEEjbServletAuthorizationHeaderTest().createDeployment(TestRun.class, BusinessBean.class);
+ }
+
+ @Override
+ protected void decorateDescriptor(WebAppDescriptor descriptor) {
+ descriptor
+ .createServlet()
+ .servletName("ServerServlet")
+ .servletClass(ServerServlet.class.getName()).up()
+ .createServletMapping()
+ .servletName("ServerServlet")
+ .urlPattern("/ejb").up()
+ .createSecurityConstraint()
+ .getOrCreateWebResourceCollection()
+ .webResourceName("all")
+ .urlPattern("/*").up()
+ .getOrCreateAuthConstraint()
+ .roleName("tomee-admin")
+ .up().up()
+ .createLoginConfig()
+ .authMethod("BASIC");
+ }
+
+ public static void main(String[] args) throws Exception {
+ final Properties properties = new Properties();
+ properties.setProperty("tomee", "password");
+ final ByteArrayOutputStream os = new ByteArrayOutputStream();
+ properties.store(os, "");
+
+ System.out.print(new String(os.toByteArray(), StandardCharsets.UTF_8));
+ }
+}
+
+
+
http://git-wip-us.apache.org/repos/asf/tomee/blob/3d2b2451/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
index 8cbddb4..70bb894 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/resources/arquillian.xml
@@ -33,6 +33,12 @@
openejb.ear.use-as-webcontext-base=true
embedded = true
</property>
+ <property name="users">
+ tomee=password
+ </property>
+ <property name="roles">
+ tomee=tomee-admin
+ </property>
</configuration>
</container>
<container qualifier="tomee-remote">
http://git-wip-us.apache.org/repos/asf/tomee/blob/3d2b2451/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/tomee/conf/tomcat-users.xml
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/tomee/conf/tomcat-users.xml b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/tomee/conf/tomcat-users.xml
new file mode 100644
index 0000000..88c6f81
--- /dev/null
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/tomee/conf/tomcat-users.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ 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.
+--><tomcat-users>
+ <!--
+ NOTE: By default, no user is included in the "manager-gui" role required
+ to operate the "/manager/html" web application. If you wish to use this app,
+ you must define such a user - the username and password are arbitrary.
+ -->
+ <!--
+ NOTE: The sample user and role entries below are wrapped in a comment
+ and thus are ignored when reading this file. Do not forget to remove
+ <!.. ..> that surrounds them.
+ -->
+ <role rolename="tomee-admin"/>
+ <user username="tomee" password="password" roles="tomee-admin"/>
+</tomcat-users>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/tomee/blob/3d2b2451/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
index f913ca4..6f69994 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
@@ -51,7 +51,7 @@ public class ServerMetaData implements Externalizable {
locationList.add(uri);
}
locations = locationList.toArray(new URI[server.locations.length]);
- location = addUserToURI(securityPrincipal, securityPrincipal, server.location);
+ location = addUserToURI(securityPrincipal, securityCredentials, server.location);
this.metaData = server.metaData;
}
[07/14] tomee git commit: feedback per romain,
have the user set this by creating a tomee web app instead
Posted by jg...@apache.org.
feedback per romain, have the user set this by creating a tomee web app instead
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/7b41ae54
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/7b41ae54
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/7b41ae54
Branch: refs/heads/tomee-1.7.x
Commit: 7b41ae54c69cb3bbf7dd5abb77ba53a47940cd61
Parents: 68c0e0d
Author: Jonathan S. Fisher <jf...@tomitribe.com>
Authored: Fri Nov 4 16:38:43 2016 -0500
Committer: Jonathan S. Fisher <jf...@tomitribe.com>
Committed: Fri Nov 4 16:38:43 2016 -0500
----------------------------------------------------------------------
.../tomee/catalina/remote/TomEERemoteWebapp.java | 13 -------------
1 file changed, 13 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/7b41ae54/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
index 8946428..bf7baeb 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
@@ -34,7 +34,6 @@ import java.beans.PropertyChangeListener;
public class TomEERemoteWebapp extends IgnoredStandardContext {
private static final String CONTEXT_NAME = SystemInstance.get().getProperty("tomee.remote.support.context", "/tomee");
private static final String MAPPING = SystemInstance.get().getProperty("tomee.remote.support.mapping", "/ejb");
- private static final String BASIC_AUTH_ROLE_NAME = SystemInstance.get().getProperty("tomee.remote.support.basicAuthRoleName", null);
public TomEERemoteWebapp() {
@@ -44,18 +43,6 @@ public class TomEERemoteWebapp extends IgnoredStandardContext {
setName(CONTEXT_NAME);
setPath(CONTEXT_NAME);
setLoader(new ServerClassLoaderLoader(this));
- if (BASIC_AUTH_ROLE_NAME != null) {
- LoginConfig config = new LoginConfig();
- config.setAuthMethod("BASIC");
- config.setRealmName("TomEERemoteWebapp");
- SecurityConstraint constraint = new SecurityConstraint();
- SecurityCollection collection = new SecurityCollection();
- collection.addPattern("/*");
- constraint.addCollection(collection);
- constraint.addAuthRole(BASIC_AUTH_ROLE_NAME);
- addConstraint(constraint);
- setLoginConfig(config);
- }
addValve(new OpenEJBValve()); // ensure security context is resetted (ThreadLocal) for each request
}
[09/14] tomee git commit: Removing unused method
Posted by jg...@apache.org.
Removing unused method
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/eddd7115
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/eddd7115
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/eddd7115
Branch: refs/heads/tomee-1.7.x
Commit: eddd711583851db8585b29a27833f3b2f4d9a797
Parents: 3d2b245
Author: Jonathan Gallimore <jg...@Jons-MacBook-Pro.local>
Authored: Mon Nov 7 00:37:53 2016 +0000
Committer: Jonathan Gallimore <jg...@Jons-MacBook-Pro.local>
Committed: Mon Nov 7 00:37:53 2016 +0000
----------------------------------------------------------------------
.../security/TomEEEjbServletAuthorizationHeaderTest.java | 10 ----------
1 file changed, 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/eddd7115/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
----------------------------------------------------------------------
diff --git a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
index a42b1c0..0b1534c 100644
--- a/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
+++ b/arquillian/arquillian-tomee-tests/arquillian-tomee-webprofile-tests/src/test/java/org/apache/openejb/arquillian/tests/security/TomEEEjbServletAuthorizationHeaderTest.java
@@ -32,9 +32,7 @@ import org.junit.runner.RunWith;
import javax.naming.Context;
import javax.naming.InitialContext;
-import java.io.ByteArrayOutputStream;
import java.net.URL;
-import java.nio.charset.StandardCharsets;
import java.util.Properties;
@@ -87,14 +85,6 @@ public class TomEEEjbServletAuthorizationHeaderTest extends TestSetup {
.authMethod("BASIC");
}
- public static void main(String[] args) throws Exception {
- final Properties properties = new Properties();
- properties.setProperty("tomee", "password");
- final ByteArrayOutputStream os = new ByteArrayOutputStream();
- properties.store(os, "");
-
- System.out.print(new String(os.toByteArray(), StandardCharsets.UTF_8));
- }
}
[02/14] tomee git commit: cannot figure out this damned "Undefined
realm:tomee:tomee:Undefined" issue
Posted by jg...@apache.org.
cannot figure out this damned "Undefined realm:tomee:tomee:Undefined" issue
Project: http://git-wip-us.apache.org/repos/asf/tomee/repo
Commit: http://git-wip-us.apache.org/repos/asf/tomee/commit/ca5545a8
Tree: http://git-wip-us.apache.org/repos/asf/tomee/tree/ca5545a8
Diff: http://git-wip-us.apache.org/repos/asf/tomee/diff/ca5545a8
Branch: refs/heads/tomee-1.7.x
Commit: ca5545a89ad92a8e684f133aeb95890ed02167b9
Parents: 57a4dec
Author: Jonathan S. Fisher <jf...@tomitribe.com>
Authored: Fri Nov 4 15:20:01 2016 -0500
Committer: Jonathan S. Fisher <jf...@tomitribe.com>
Committed: Fri Nov 4 15:20:01 2016 -0500
----------------------------------------------------------------------
.../java/org/apache/openejb/client/Client.java | 120 ++++++++-----------
.../openejb/client/HttpConnectionFactory.java | 13 +-
.../org/apache/openejb/client/JNDIContext.java | 26 ++--
.../apache/openejb/client/JNDIContextAuth.java | 79 ------------
.../apache/openejb/client/ServerMetaData.java | 46 ++++++-
.../openejb/client/ServerMetaDataTest.java | 1 -
.../catalina/remote/TomEERemoteWebapp.java | 1 +
7 files changed, 111 insertions(+), 175 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/tomee/blob/ca5545a8/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java b/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
index 71c2c76..4cc352a 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/Client.java
@@ -16,7 +16,15 @@
*/
package org.apache.openejb.client;
-import static org.apache.openejb.client.Exceptions.newIOException;
+import org.apache.openejb.client.event.ClientVersion;
+import org.apache.openejb.client.event.ClusterMetaDataUpdated;
+import org.apache.openejb.client.event.ObserverAdded;
+import org.apache.openejb.client.event.RequestFailed;
+import org.apache.openejb.client.event.RetryConditionAdded;
+import org.apache.openejb.client.event.RetryConditionRemoved;
+import org.apache.openejb.client.event.RetryingRequest;
+import org.apache.openejb.client.event.ServerAdded;
+import org.apache.openejb.client.event.ServerRemoved;
import java.io.EOFException;
import java.io.IOException;
@@ -38,16 +46,7 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
-import org.apache.openejb.client.HttpConnectionFactory.HttpConnection;
-import org.apache.openejb.client.event.ClientVersion;
-import org.apache.openejb.client.event.ClusterMetaDataUpdated;
-import org.apache.openejb.client.event.ObserverAdded;
-import org.apache.openejb.client.event.RequestFailed;
-import org.apache.openejb.client.event.RetryConditionAdded;
-import org.apache.openejb.client.event.RetryConditionRemoved;
-import org.apache.openejb.client.event.RetryingRequest;
-import org.apache.openejb.client.event.ServerAdded;
-import org.apache.openejb.client.event.ServerRemoved;
+import static org.apache.openejb.client.Exceptions.newIOException;
public class Client {
@@ -138,15 +137,14 @@ public class Client {
}
public static Response request(final Request req, final Response res, final ServerMetaData server) throws RemoteException {
- return request(req, res, server, null);
+ try {
+ return client.processRequest(req, res, server);
+ } finally {
+ failed.remove();
+ }
}
protected Response processRequest(final Request req, final Response res, final ServerMetaData server) throws RemoteException {
- return processRequest(req, res, server, null);
- }
-
- protected Response processRequest(final Request req, final Response res, final ServerMetaData server,
- JNDIContextAuth jndiContextAuth) throws RemoteException {
if (server == null) {
throw new IllegalArgumentException("Server instance cannot be null");
@@ -155,11 +153,12 @@ public class Client {
final long start = System.nanoTime();
final ClusterMetaData cluster = getClusterMetaData(server);
- // Determine which protocol to use for request writes
+ //Determine which protocol to use for request writes
final ProtocolMetaData protocolRequest = (null != COMPATIBLE_META_DATA ? COMPATIBLE_META_DATA : PROTOCOL_META_DATA);
/*----------------------------*/
/* Get a connection to server */
+ /*----------------------------*/
final Connection conn;
try {
@@ -168,15 +167,12 @@ public class Client {
throw new RemoteException("Unable to connect", e);
}
- if (jndiContextAuth != null && conn instanceof HttpConnection) {
- ((HttpConnection) conn).setAuthenticationHeader(jndiContextAuth);
- }
-
OutputStream out = null;
InputStream in = null;
try {
+
/*----------------------------------*/
/* Get output streams */
/*----------------------------------*/
@@ -189,7 +185,7 @@ public class Client {
}
/*----------------------------------*/
- /* Write the protocol magic */
+ /* Write the protocol magic */
/*----------------------------------*/
try {
protocolRequest.writeExternal(out);
@@ -260,7 +256,7 @@ public class Client {
}
/*----------------------------------*/
- /* Get input streams */
+ /* Get input streams */
/*----------------------------------*/
try {
@@ -271,7 +267,7 @@ public class Client {
throw newIOException("Cannot open input stream to server: ", e);
}
- // Determine the server response protocol for reading
+ //Determine the server response protocol for reading
final ProtocolMetaData protocolResponse = new ProtocolMetaData();
try {
@@ -279,14 +275,11 @@ public class Client {
} catch (final EOFException e) {
- String message = "Prematurely reached the end of the stream. " + protocolResponse.getSpec() + " : " + e.getMessage();
- throw newIOException(message, e);
+ throw newIOException("Prematurely reached the end of the stream. " + protocolResponse.getSpec() + " : " + e.getMessage(), e);
} catch (final IOException e) {
- String message = "Cannot determine server protocol version: Received " + protocolResponse.getSpec() + " : "
- + e.getMessage();
- throw newIOException(message, e);
+ throw newIOException("Cannot determine server protocol version: Received " + protocolResponse.getSpec() + " : " + e.getMessage(), e);
}
final ObjectInput objectIn;
@@ -295,8 +288,7 @@ public class Client {
objectIn = new EjbObjectInputStream(in);
} catch (final IOException e) {
- String message = "Cannot open object input stream to server (" + protocolResponse.getSpec() + ") : " + e.getMessage();
- throw newIOException(message, e);
+ throw newIOException("Cannot open object input stream to server (" + protocolResponse.getSpec() + ") : " + e.getMessage(), e);
}
/*----------------------------------*/
@@ -307,26 +299,22 @@ public class Client {
clusterResponse.setMetaData(protocolResponse);
clusterResponse.readExternal(objectIn);
switch (clusterResponse.getResponseCode()) {
- case UPDATE: {
- setClusterMetaData(server, clusterResponse.getUpdatedMetaData());
- }
+ case UPDATE: {
+ setClusterMetaData(server, clusterResponse.getUpdatedMetaData());
+ }
break;
- case FAILURE: {
- throw clusterResponse.getFailure();
- }
+ case FAILURE: {
+ throw clusterResponse.getFailure();
+ }
}
} catch (final ClassNotFoundException e) {
- String message = "Cannot read the cluster response from the server. The class for an object being returned is not located in this system:";
- throw new RemoteException(message, e);
+ throw new RemoteException("Cannot read the cluster response from the server. The class for an object being returned is not located in this system:", e);
} catch (final IOException e) {
- String message = "Cannot read the cluster response from the server (" + protocolResponse.getSpec() + ") : "
- + e.getMessage();
- throw newIOException(message, e);
+ throw newIOException("Cannot read the cluster response from the server (" + protocolResponse.getSpec() + ") : " + e.getMessage(), e);
} catch (final Throwable e) {
- String message = "Error reading cluster response from server (" + protocolResponse.getSpec() + ") : " + e.getMessage();
- throw new RemoteException(message, e);
+ throw new RemoteException("Error reading cluster response from server (" + protocolResponse.getSpec() + ") : " + e.getMessage(), e);
}
/*----------------------------------*/
@@ -336,16 +324,13 @@ public class Client {
res.setMetaData(protocolResponse);
res.readExternal(objectIn);
} catch (final ClassNotFoundException e) {
- String message = "Cannot read the response from the server. The class for an object being returned is not located in this system:";
- throw new RemoteException(message, e);
+ throw new RemoteException("Cannot read the response from the server. The class for an object being returned is not located in this system:", e);
} catch (final IOException e) {
- String message = "Cannot read the response from the server (" + protocolResponse.getSpec() + ") : " + e.getMessage();
- throw newIOException(message, e);
+ throw newIOException("Cannot read the response from the server (" + protocolResponse.getSpec() + ") : " + e.getMessage(), e);
} catch (final Throwable e) {
- String message = "Error reading response from server (" + protocolResponse.getSpec() + ") : " + e.getMessage();
- throw new RemoteException(message, e);
+ throw new RemoteException("Error reading response from server (" + protocolResponse.getSpec() + ") : " + e.getMessage(), e);
}
if (retryConditions.size() > 0) {
@@ -353,19 +338,18 @@ public class Client {
final EJBResponse ejbResponse = (EJBResponse) res;
if (ejbResponse.getResult() instanceof ThrowableArtifact) {
final ThrowableArtifact artifact = (ThrowableArtifact) ejbResponse.getResult();
- // noinspection ThrowableResultOfMethodCallIgnored
+ //noinspection ThrowableResultOfMethodCallIgnored
if (retryConditions.contains(artifact.getThrowable().getClass())) {
throw new RetryException(res);
- // if (? < maxConditionRetry) {
- // throw new RetryException(res);
- // } else {
- // if (FINER) {
- // logger.log(Level.FINER, "Giving up on " +
- // artifact.getThrowable().getClass().getName().toString());
- // }
- // }
+ // if (? < maxConditionRetry) {
+ // throw new RetryException(res);
+ // } else {
+ // if (FINER) {
+ // logger.log(Level.FINER, "Giving up on " + artifact.getThrowable().getClass().getName().toString());
+ // }
+ // }
}
}
}
@@ -373,8 +357,7 @@ public class Client {
if (FINEST) {
final long time = System.nanoTime() - start;
- final String message = String.format("Invocation %sns - %s - Request(%s) - Response(%s)", time, conn.getURI(), req,
- res);
+ final String message = String.format("Invocation %sns - %s - Request(%s) - Response(%s)", time, conn.getURI(), req, res);
logger.log(Level.FINEST, message);
}
@@ -397,7 +380,7 @@ public class Client {
Client.fireEvent(new RetryingRequest(req, server));
- processRequest(req, res, server, jndiContextAuth);
+ processRequest(req, res, server);
} catch (final RemoteFailoverException re) {
throw re;
} catch (final RemoteException re) {
@@ -425,15 +408,6 @@ public class Client {
return res;
}
- public static Response request(final Request req, final Response res, final ServerMetaData server, JNDIContextAuth jndiContextAuth)
- throws RemoteException {
- try {
- return client.processRequest(req, res, server, jndiContextAuth);
- } finally {
- failed.remove();
- }
- }
-
public static Set<URI> getFailed() {
Set<URI> set = failed.get();
if (set == null) {
@@ -452,7 +426,7 @@ public class Client {
return getContext(server).getClusterMetaData();
}
- // openejb.client.connection.strategy
+ //openejb.client.connection.strategy
private boolean getRetry() {
return retry = Boolean.valueOf(System.getProperty("openejb.client.requestretry", retry + ""));
http://git-wip-us.apache.org/repos/asf/tomee/blob/ca5545a8/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
index 4551305..9cb86bd 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/HttpConnectionFactory.java
@@ -15,7 +15,7 @@
* limitations under the License.
*/
package org.apache.openejb.client;
-
+import static javax.xml.bind.DatatypeConverter.printBase64Binary;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -23,6 +23,7 @@ import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.nio.charset.StandardCharsets;
import java.security.KeyManagementException;
import java.security.NoSuchAlgorithmException;
import java.util.Map;
@@ -92,6 +93,12 @@ public class HttpConnectionFactory implements ConnectionFactory {
httpURLConnection.setReadTimeout(Integer.parseInt(params.get("readTimeout")));
}
+ if (uri.getUserInfo() != null) {
+ String authorization = "Basic "
+ + printBase64Binary((url.getUserInfo()).getBytes(StandardCharsets.UTF_8));
+ httpURLConnection.setRequestProperty("Authorization", authorization);
+ }
+
if (params.containsKey("sslKeyStore") || params.containsKey("sslTrustStore")) {
try {
SSLSocketFactory sslSocketFactory = socketFactoryMap.get(uri);
@@ -182,9 +189,5 @@ public class HttpConnectionFactory implements ConnectionFactory {
}
return inputStream;
}
-
- public void setAuthenticationHeader(JNDIContextAuth jndiContextAuth) {
- jndiContextAuth.setAuthenticationHeader(httpURLConnection);
- }
}
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/ca5545a8/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 b97b636..94dd9c3 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
@@ -88,7 +88,6 @@ public class JNDIContext implements InitialContextFactory, Context {
private ClientInstance clientIdentity;
// TODO read HTTP_AUTH_DISABLE on creation
private boolean disableHttpAuth = false;
- private JNDIContextAuth jndiContextAuth;
private static final ThreadPoolExecutor GLOBAL_CLIENT_POOL = newExecutor(10, null);
@@ -226,19 +225,16 @@ public class JNDIContext implements InitialContextFactory, Context {
req.setServerHash(server.buildHash());
final JNDIResponse response = new JNDIResponse();
- if (authenticationInfo != null && !disableHttpAuth){
- Client.request(req, response, server, jndiContextAuth);
- } else {
- Client.request(req, response, server, null);
- }
+ Client.request(req, response, server);
if (null != response.getServer()) {
server.merge(response.getServer());
}
return response;
}
+
protected AuthenticationResponse requestAuthorization(final AuthenticationRequest req) throws RemoteException {
- return (AuthenticationResponse) Client.request(req, new AuthenticationResponse(), server, jndiContextAuth);
+ return (AuthenticationResponse) Client.request(req, new AuthenticationResponse(), server);
}
@Override
@@ -249,8 +245,7 @@ public class JNDIContext implements InitialContextFactory, Context {
env = (Hashtable) environment.clone();
}
- jndiContextAuth = new JNDIContextAuth((String) env.get(Context.SECURITY_PRINCIPAL),
- ((String) env.get(Context.SECURITY_CREDENTIALS)));
+
String providerUrl = (String) env.get(Context.PROVIDER_URL);
final boolean authWithRequest = "true"
@@ -267,6 +262,11 @@ public class JNDIContext implements InitialContextFactory, Context {
.initCause(e);
}
this.server = new ServerMetaData(location);
+ String securityPrincipal = (String) env.get(Context.SECURITY_PRINCIPAL);
+ String securityCredentials = (String) env.get(Context.SECURITY_CREDENTIALS);
+ if (securityPrincipal != null) {
+ server = new ServerMetaData(server, securityPrincipal, securityCredentials);
+ }
final Client.Context context = Client.getContext(this.server);
context.getProperties().putAll(environment);
@@ -278,12 +278,12 @@ public class JNDIContext implements InitialContextFactory, Context {
// TODO: Either aggressively initiate authentication or wait for the
// server to send us an authentication challenge.
- if (jndiContextAuth.username != null) {
+ if (securityPrincipal != null) {
if (!authWithRequest) {
- authenticate(jndiContextAuth.username, String.valueOf(jndiContextAuth.password), false);
+ authenticate(securityPrincipal, securityCredentials, false);
} else {
authenticationInfo = new AuthenticationInfo(String.class.cast(env.get(AUTHENTICATION_REALM_NAME)),
- jndiContextAuth.username, jndiContextAuth.password, getTimeout(env));
+ securityPrincipal, securityCredentials.toCharArray(), getTimeout(env));
}
}
if (client == null) {
@@ -370,7 +370,7 @@ public class JNDIContext implements InitialContextFactory, Context {
public void authenticate(final String userID, final String psswrd, final boolean logout)
throws AuthenticationException {
-
+//TODO needs http auth
final AuthenticationRequest req = new AuthenticationRequest(
String.class.cast(env.get(AUTHENTICATION_REALM_NAME)), userID, psswrd, getTimeout(env));
http://git-wip-us.apache.org/repos/asf/tomee/blob/ca5545a8/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContextAuth.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContextAuth.java b/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContextAuth.java
deleted file mode 100644
index 6fb7f98..0000000
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/JNDIContextAuth.java
+++ /dev/null
@@ -1,79 +0,0 @@
-package org.apache.openejb.client;
-
-import static javax.xml.bind.DatatypeConverter.printBase64Binary;
-
-import java.io.Serializable;
-import java.net.HttpURLConnection;
-import java.nio.charset.StandardCharsets;
-import java.util.Arrays;
-
-public class JNDIContextAuth implements Serializable {
- private static final long serialVersionUID = 1L;
- public final String username;
- public final char[] password;
-
- public JNDIContextAuth(String username, String password) {
- this.username = username;
- if (password != null) {
- this.password = password.toCharArray();
- } else {
- this.password = new char[0];
- }
- checkConstraints();
- }
-
- public void checkConstraints() {
- if (username == null) {
- throw new IllegalArgumentException("username cannot be null, don't use this class if you don't have a username");
- }
- }
-
- public void setAuthenticationHeader(HttpURLConnection httpURLConnection) {
- httpURLConnection.setRequestProperty("Authorization", "Basic " + toEncodedString());
- }
-
- public String toEncodedString() {
- byte[] message = (username + ":" + String.valueOf(password)).getBytes(StandardCharsets.UTF_8);
- String encoded = printBase64Binary(message);
- return encoded;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + Arrays.hashCode(password);
- result = prime * result + ((username == null) ? 0 : username.hashCode());
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (obj == null) {
- return false;
- }
- if (!(obj instanceof JNDIContextAuth)) {
- return false;
- }
- JNDIContextAuth other = (JNDIContextAuth) obj;
- if (!Arrays.equals(password, other.password)) {
- return false;
- }
- if (username == null) {
- if (other.username != null) {
- return false;
- }
- } else if (!username.equals(other.username)) {
- return false;
- }
- return true;
- }
-
- @Override
- public String toString() {
- return "JNDIContextAuth [username=" + username + ", password=" + Arrays.toString(password) + "]";
- }
-}
http://git-wip-us.apache.org/repos/asf/tomee/blob/ca5545a8/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
index bb9e36d..60c9c92 100644
--- a/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
+++ b/server/openejb-client/src/main/java/org/apache/openejb/client/ServerMetaData.java
@@ -21,23 +21,62 @@ import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.ArrayList;
import java.util.Arrays;
+import java.util.List;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
public class ServerMetaData implements Externalizable {
private static final long serialVersionUID = -915541900332460068L;
+ private static final transient Pattern urlPattern = Pattern.compile("http(?s):\\/\\/(.+):(.+)@.*");
private transient URI[] locations;
private transient URI location;
private transient ProtocolMetaData metaData;
- public ServerMetaData() {
- }
-
public ServerMetaData(final URI... locations) {
this.locations = locations;
location = locations[0];
}
+ public ServerMetaData(ServerMetaData server, String securityPrincipal, String securityCredentials) {
+ List<URI> locationList = new ArrayList<URI>(server.locations.length);
+ for (URI uri : server.locations) {
+ uri = addUserToURI(securityPrincipal, securityPrincipal, uri);
+ locationList.add(uri);
+ }
+ locations = locationList.toArray(new URI[server.locations.length]);
+ location = addUserToURI(securityPrincipal, securityPrincipal, server.location);
+ this.metaData = server.metaData;
+ }
+
+ private URI addUserToURI(String securityPrincipal, String securityCredentials, URI uri) {
+ String uriString = uri.toString();
+ Matcher matcher = urlPattern.matcher(uriString);
+ if (!matcher.matches()) {
+ String restOfUrl = null;
+ String scheme = null;
+ if (uriString.startsWith("http://")) {
+ restOfUrl = uriString.substring("http://".length());
+ scheme = "http://";
+ } else if (uriString.startsWith("https://")) {
+ restOfUrl = uriString.substring("https://".length());
+ scheme = "https://";
+ }
+ if (restOfUrl != null) {
+ try {
+ uri = new URI(scheme + securityPrincipal + ":" + (securityCredentials == null ? "" : securityCredentials) + "@"
+ + restOfUrl);
+ } catch (URISyntaxException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ }
+ return uri;
+ }
+
public void setMetaData(final ProtocolMetaData metaData) {
this.metaData = metaData;
}
@@ -100,4 +139,3 @@ public class ServerMetaData implements Externalizable {
return (location != null ? location.hashCode() : 0);
}
}
-
http://git-wip-us.apache.org/repos/asf/tomee/blob/ca5545a8/server/openejb-client/src/test/java/org/apache/openejb/client/ServerMetaDataTest.java
----------------------------------------------------------------------
diff --git a/server/openejb-client/src/test/java/org/apache/openejb/client/ServerMetaDataTest.java b/server/openejb-client/src/test/java/org/apache/openejb/client/ServerMetaDataTest.java
index 365deff..b578695 100644
--- a/server/openejb-client/src/test/java/org/apache/openejb/client/ServerMetaDataTest.java
+++ b/server/openejb-client/src/test/java/org/apache/openejb/client/ServerMetaDataTest.java
@@ -29,5 +29,4 @@ public class ServerMetaDataTest extends TestCase {
final ServerMetaData server2 = new ServerMetaData(uri2, uri1);
assertEquals(server1.buildHash(), server2.buildHash());
}
-
}
http://git-wip-us.apache.org/repos/asf/tomee/blob/ca5545a8/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
----------------------------------------------------------------------
diff --git a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
index 006db5e..8946428 100644
--- a/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
+++ b/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/remote/TomEERemoteWebapp.java
@@ -47,6 +47,7 @@ public class TomEERemoteWebapp extends IgnoredStandardContext {
if (BASIC_AUTH_ROLE_NAME != null) {
LoginConfig config = new LoginConfig();
config.setAuthMethod("BASIC");
+ config.setRealmName("TomEERemoteWebapp");
SecurityConstraint constraint = new SecurityConstraint();
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");