moved to codehaus
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@733 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
8e7032aa42
commit
800dfa2883
|
@ -6,7 +6,6 @@ jetty-7.0.0.RC4-SNAPSHOT
|
|||
+ JETTY-1079 ResourceCollection.toString
|
||||
+ 279820 Fixed HotSwapHandler
|
||||
+ JETTY-1080 Ignore files that would be extracted outside the destination directory when unpacking WARs
|
||||
+ 286242 Ported jetty-setuid from jetty-6
|
||||
|
||||
jetty-7.0.0.RC3 7 August 2009
|
||||
+ 277403 remove system properties
|
||||
|
|
|
@ -179,16 +179,6 @@
|
|||
<includes>**</includes>
|
||||
<outputDirectory>${assembly.directory}</outputDirectory>
|
||||
</artifactItem>
|
||||
<artifactItem>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-setuid</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<classifier>config</classifier>
|
||||
<type>jar</type>
|
||||
<overWrite>true</overWrite>
|
||||
<includes>**</includes>
|
||||
<outputDirectory>${assembly.directory}</outputDirectory>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
@ -391,15 +381,6 @@
|
|||
<outputDirectory>${assembly.directory}</outputDirectory>
|
||||
<destFileName>start.jar</destFileName>
|
||||
</artifactItem>
|
||||
<artifactItem>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-setuid</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<type>jar</type>
|
||||
<overWrite>true</overWrite>
|
||||
<includes>**</includes>
|
||||
<outputDirectory>${assembly.directory}/lib</outputDirectory>
|
||||
</artifactItem>
|
||||
</artifactItems>
|
||||
</configuration>
|
||||
</execution>
|
||||
|
@ -410,12 +391,6 @@
|
|||
</goals>
|
||||
<configuration>
|
||||
<artifactItems>
|
||||
<artifactItem>
|
||||
<groupId>net.java.dev.jna</groupId>
|
||||
<artifactId>jna</artifactId>
|
||||
<version>${jna-version}</version>
|
||||
<outputDirectory>${assembly.directory}/lib/setuid</outputDirectory>
|
||||
</artifactItem>
|
||||
<!--
|
||||
<artifactItem>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
|
@ -529,11 +504,6 @@
|
|||
<artifactId>jetty-policy</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-setuid</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
||||
|
|
|
@ -1,79 +0,0 @@
|
|||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<parent>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-project</artifactId>
|
||||
<version>7.0.0.RC4-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<artifactId>jetty-jndi</artifactId>
|
||||
<name>Jetty :: JNDI Naming</name>
|
||||
<description>JNDI spi impl for java namespace.</description>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.felix</groupId>
|
||||
<artifactId>maven-bundle-plugin</artifactId>
|
||||
<version>${felix.bundle.version}</version>
|
||||
<extensions>true</extensions>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>manifest</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!--
|
||||
Required for OSGI
|
||||
-->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-webapp</artifactId>
|
||||
<version>${project.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>${mail-version}</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>below-jdk1.6</id>
|
||||
<activation>
|
||||
<jdk>!1.6</jdk>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.activation</groupId>
|
||||
<artifactId>activation</artifactId>
|
||||
<version>${activation-version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</profile>
|
||||
</profiles>
|
||||
</project>
|
|
@ -1,192 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.jndi;
|
||||
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.StringRefAddr;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.eclipse.jetty.server.handler.ContextHandler;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* ContextFactory.java
|
||||
*
|
||||
* This is an object factory that produces a jndi naming
|
||||
* context based on a classloader.
|
||||
*
|
||||
* It is used for the java:comp context.
|
||||
*
|
||||
* This object factory is bound at java:comp. When a
|
||||
* lookup arrives for java:comp, this object factory
|
||||
* is invoked and will return a context specific to
|
||||
* the caller's environment (so producing the java:comp/env
|
||||
* specific to a webapp).
|
||||
*
|
||||
* The context selected is based on classloaders. First
|
||||
* we try looking in at the classloader that is associated
|
||||
* with the current webapp context (if there is one). If
|
||||
* not, we use the thread context classloader.
|
||||
*
|
||||
* Created: Fri Jun 27 09:26:40 2003
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ContextFactory implements ObjectFactory
|
||||
{
|
||||
/**
|
||||
* Map of classloaders to contexts.
|
||||
*/
|
||||
private static WeakHashMap _contextMap;
|
||||
|
||||
/**
|
||||
* Threadlocal for injecting a context to use
|
||||
* instead of looking up the map.
|
||||
*/
|
||||
private static ThreadLocal _threadContext;
|
||||
|
||||
static
|
||||
{
|
||||
_contextMap = new WeakHashMap();
|
||||
_threadContext = new ThreadLocal();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Find or create a context which pertains to a classloader.
|
||||
*
|
||||
* We use either the classloader for the current ContextHandler if
|
||||
* we are handling a request, OR we use the thread context classloader
|
||||
* if we are not processing a request.
|
||||
* @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
|
||||
*/
|
||||
public Object getObjectInstance (Object obj,
|
||||
Name name,
|
||||
Context nameCtx,
|
||||
Hashtable env)
|
||||
throws Exception
|
||||
{
|
||||
//First, see if we have had a context injected into us to use.
|
||||
Context ctx = (Context)_threadContext.get();
|
||||
if (ctx != null)
|
||||
{
|
||||
if(Log.isDebugEnabled()) Log.debug("Using the Context that is bound on the thread");
|
||||
return ctx;
|
||||
}
|
||||
|
||||
// Next, see if we are in a webapp context, if we are, use
|
||||
// the classloader of the webapp to find the right jndi comp context
|
||||
ClassLoader loader = null;
|
||||
if (ContextHandler.getCurrentContext() != null)
|
||||
{
|
||||
loader = ContextHandler.getCurrentContext().getContextHandler().getClassLoader();
|
||||
}
|
||||
|
||||
|
||||
if (loader != null)
|
||||
{
|
||||
if (Log.isDebugEnabled()) Log.debug("Using classloader of current org.eclipse.jetty.server.handler.ContextHandler");
|
||||
}
|
||||
else
|
||||
{
|
||||
//Not already in a webapp context, in that case, we try the
|
||||
//curren't thread's classloader instead
|
||||
loader = Thread.currentThread().getContextClassLoader();
|
||||
if (Log.isDebugEnabled()) Log.debug("Using thread context classloader");
|
||||
}
|
||||
|
||||
//Get the context matching the classloader
|
||||
ctx = (Context)_contextMap.get(loader);
|
||||
|
||||
//The map does not contain an entry for this classloader
|
||||
if (ctx == null)
|
||||
{
|
||||
//Check if a parent classloader has created the context
|
||||
ctx = getParentClassLoaderContext(loader);
|
||||
|
||||
//Didn't find a context to match any of the ancestors
|
||||
//of the classloader, so make a context
|
||||
if (ctx == null)
|
||||
{
|
||||
Reference ref = (Reference)obj;
|
||||
StringRefAddr parserAddr = (StringRefAddr)ref.get("parser");
|
||||
String parserClassName = (parserAddr==null?null:(String)parserAddr.getContent());
|
||||
NameParser parser = (NameParser)(parserClassName==null?null:loader.loadClass(parserClassName).newInstance());
|
||||
|
||||
ctx = new NamingContext (env,
|
||||
name.get(0),
|
||||
nameCtx,
|
||||
parser);
|
||||
if(Log.isDebugEnabled())Log.debug("No entry for classloader: "+loader);
|
||||
_contextMap.put (loader, ctx);
|
||||
}
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
/**
|
||||
* Keep trying ancestors of the given classloader to find one to which
|
||||
* the context is bound.
|
||||
* @param loader
|
||||
* @return
|
||||
*/
|
||||
public Context getParentClassLoaderContext (ClassLoader loader)
|
||||
{
|
||||
Context ctx = null;
|
||||
ClassLoader cl = loader;
|
||||
for (cl = cl.getParent(); (cl != null) && (ctx == null); cl = cl.getParent())
|
||||
{
|
||||
ctx = (Context)_contextMap.get(cl);
|
||||
}
|
||||
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Associate the given Context with the current thread.
|
||||
* resetComponentContext method should be called to reset the context.
|
||||
* @param ctx the context to associate to the current thread.
|
||||
* @return the previous context associated on the thread (can be null)
|
||||
*/
|
||||
public static Context setComponentContext(final Context ctx)
|
||||
{
|
||||
Context previous = (Context)_threadContext.get();
|
||||
_threadContext.set(ctx);
|
||||
return previous;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set back the context with the given value.
|
||||
* Don't return the previous context, use setComponentContext() method for this.
|
||||
* @param ctx the context to associate to the current thread.
|
||||
*/
|
||||
public static void resetComponentContext(final Context ctx)
|
||||
{
|
||||
_threadContext.set(ctx);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.jndi;
|
||||
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.naming.CompoundName;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.eclipse.jetty.jndi.local.localContextRoot;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
||||
|
||||
/*------------------------------------------------*/
|
||||
/**
|
||||
* InitialContextFactory.java
|
||||
*
|
||||
* Factory for the default InitialContext.
|
||||
* Created: Tue Jul 1 19:08:08 2003
|
||||
*
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
public class InitialContextFactory implements javax.naming.spi.InitialContextFactory
|
||||
{
|
||||
public static class DefaultParser implements NameParser
|
||||
{
|
||||
static Properties syntax = new Properties();
|
||||
static
|
||||
{
|
||||
syntax.put("jndi.syntax.direction", "left_to_right");
|
||||
syntax.put("jndi.syntax.separator", "/");
|
||||
syntax.put("jndi.syntax.ignorecase", "false");
|
||||
}
|
||||
public Name parse (String name)
|
||||
throws NamingException
|
||||
{
|
||||
return new CompoundName (name, syntax);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------*/
|
||||
/**
|
||||
* Get Context that has access to default Namespace.
|
||||
* This method won't be called if a name URL beginning
|
||||
* with java: is passed to an InitialContext.
|
||||
*
|
||||
* @see org.eclipse.jetty.jndi.java.javaURLContextFactory
|
||||
* @param env a <code>Hashtable</code> value
|
||||
* @return a <code>Context</code> value
|
||||
*/
|
||||
public Context getInitialContext(Hashtable env)
|
||||
{
|
||||
Log.debug("InitialContextFactory.getInitialContext()");
|
||||
|
||||
Context ctx = new localContextRoot(env);
|
||||
if(Log.isDebugEnabled())Log.debug("Created initial context delegate for local namespace:"+ctx);
|
||||
|
||||
return ctx;
|
||||
}
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -1,139 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.jndi;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.naming.Binding;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameNotFoundException;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
||||
|
||||
/**
|
||||
* Util.java
|
||||
*
|
||||
*
|
||||
* Created: Tue Jul 1 18:26:17 2003
|
||||
*
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
public class NamingUtil
|
||||
{
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Bind an object to a context ensuring all subcontexts
|
||||
* are created if necessary
|
||||
*
|
||||
* @param ctx the context into which to bind
|
||||
* @param name the name relative to context to bind
|
||||
* @param obj the object to be bound
|
||||
* @exception NamingException if an error occurs
|
||||
*/
|
||||
public static Context bind (Context ctx, String nameStr, Object obj)
|
||||
throws NamingException
|
||||
{
|
||||
Name name = ctx.getNameParser("").parse(nameStr);
|
||||
|
||||
//no name, nothing to do
|
||||
if (name.size() == 0)
|
||||
return null;
|
||||
|
||||
Context subCtx = ctx;
|
||||
|
||||
//last component of the name will be the name to bind
|
||||
for (int i=0; i < name.size() - 1; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
subCtx = (Context)subCtx.lookup (name.get(i));
|
||||
if(Log.isDebugEnabled())Log.debug("Subcontext "+name.get(i)+" already exists");
|
||||
}
|
||||
catch (NameNotFoundException e)
|
||||
{
|
||||
subCtx = subCtx.createSubcontext(name.get(i));
|
||||
if(Log.isDebugEnabled())Log.debug("Subcontext "+name.get(i)+" created");
|
||||
}
|
||||
}
|
||||
|
||||
subCtx.rebind (name.get(name.size() - 1), obj);
|
||||
if(Log.isDebugEnabled())Log.debug("Bound object to "+name.get(name.size() - 1));
|
||||
return subCtx;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public static void unbind (Context ctx)
|
||||
throws NamingException
|
||||
{
|
||||
//unbind everything in the context and all of its subdirectories
|
||||
NamingEnumeration ne = ctx.listBindings(ctx.getNameInNamespace());
|
||||
|
||||
while (ne.hasMoreElements())
|
||||
{
|
||||
Binding b = (Binding)ne.nextElement();
|
||||
if (b.getObject() instanceof Context)
|
||||
{
|
||||
unbind((Context)b.getObject());
|
||||
}
|
||||
else
|
||||
ctx.unbind(b.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do a deep listing of the bindings for a context.
|
||||
* @param ctx the context containing the name for which to list the bindings
|
||||
* @param name the name in the context to list
|
||||
* @return map: key is fully qualified name, value is the bound object
|
||||
* @throws NamingException
|
||||
*/
|
||||
public static Map flattenBindings (Context ctx, String name)
|
||||
throws NamingException
|
||||
{
|
||||
HashMap map = new HashMap();
|
||||
|
||||
//the context representation of name arg
|
||||
Context c = (Context)ctx.lookup (name);
|
||||
NameParser parser = c.getNameParser("");
|
||||
NamingEnumeration enm = ctx.listBindings(name);
|
||||
while (enm.hasMore())
|
||||
{
|
||||
Binding b = (Binding)enm.next();
|
||||
|
||||
if (b.getObject() instanceof Context)
|
||||
{
|
||||
map.putAll(flattenBindings (c, b.getName()));
|
||||
}
|
||||
else
|
||||
{
|
||||
Name compoundName = parser.parse (c.getNameInNamespace());
|
||||
compoundName.add(b.getName());
|
||||
map.put (compoundName.toString(), b.getObject());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,183 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.jndi.factories;
|
||||
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.RefAddr;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.StringRefAddr;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.eclipse.jetty.http.security.Password;
|
||||
|
||||
/**
|
||||
* MailSessionReference
|
||||
*
|
||||
* This is a subclass of javax.mail.Reference and an ObjectFactory for javax.mail.Session objects.
|
||||
*
|
||||
* The subclassing of Reference allows all of the setup for a javax.mail.Session
|
||||
* to be captured without necessitating first instantiating a Session object. The
|
||||
* reference is bound into JNDI and it is only when the reference is looked up that
|
||||
* this object factory will create an instance of javax.mail.Session using the
|
||||
* information captured in the Reference.
|
||||
*
|
||||
*/
|
||||
public class MailSessionReference extends Reference implements ObjectFactory
|
||||
{
|
||||
|
||||
|
||||
public static class PasswordAuthenticator extends Authenticator
|
||||
{
|
||||
PasswordAuthentication passwordAuthentication;
|
||||
private String user;
|
||||
private String password;
|
||||
|
||||
public PasswordAuthenticator()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public PasswordAuthenticator(String user, String password)
|
||||
{
|
||||
passwordAuthentication = new PasswordAuthentication (user, (password.startsWith(Password.__OBFUSCATE)?Password.deobfuscate(password):password));
|
||||
}
|
||||
|
||||
public PasswordAuthentication getPasswordAuthentication()
|
||||
{
|
||||
return passwordAuthentication;
|
||||
}
|
||||
|
||||
public void setUser (String user)
|
||||
{
|
||||
this.user = user;
|
||||
}
|
||||
public String getUser ()
|
||||
{
|
||||
return this.user;
|
||||
}
|
||||
|
||||
public String getPassword ()
|
||||
{
|
||||
return this.password;
|
||||
}
|
||||
|
||||
public void setPassword(String password)
|
||||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public MailSessionReference()
|
||||
{
|
||||
super ("javax.mail.Session", MailSessionReference.class.getName(), null);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a javax.mail.Session instance based on the information passed in the Reference
|
||||
* @see javax.naming.spi.ObjectFactory#getObjectInstance(java.lang.Object, javax.naming.Name, javax.naming.Context, java.util.Hashtable)
|
||||
* @param ref the Reference
|
||||
* @param arg1 not used
|
||||
* @param arg2 not used
|
||||
* @param arg3 not used
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
public Object getObjectInstance(Object ref, Name arg1, Context arg2, Hashtable arg3) throws Exception
|
||||
{
|
||||
if (ref == null)
|
||||
return null;
|
||||
|
||||
Reference reference = (Reference)ref;
|
||||
|
||||
|
||||
Properties props = new Properties();
|
||||
String user = null;
|
||||
String password = null;
|
||||
|
||||
Enumeration refs = reference.getAll();
|
||||
while (refs.hasMoreElements())
|
||||
{
|
||||
RefAddr refAddr = (RefAddr)refs.nextElement();
|
||||
String name = refAddr.getType();
|
||||
String value = (String)refAddr.getContent();
|
||||
if (name.equalsIgnoreCase("user"))
|
||||
user = value;
|
||||
else if (name.equalsIgnoreCase("pwd"))
|
||||
password = value;
|
||||
else
|
||||
props.put(name, value);
|
||||
}
|
||||
|
||||
if (password == null)
|
||||
return Session.getInstance(props);
|
||||
else
|
||||
return Session.getInstance(props, new PasswordAuthenticator(user, password));
|
||||
}
|
||||
|
||||
|
||||
public void setUser (String user)
|
||||
{
|
||||
StringRefAddr addr = (StringRefAddr)get("user");
|
||||
if (addr != null)
|
||||
{
|
||||
throw new RuntimeException ("user already set on SessionReference, can't be changed");
|
||||
}
|
||||
add(new StringRefAddr("user", user));
|
||||
}
|
||||
|
||||
public void setPassword (String password)
|
||||
{
|
||||
StringRefAddr addr = (StringRefAddr)get("pwd");
|
||||
if (addr != null)
|
||||
throw new RuntimeException ("password already set on SessionReference, can't be changed");
|
||||
add(new StringRefAddr ("pwd", password));
|
||||
}
|
||||
|
||||
public void setProperties (Properties properties)
|
||||
{
|
||||
Iterator entries = properties.entrySet().iterator();
|
||||
while (entries.hasNext())
|
||||
{
|
||||
Map.Entry e = (Map.Entry)entries.next();
|
||||
StringRefAddr sref = (StringRefAddr)get((String)e.getKey());
|
||||
if (sref != null)
|
||||
throw new RuntimeException ("property "+e.getKey()+" already set on Session reference, can't be changed");
|
||||
add(new StringRefAddr((String)e.getKey(), (String)e.getValue()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2006-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.jndi.java;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.naming.CompoundName;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
|
||||
/**
|
||||
* javaNameParser
|
||||
*
|
||||
*/
|
||||
public class javaNameParser implements NameParser
|
||||
{
|
||||
|
||||
static Properties syntax = new Properties();
|
||||
|
||||
static
|
||||
{
|
||||
syntax.put("jndi.syntax.direction", "left_to_right");
|
||||
syntax.put("jndi.syntax.separator", "/");
|
||||
syntax.put("jndi.syntax.ignorecase", "false");
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse a name into its components.
|
||||
* @param name The non-null string name to parse.
|
||||
* @return A non-null parsed form of the name using the naming convention
|
||||
* of this parser.
|
||||
* @exception NamingException If a naming exception was encountered.
|
||||
*/
|
||||
public Name parse(String name) throws NamingException
|
||||
{
|
||||
return new CompoundName(name, syntax);
|
||||
}
|
||||
|
||||
}
|
|
@ -1,329 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.jndi.java;
|
||||
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.StringRefAddr;
|
||||
|
||||
import org.eclipse.jetty.jndi.ContextFactory;
|
||||
import org.eclipse.jetty.jndi.NamingContext;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
||||
|
||||
|
||||
|
||||
/** javaRootURLContext
|
||||
* <p>This is the root of the java: url namespace
|
||||
*
|
||||
* <p><h4>Notes</h4>
|
||||
* <p>Thanks to Rickard Oberg for the idea of binding an ObjectFactory at "comp".
|
||||
*
|
||||
* <p><h4>Usage</h4>
|
||||
* <pre>
|
||||
*/
|
||||
/*
|
||||
* </pre>
|
||||
*
|
||||
* @see
|
||||
*
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
public class javaRootURLContext implements Context
|
||||
{
|
||||
public static final String URL_PREFIX = "java:";
|
||||
|
||||
protected Hashtable _env;
|
||||
|
||||
protected static NamingContext _nameRoot;
|
||||
|
||||
protected static NameParser _javaNameParser;
|
||||
|
||||
|
||||
static
|
||||
{
|
||||
try
|
||||
{
|
||||
_javaNameParser = new javaNameParser();
|
||||
_nameRoot = new NamingContext();
|
||||
_nameRoot.setNameParser(_javaNameParser);
|
||||
|
||||
StringRefAddr parserAddr = new StringRefAddr("parser", _javaNameParser.getClass().getName());
|
||||
|
||||
Reference ref = new Reference ("javax.naming.Context",
|
||||
parserAddr,
|
||||
ContextFactory.class.getName(),
|
||||
(String)null);
|
||||
|
||||
//bind special object factory at comp
|
||||
_nameRoot.bind ("comp", ref);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Log.warn(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*------------------------------------------------*/
|
||||
/**
|
||||
* Creates a new <code>javaRootURLContext</code> instance.
|
||||
*
|
||||
* @param env a <code>Hashtable</code> value
|
||||
*/
|
||||
public javaRootURLContext(Hashtable env)
|
||||
{
|
||||
_env = env;
|
||||
}
|
||||
|
||||
|
||||
public Object lookup(Name name)
|
||||
throws NamingException
|
||||
{
|
||||
return getRoot().lookup(stripProtocol(name));
|
||||
}
|
||||
|
||||
|
||||
public Object lookup(String name)
|
||||
throws NamingException
|
||||
{
|
||||
return getRoot().lookup(stripProtocol(name));
|
||||
}
|
||||
|
||||
public void bind(Name name, Object obj)
|
||||
throws NamingException
|
||||
{
|
||||
getRoot().bind(stripProtocol(name), obj);
|
||||
}
|
||||
|
||||
public void bind(String name, Object obj)
|
||||
throws NamingException
|
||||
{
|
||||
getRoot().bind(stripProtocol(name), obj);
|
||||
}
|
||||
|
||||
public void unbind (String name)
|
||||
throws NamingException
|
||||
{
|
||||
getRoot().unbind(stripProtocol(name));
|
||||
}
|
||||
|
||||
public void unbind (Name name)
|
||||
throws NamingException
|
||||
{
|
||||
getRoot().unbind(stripProtocol(name));
|
||||
}
|
||||
|
||||
public void rename (String oldStr, String newStr)
|
||||
throws NamingException
|
||||
{
|
||||
getRoot().rename (stripProtocol(oldStr), stripProtocol(newStr));
|
||||
}
|
||||
|
||||
public void rename (Name oldName, Name newName)
|
||||
throws NamingException
|
||||
{
|
||||
getRoot().rename (stripProtocol(oldName), stripProtocol(newName));
|
||||
}
|
||||
|
||||
public void rebind (Name name, Object obj)
|
||||
throws NamingException
|
||||
{
|
||||
getRoot().rebind(stripProtocol(name), obj);
|
||||
}
|
||||
|
||||
public void rebind (String name, Object obj)
|
||||
throws NamingException
|
||||
{
|
||||
getRoot().rebind(stripProtocol(name), obj);
|
||||
}
|
||||
|
||||
|
||||
public Object lookupLink (Name name)
|
||||
throws NamingException
|
||||
{
|
||||
return getRoot().lookupLink(stripProtocol(name));
|
||||
}
|
||||
|
||||
public Object lookupLink (String name)
|
||||
throws NamingException
|
||||
{
|
||||
return getRoot().lookupLink(stripProtocol(name));
|
||||
}
|
||||
|
||||
|
||||
public Context createSubcontext (Name name)
|
||||
throws NamingException
|
||||
{
|
||||
return getRoot().createSubcontext(stripProtocol(name));
|
||||
}
|
||||
|
||||
public Context createSubcontext (String name)
|
||||
throws NamingException
|
||||
{
|
||||
return getRoot().createSubcontext(stripProtocol(name));
|
||||
}
|
||||
|
||||
|
||||
public void destroySubcontext (Name name)
|
||||
throws NamingException
|
||||
{
|
||||
getRoot().destroySubcontext(stripProtocol(name));
|
||||
}
|
||||
|
||||
public void destroySubcontext (String name)
|
||||
throws NamingException
|
||||
{
|
||||
getRoot().destroySubcontext(stripProtocol(name));
|
||||
}
|
||||
|
||||
|
||||
public NamingEnumeration list(Name name)
|
||||
throws NamingException
|
||||
{
|
||||
return getRoot().list(stripProtocol(name));
|
||||
}
|
||||
|
||||
|
||||
public NamingEnumeration list(String name)
|
||||
throws NamingException
|
||||
{
|
||||
return getRoot().list(stripProtocol(name));
|
||||
}
|
||||
|
||||
public NamingEnumeration listBindings(Name name)
|
||||
throws NamingException
|
||||
{
|
||||
return getRoot().listBindings(stripProtocol(name));
|
||||
}
|
||||
|
||||
public NamingEnumeration listBindings(String name)
|
||||
throws NamingException
|
||||
{
|
||||
return getRoot().listBindings(stripProtocol(name));
|
||||
}
|
||||
|
||||
|
||||
public Name composeName (Name name,
|
||||
Name prefix)
|
||||
throws NamingException
|
||||
{
|
||||
return getRoot().composeName(name, prefix);
|
||||
}
|
||||
|
||||
public String composeName (String name,
|
||||
String prefix)
|
||||
throws NamingException
|
||||
{
|
||||
return getRoot().composeName(name, prefix);
|
||||
}
|
||||
|
||||
|
||||
public void close ()
|
||||
throws NamingException
|
||||
{
|
||||
}
|
||||
|
||||
public String getNameInNamespace ()
|
||||
throws NamingException
|
||||
{
|
||||
return URL_PREFIX;
|
||||
}
|
||||
|
||||
public NameParser getNameParser (Name name)
|
||||
throws NamingException
|
||||
{
|
||||
return _javaNameParser;
|
||||
}
|
||||
|
||||
public NameParser getNameParser (String name)
|
||||
throws NamingException
|
||||
{
|
||||
return _javaNameParser;
|
||||
}
|
||||
|
||||
|
||||
public Object addToEnvironment(String propName,
|
||||
Object propVal)
|
||||
throws NamingException
|
||||
{
|
||||
return _env.put (propName,propVal);
|
||||
}
|
||||
|
||||
public Object removeFromEnvironment(String propName)
|
||||
throws NamingException
|
||||
{
|
||||
return _env.remove (propName);
|
||||
}
|
||||
|
||||
public Hashtable getEnvironment ()
|
||||
{
|
||||
return _env;
|
||||
}
|
||||
|
||||
|
||||
protected NamingContext getRoot ()
|
||||
{
|
||||
return _nameRoot;
|
||||
}
|
||||
|
||||
|
||||
protected Name stripProtocol (Name name)
|
||||
throws NamingException
|
||||
{
|
||||
if ((name != null) && (name.size() > 0))
|
||||
{
|
||||
String head = name.get(0);
|
||||
|
||||
if(Log.isDebugEnabled())Log.debug("Head element of name is: "+head);
|
||||
|
||||
if (head.startsWith(URL_PREFIX))
|
||||
{
|
||||
head = head.substring (URL_PREFIX.length());
|
||||
name.remove(0);
|
||||
if (head.length() > 0)
|
||||
name.add(0, head);
|
||||
|
||||
if(Log.isDebugEnabled())Log.debug("name modified to "+name.toString());
|
||||
}
|
||||
}
|
||||
|
||||
return name;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected String stripProtocol (String name)
|
||||
{
|
||||
String newName = name;
|
||||
|
||||
if ((name != null) && (!name.equals("")))
|
||||
{
|
||||
if (name.startsWith(URL_PREFIX))
|
||||
newName = name.substring(URL_PREFIX.length());
|
||||
}
|
||||
|
||||
return newName;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,103 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.jndi.java;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
||||
|
||||
/** javaURLContextFactory
|
||||
* <p>This is the URL context factory for the java: URL.
|
||||
*
|
||||
* <p><h4>Notes</h4>
|
||||
* <p>
|
||||
*
|
||||
* <p><h4>Usage</h4>
|
||||
* <pre>
|
||||
*/
|
||||
/*
|
||||
* </pre>
|
||||
*
|
||||
* @see
|
||||
*
|
||||
*
|
||||
* @version 1.0
|
||||
*/
|
||||
public class javaURLContextFactory implements ObjectFactory
|
||||
{
|
||||
|
||||
/**
|
||||
* Either return a new context or the resolution of a url.
|
||||
*
|
||||
* @param url an <code>Object</code> value
|
||||
* @param name a <code>Name</code> value
|
||||
* @param ctx a <code>Context</code> value
|
||||
* @param env a <code>Hashtable</code> value
|
||||
* @return a new context or the resolved object for the url
|
||||
* @exception Exception if an error occurs
|
||||
*/
|
||||
public Object getObjectInstance(Object url, Name name, Context ctx, Hashtable env)
|
||||
throws Exception
|
||||
{
|
||||
// null object means return a root context for doing resolutions
|
||||
if (url == null)
|
||||
{
|
||||
if(Log.isDebugEnabled())Log.debug(">>> new root context requested ");
|
||||
return new javaRootURLContext(env);
|
||||
}
|
||||
|
||||
// return the resolution of the url
|
||||
if (url instanceof String)
|
||||
{
|
||||
if(Log.isDebugEnabled())Log.debug(">>> resolution of url "+url+" requested");
|
||||
Context rootctx = new javaRootURLContext (env);
|
||||
return rootctx.lookup ((String)url);
|
||||
}
|
||||
|
||||
// return the resolution of at least one of the urls
|
||||
if (url instanceof String[])
|
||||
{
|
||||
if(Log.isDebugEnabled())Log.debug(">>> resolution of array of urls requested");
|
||||
String[] urls = (String[])url;
|
||||
Context rootctx = new javaRootURLContext (env);
|
||||
Object object = null;
|
||||
NamingException e = null;
|
||||
for (int i=0;(i< urls.length) && (object == null); i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
object = rootctx.lookup (urls[i]);
|
||||
}
|
||||
catch (NamingException x)
|
||||
{
|
||||
e = x;
|
||||
}
|
||||
}
|
||||
|
||||
if (object == null)
|
||||
throw e;
|
||||
else
|
||||
return object;
|
||||
}
|
||||
|
||||
if(Log.isDebugEnabled())Log.debug(">>> No idea what to do, so return a new root context anyway");
|
||||
return new javaRootURLContext (env);
|
||||
}
|
||||
};
|
|
@ -1,435 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2000-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.jndi.local;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.naming.CompoundName;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameParser;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
|
||||
import org.eclipse.jetty.jndi.NamingContext;
|
||||
|
||||
/**
|
||||
*
|
||||
* localContext
|
||||
*
|
||||
*
|
||||
* @version $Revision: 4780 $ $Date: 2009-03-17 16:36:08 +0100 (Tue, 17 Mar 2009) $
|
||||
*
|
||||
*/
|
||||
public class localContextRoot implements Context
|
||||
{
|
||||
private static final NamingContext _root;
|
||||
|
||||
private final Hashtable _env;
|
||||
|
||||
// make a root for the static namespace local:
|
||||
static
|
||||
{
|
||||
_root = new NamingContext();
|
||||
_root.setNameParser(new LocalNameParser());
|
||||
}
|
||||
|
||||
static class LocalNameParser implements NameParser
|
||||
{
|
||||
Properties syntax = new Properties();
|
||||
|
||||
LocalNameParser()
|
||||
{
|
||||
syntax.put("jndi.syntax.direction", "left_to_right");
|
||||
syntax.put("jndi.syntax.separator", "/");
|
||||
syntax.put("jndi.syntax.ignorecase", "false");
|
||||
}
|
||||
|
||||
public Name parse(String name) throws NamingException
|
||||
{
|
||||
return new CompoundName(name, syntax);
|
||||
}
|
||||
}
|
||||
|
||||
public localContextRoot(Hashtable env)
|
||||
{
|
||||
_env = new Hashtable(env);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#close()
|
||||
*/
|
||||
public void close() throws NamingException
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#getNameInNamespace()
|
||||
*/
|
||||
public String getNameInNamespace() throws NamingException
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#destroySubcontext(java.lang.String)
|
||||
*/
|
||||
public void destroySubcontext(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
_root.destroySubcontext(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#unbind(java.lang.String)
|
||||
*/
|
||||
public void unbind(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
_root.unbind(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#getEnvironment()
|
||||
*/
|
||||
public Hashtable getEnvironment() throws NamingException
|
||||
{
|
||||
return _env;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#destroySubcontext(javax.naming.Name)
|
||||
*/
|
||||
public void destroySubcontext(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
_root.destroySubcontext(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#unbind(javax.naming.Name)
|
||||
*/
|
||||
public void unbind(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
_root.unbind(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#lookup(java.lang.String)
|
||||
*/
|
||||
public Object lookup(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
return _root.lookup(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#lookupLink(java.lang.String)
|
||||
*/
|
||||
public Object lookupLink(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
return _root.lookupLink(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#removeFromEnvironment(java.lang.String)
|
||||
*/
|
||||
public Object removeFromEnvironment(String propName) throws NamingException
|
||||
{
|
||||
return _env.remove(propName);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#bind(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public void bind(String name, Object obj) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
_root.bind(getSuffix(name), obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#rebind(java.lang.String, java.lang.Object)
|
||||
*/
|
||||
public void rebind(String name, Object obj) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
_root.rebind(getSuffix(name), obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#lookup(javax.naming.Name)
|
||||
*/
|
||||
public Object lookup(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
return _root.lookup(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#lookupLink(javax.naming.Name)
|
||||
*/
|
||||
public Object lookupLink(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
return _root.lookupLink(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#bind(javax.naming.Name, java.lang.Object)
|
||||
*/
|
||||
public void bind(Name name, Object obj) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
_root.bind(getSuffix(name), obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#rebind(javax.naming.Name, java.lang.Object)
|
||||
*/
|
||||
public void rebind(Name name, Object obj) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
_root.rebind(getSuffix(name), obj);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#rename(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public void rename(String oldName, String newName) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
_root.rename(getSuffix(oldName), getSuffix(newName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#createSubcontext(java.lang.String)
|
||||
*/
|
||||
public Context createSubcontext(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
return _root.createSubcontext(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#createSubcontext(javax.naming.Name)
|
||||
*/
|
||||
public Context createSubcontext(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
return _root.createSubcontext(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#rename(javax.naming.Name, javax.naming.Name)
|
||||
*/
|
||||
public void rename(Name oldName, Name newName) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
_root.rename(getSuffix(oldName), getSuffix(newName));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#getNameParser(java.lang.String)
|
||||
*/
|
||||
public NameParser getNameParser(String name) throws NamingException
|
||||
{
|
||||
return _root.getNameParser(name);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#getNameParser(javax.naming.Name)
|
||||
*/
|
||||
public NameParser getNameParser(Name name) throws NamingException
|
||||
{
|
||||
return _root.getNameParser(name);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#list(java.lang.String)
|
||||
*/
|
||||
public NamingEnumeration list(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
return _root.list(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#listBindings(java.lang.String)
|
||||
*/
|
||||
public NamingEnumeration listBindings(String name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
return _root.listBindings(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#list(javax.naming.Name)
|
||||
*/
|
||||
public NamingEnumeration list(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
return _root.list(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#listBindings(javax.naming.Name)
|
||||
*/
|
||||
public NamingEnumeration listBindings(Name name) throws NamingException
|
||||
{
|
||||
synchronized (_root)
|
||||
{
|
||||
return _root.listBindings(getSuffix(name));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#addToEnvironment(java.lang.String,
|
||||
* java.lang.Object)
|
||||
*/
|
||||
public Object addToEnvironment(String propName, Object propVal)
|
||||
throws NamingException
|
||||
{
|
||||
return _env.put(propName, propVal);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#composeName(java.lang.String, java.lang.String)
|
||||
*/
|
||||
public String composeName(String name, String prefix)
|
||||
throws NamingException
|
||||
{
|
||||
return _root.composeName(name, prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @see javax.naming.Context#composeName(javax.naming.Name,
|
||||
* javax.naming.Name)
|
||||
*/
|
||||
public Name composeName(Name name, Name prefix) throws NamingException
|
||||
{
|
||||
return _root.composeName(name, prefix);
|
||||
}
|
||||
|
||||
protected String getSuffix(String url) throws NamingException
|
||||
{
|
||||
return url;
|
||||
}
|
||||
|
||||
protected Name getSuffix(Name name) throws NamingException
|
||||
{
|
||||
return name;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
java.naming.factory.url.pkgs=org.eclipse.jetty.jndi
|
||||
java.naming.factory.initial=org.eclipse.jetty.jndi.InitialContextFactory
|
|
@ -1,72 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.jndi.factories;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Session;
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.LinkRef;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameParser;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.jetty.jndi.NamingUtil;
|
||||
|
||||
/**
|
||||
* TestMailSessionReference
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class TestMailSessionReference extends TestCase
|
||||
{
|
||||
public void testMailSessionReference ()
|
||||
throws Exception
|
||||
{
|
||||
InitialContext icontext = new InitialContext();
|
||||
MailSessionReference sref = new MailSessionReference();
|
||||
sref.setUser("janb");
|
||||
sref.setPassword("OBF:1xmk1w261z0f1w1c1xmq");
|
||||
Properties props = new Properties ();
|
||||
props.put("mail.smtp.host", "xxx");
|
||||
props.put("mail.debug", "true");
|
||||
sref.setProperties(props);
|
||||
NamingUtil.bind(icontext, "mail/Session", sref);
|
||||
Object x = icontext.lookup("mail/Session");
|
||||
assertNotNull(x);
|
||||
assertTrue(x instanceof javax.mail.Session);
|
||||
javax.mail.Session session = (javax.mail.Session)x;
|
||||
Properties sessionProps = session.getProperties();
|
||||
assertEquals(props, sessionProps);
|
||||
assertTrue (session.getDebug());
|
||||
|
||||
Context foo = icontext.createSubcontext("foo");
|
||||
NameParser parser = icontext.getNameParser("");
|
||||
Name objectNameInNamespace = parser.parse(icontext.getNameInNamespace());
|
||||
objectNameInNamespace.addAll(parser.parse("mail/Session"));
|
||||
|
||||
NamingUtil.bind(foo, "mail/Session", new LinkRef(objectNameInNamespace.toString()));
|
||||
|
||||
Object o = foo.lookup("mail/Session");
|
||||
assertNotNull(o);
|
||||
Session fooSession = (Session)o;
|
||||
assertEquals(props, fooSession.getProperties());
|
||||
assertTrue(fooSession.getDebug());
|
||||
|
||||
icontext.destroySubcontext("mail");
|
||||
icontext.destroySubcontext("foo");
|
||||
}
|
||||
}
|
|
@ -1,295 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 1999-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
|
||||
package org.eclipse.jetty.jndi.java;
|
||||
|
||||
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.LinkRef;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameAlreadyBoundException;
|
||||
import javax.naming.NameClassPair;
|
||||
import javax.naming.NameNotFoundException;
|
||||
import javax.naming.NamingEnumeration;
|
||||
import javax.naming.NamingException;
|
||||
import javax.naming.Reference;
|
||||
import javax.naming.StringRefAddr;
|
||||
import javax.naming.spi.ObjectFactory;
|
||||
|
||||
import junit.framework.Test;
|
||||
import junit.framework.TestCase;
|
||||
import junit.framework.TestSuite;
|
||||
|
||||
import org.eclipse.jetty.jndi.NamingContext;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
||||
|
||||
|
||||
public class TestJNDI extends TestCase
|
||||
{
|
||||
|
||||
|
||||
public static class MyObjectFactory implements ObjectFactory
|
||||
{
|
||||
public static String myString = "xxx";
|
||||
|
||||
public Object getObjectInstance(Object obj,
|
||||
Name name,
|
||||
Context nameCtx,
|
||||
Hashtable environment)
|
||||
throws Exception
|
||||
{
|
||||
return myString;
|
||||
}
|
||||
}
|
||||
|
||||
public TestJNDI (String name)
|
||||
{
|
||||
super (name);
|
||||
}
|
||||
|
||||
|
||||
public static Test suite ()
|
||||
{
|
||||
return new TestSuite (TestJNDI.class);
|
||||
}
|
||||
|
||||
public void setUp ()
|
||||
throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public void tearDown ()
|
||||
throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
public void testIt ()
|
||||
throws Exception
|
||||
{
|
||||
try
|
||||
{
|
||||
//set up some classloaders
|
||||
Thread currentThread = Thread.currentThread();
|
||||
ClassLoader currentLoader = currentThread.getContextClassLoader();
|
||||
ClassLoader childLoader1 = new URLClassLoader(new URL[0], currentLoader);
|
||||
ClassLoader childLoader2 = new URLClassLoader(new URL[0], currentLoader);
|
||||
|
||||
//set the current thread's classloader
|
||||
currentThread.setContextClassLoader(childLoader1);
|
||||
|
||||
InitialContext initCtxA = new InitialContext();
|
||||
initCtxA.bind ("blah", "123");
|
||||
assertEquals ("123", initCtxA.lookup("blah"));
|
||||
|
||||
|
||||
|
||||
|
||||
InitialContext initCtx = new InitialContext();
|
||||
Context sub0 = (Context)initCtx.lookup("java:");
|
||||
|
||||
if(Log.isDebugEnabled())Log.debug("------ Looked up java: --------------");
|
||||
|
||||
Name n = sub0.getNameParser("").parse("/red/green/");
|
||||
|
||||
|
||||
if(Log.isDebugEnabled())Log.debug("get(0)="+n.get(0));
|
||||
if(Log.isDebugEnabled())Log.debug("getPrefix(1)="+n.getPrefix(1));
|
||||
n = n.getSuffix(1);
|
||||
if(Log.isDebugEnabled())Log.debug("getSuffix(1)="+n);
|
||||
if(Log.isDebugEnabled())Log.debug("get(0)="+n.get(0));
|
||||
if(Log.isDebugEnabled())Log.debug("getPrefix(1)="+n.getPrefix(1));
|
||||
n = n.getSuffix(1);
|
||||
if(Log.isDebugEnabled())Log.debug("getSuffix(1)="+n);
|
||||
if(Log.isDebugEnabled())Log.debug("get(0)="+n.get(0));
|
||||
if(Log.isDebugEnabled())Log.debug("getPrefix(1)="+n.getPrefix(1));
|
||||
n = n.getSuffix(1);
|
||||
if(Log.isDebugEnabled())Log.debug("getSuffix(1)="+n);
|
||||
|
||||
n = sub0.getNameParser("").parse("pink/purple/");
|
||||
if(Log.isDebugEnabled())Log.debug("get(0)="+n.get(0));
|
||||
if(Log.isDebugEnabled())Log.debug("getPrefix(1)="+n.getPrefix(1));
|
||||
n = n.getSuffix(1);
|
||||
if(Log.isDebugEnabled())Log.debug("getSuffix(1)="+n);
|
||||
if(Log.isDebugEnabled())Log.debug("get(0)="+n.get(0));
|
||||
if(Log.isDebugEnabled())Log.debug("getPrefix(1)="+n.getPrefix(1));
|
||||
|
||||
NamingContext ncontext = (NamingContext)sub0;
|
||||
|
||||
Name nn = ncontext.toCanonicalName(ncontext.getNameParser("").parse("/yellow/blue/"));
|
||||
Log.debug(nn.toString());
|
||||
assertEquals (2, nn.size());
|
||||
|
||||
nn = ncontext.toCanonicalName(ncontext.getNameParser("").parse("/yellow/blue"));
|
||||
Log.debug(nn.toString());
|
||||
assertEquals (2, nn.size());
|
||||
|
||||
nn = ncontext.toCanonicalName(ncontext.getNameParser("").parse("/"));
|
||||
if(Log.isDebugEnabled())Log.debug("/ parses as: "+nn+" with size="+nn.size());
|
||||
Log.debug(nn.toString());
|
||||
assertEquals (1, nn.size());
|
||||
|
||||
nn = ncontext.toCanonicalName(ncontext.getNameParser("").parse(""));
|
||||
Log.debug(nn.toString());
|
||||
assertEquals (0, nn.size());
|
||||
|
||||
Context fee = ncontext.createSubcontext("fee");
|
||||
fee.bind ("fi", "88");
|
||||
assertEquals("88", initCtxA.lookup("java:/fee/fi"));
|
||||
assertEquals("88", initCtxA.lookup("java:/fee/fi/"));
|
||||
assertTrue (initCtxA.lookup("java:/fee/") instanceof javax.naming.Context);
|
||||
|
||||
try
|
||||
{
|
||||
Context sub1 = sub0.createSubcontext ("comp");
|
||||
fail("Comp should already be bound");
|
||||
}
|
||||
catch (NameAlreadyBoundException e)
|
||||
{
|
||||
//expected exception
|
||||
}
|
||||
|
||||
|
||||
|
||||
//check bindings at comp
|
||||
Context sub1 = (Context)initCtx.lookup("java:comp");
|
||||
|
||||
Context sub2 = sub1.createSubcontext ("env");
|
||||
|
||||
initCtx.bind ("java:comp/env/rubbish", "abc");
|
||||
assertEquals ("abc", (String)initCtx.lookup("java:comp/env/rubbish"));
|
||||
|
||||
|
||||
|
||||
//check binding LinkRefs
|
||||
LinkRef link = new LinkRef ("java:comp/env/rubbish");
|
||||
initCtx.bind ("java:comp/env/poubelle", link);
|
||||
assertEquals ("abc", (String)initCtx.lookup("java:comp/env/poubelle"));
|
||||
|
||||
//check binding References
|
||||
StringRefAddr addr = new StringRefAddr("blah", "myReferenceable");
|
||||
Reference ref = new Reference (java.lang.String.class.getName(),
|
||||
addr,
|
||||
MyObjectFactory.class.getName(),
|
||||
(String)null);
|
||||
|
||||
initCtx.bind ("java:comp/env/quatsch", ref);
|
||||
assertEquals (MyObjectFactory.myString, (String)initCtx.lookup("java:comp/env/quatsch"));
|
||||
|
||||
//test binding something at java:
|
||||
Context sub3 = initCtx.createSubcontext("java:zero");
|
||||
initCtx.bind ("java:zero/one", "ONE");
|
||||
assertEquals ("ONE", initCtx.lookup("java:zero/one"));
|
||||
|
||||
|
||||
|
||||
|
||||
//change the current thread's classloader to check distinct naming
|
||||
currentThread.setContextClassLoader(childLoader2);
|
||||
|
||||
Context otherSub1 = (Context)initCtx.lookup("java:comp");
|
||||
assertTrue (!(sub1 == otherSub1));
|
||||
try
|
||||
{
|
||||
initCtx.lookup("java:comp/env/rubbish");
|
||||
}
|
||||
catch (NameNotFoundException e)
|
||||
{
|
||||
//expected
|
||||
}
|
||||
|
||||
|
||||
//put the thread's classloader back
|
||||
currentThread.setContextClassLoader(childLoader1);
|
||||
|
||||
//test rebind with existing binding
|
||||
initCtx.rebind("java:comp/env/rubbish", "xyz");
|
||||
assertEquals ("xyz", initCtx.lookup("java:comp/env/rubbish"));
|
||||
|
||||
//test rebind with no existing binding
|
||||
initCtx.rebind ("java:comp/env/mullheim", "hij");
|
||||
assertEquals ("hij", initCtx.lookup("java:comp/env/mullheim"));
|
||||
|
||||
//test that the other bindings are already there
|
||||
assertEquals ("xyz", (String)initCtx.lookup("java:comp/env/poubelle"));
|
||||
|
||||
//test java:/comp/env/stuff
|
||||
assertEquals ("xyz", (String)initCtx.lookup("java:/comp/env/poubelle/"));
|
||||
|
||||
//test list Names
|
||||
NamingEnumeration nenum = initCtx.list ("java:comp/env");
|
||||
HashMap results = new HashMap();
|
||||
while (nenum.hasMore())
|
||||
{
|
||||
NameClassPair ncp = (NameClassPair)nenum.next();
|
||||
results.put (ncp.getName(), ncp.getClassName());
|
||||
}
|
||||
|
||||
assertEquals (4, results.size());
|
||||
|
||||
assertEquals ("java.lang.String", (String)results.get("rubbish"));
|
||||
assertEquals ("javax.naming.LinkRef", (String)results.get("poubelle"));
|
||||
assertEquals ("java.lang.String", (String)results.get("mullheim"));
|
||||
assertEquals ("javax.naming.Reference", (String)results.get("quatsch"));
|
||||
|
||||
//test list Bindings
|
||||
NamingEnumeration benum = initCtx.list("java:comp/env");
|
||||
assertEquals (4, results.size());
|
||||
|
||||
//test NameInNamespace
|
||||
assertEquals ("comp/env", sub2.getNameInNamespace());
|
||||
|
||||
//test close does nothing
|
||||
Context closeCtx = (Context)initCtx.lookup("java:comp/env");
|
||||
closeCtx.close();
|
||||
|
||||
|
||||
//test what happens when you close an initial context
|
||||
InitialContext closeInit = new InitialContext();
|
||||
closeInit.close();
|
||||
|
||||
|
||||
|
||||
//check locking the context
|
||||
Context ectx = (Context)initCtx.lookup("java:comp");
|
||||
ectx.bind("crud", "xxx");
|
||||
ectx.addToEnvironment("org.eclipse.jndi.immutable", "TRUE");
|
||||
assertEquals ("xxx", (String)initCtx.lookup("java:comp/crud"));
|
||||
try
|
||||
{
|
||||
ectx.bind("crud2", "xxx2");
|
||||
}
|
||||
catch (NamingException ne)
|
||||
{
|
||||
//expected failure to modify immutable context
|
||||
}
|
||||
|
||||
//test what happens when you close an initial context that was used
|
||||
initCtx.close();
|
||||
}
|
||||
finally
|
||||
{
|
||||
InitialContext ic = new InitialContext();
|
||||
Context comp = (Context)ic.lookup("java:comp");
|
||||
comp.destroySubcontext("env");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,88 +0,0 @@
|
|||
// ========================================================================
|
||||
// Copyright (c) 2008-2009 Mort Bay Consulting Pty. Ltd.
|
||||
// ------------------------------------------------------------------------
|
||||
// All rights reserved. This program and the accompanying materials
|
||||
// are made available under the terms of the Eclipse Public License v1.0
|
||||
// and Apache License v2.0 which accompanies this distribution.
|
||||
// The Eclipse Public License is available at
|
||||
// http://www.eclipse.org/legal/epl-v10.html
|
||||
// The Apache License v2.0 is available at
|
||||
// http://www.opensource.org/licenses/apache2.0.php
|
||||
// You may elect to redistribute this code under either of these licenses.
|
||||
// ========================================================================
|
||||
package org.eclipse.jetty.jndi.java;
|
||||
|
||||
import javax.naming.Context;
|
||||
import javax.naming.InitialContext;
|
||||
import javax.naming.Name;
|
||||
import javax.naming.NameNotFoundException;
|
||||
import javax.naming.NameParser;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
import org.eclipse.jetty.jndi.NamingUtil;
|
||||
|
||||
|
||||
public class TestLocalJNDI extends TestCase
|
||||
{
|
||||
|
||||
|
||||
public void setUp ()
|
||||
throws Exception
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public void tearDown ()
|
||||
throws Exception
|
||||
{
|
||||
InitialContext ic = new InitialContext();
|
||||
ic.destroySubcontext("a");
|
||||
}
|
||||
|
||||
|
||||
public void testLocal ()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
InitialContext ic = new InitialContext();
|
||||
NameParser parser = ic.getNameParser("");
|
||||
ic.bind("foo", "xxx");
|
||||
|
||||
Object o = ic.lookup("foo");
|
||||
assertNotNull(o);
|
||||
assertEquals("xxx", (String)o);
|
||||
|
||||
ic.unbind("foo");
|
||||
try
|
||||
{
|
||||
ic.lookup("foo");
|
||||
fail("Foo exists");
|
||||
}
|
||||
catch (NameNotFoundException e)
|
||||
{
|
||||
//expected
|
||||
}
|
||||
Name name = parser.parse("a");
|
||||
name.addAll(parser.parse("b/c/d"));
|
||||
NamingUtil.bind(ic, name.toString(), "333");
|
||||
assertNotNull(ic.lookup("a"));
|
||||
assertNotNull(ic.lookup("a/b"));
|
||||
assertNotNull(ic.lookup("a/b/c"));
|
||||
Context c = (Context)ic.lookup("a/b/c");
|
||||
o = c.lookup("d");
|
||||
assertNotNull(o);
|
||||
assertEquals("333", (String)o);
|
||||
assertEquals("333", ic.lookup(name));
|
||||
ic.destroySubcontext("a");
|
||||
|
||||
name = parser.parse("");
|
||||
name.add("x");
|
||||
Name suffix = parser.parse("y/z");
|
||||
name.addAll(suffix);
|
||||
NamingUtil.bind(ic, name.toString(), "555");
|
||||
assertEquals("555", ic.lookup(name));
|
||||
ic.destroySubcontext("x");
|
||||
}
|
||||
|
||||
}
|
2
pom.xml
2
pom.xml
|
@ -23,7 +23,6 @@
|
|||
<slf4j-version>1.5.6</slf4j-version>
|
||||
<eclipse-compiler-version>3.1.1</eclipse-compiler-version>
|
||||
<cometd-version>1.0.beta4</cometd-version>
|
||||
<jna-version>3.2.2</jna-version>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
</properties>
|
||||
<scm>
|
||||
|
@ -143,7 +142,6 @@
|
|||
<module>jetty-rewrite</module>
|
||||
<module>jetty-policy</module>
|
||||
<module>jetty-start</module>
|
||||
<module>jetty-setuid</module>
|
||||
<module>test-continuation</module>
|
||||
<module>test-continuation-jetty6</module>
|
||||
<module>test-jetty-servlet</module>
|
||||
|
|
Loading…
Reference in New Issue