Beruflich Dokumente
Kultur Dokumente
jGuru
Generated Sep 13, 2005 1:47:06 PM
Location: http://www.jguru.com/faq/JNDI
Ownership: http://www.jguru.com/misc/user-agree.jsp#ownership.
Does JMS require the Java Naming and Directory Interface (JNDI)?
Location: http://www.jguru.com/faq/view.jsp?EID=778
Created: Nov 10, 1999 Modified: 1999-11-10 16:23:38.421
Author: Jerry Smith (http://www.jguru.com/guru/viewbio.jsp?EID=9)
No, but... JNDI provides network-oriented look-up services for distributed objects
(among other things). It's possible to implement, as well as use, JMS software
without JNDI. In general, however, JNDI provides critical services for JMS-based
software because it's important to be able to locate (programmatically) JMS services
implemented in objects called factories.
For example, applications that communicate via JMS must set up communication
pathways that involve destinations (topic areas and queues), connections, sessions,
and so on. JNDI makes it easy for an application to locate, for example, a connection
factory for the appropriate vendor's JMS middleware, which can then provide a
connection, which can provide a session, and so on, all relative to the JMS server
that's associated with that connection factory.
What is JNDI?
Location: http://www.jguru.com/faq/view.jsp?EID=10852
Created: Feb 2, 2000 Modified: 2000-02-02 05:25:14.381
Author: Richard Monson-Haefel (http://www.jguru.com/guru/viewbio.jsp?EID=16)
JNDI is similar to JDBC in that they are both Object-Oriented Java APIs that provide
a common abstraction for accessing services from different vendors. While JDBC can
be used to access a variety of relational databases, JNDI can be used to access a
variety of of naming and directory services. Using one API to access many different
brands of a service is possible because both JDBC and JNDI subscribe to the same
architectural tenet: Define a common abstraction that most vendors can implement.
The common abstraction is the API. It provides an objectified view of a service while
hiding the details specific to any brand of service. The implementation is provided by
the vendor, it plugs into the API and implements code specific to accessing that
vendor's product.
JNDI provides two APIs and one SPI. JNDI has a naming API that allows Java
applications to access naming systems like CORBA's Naming services and a directory
API that extends the naming service to provide access to directory services like
LDAP. JNDI also has a SPI (Service-Provider Interface) which is a programming
model that vendors use to write JNDI plug-ins or implementations for their specific
product. Each vendor's plug-in is called a service-provider. A service-provider
implements the JNDI APIs so that a Java application can access that vendor's
product. For the most part, JNDI hides the implementation details of the a service-
provider so that Java developer that uses JNDI can use the same objects and method
regardless of the brand of naming or directory service accessed. This is the real
power behind APIs like JDBC and JNDI: They provide one programming model for
accessing many different products; there is no need to learn a different programming
model every time a different product is used.
its good
Author: srinivas kumar (http://www.jguru.com/guru/viewbio.jsp?EID=1100681), Jul
10, 2003
this page is highly informative and can be easily understood
Sun manages the JNDI-INTEREST mailing list. A searchable archive of this list can be
found at http://archives.java.sun.com/archives/jndi-interest.html. There is also a link
on that page which lets you join or leave the mailing list.
There are no books at this time that cover JNDI exclusively. There are, however, two
books that include some coverage of JNDI as well as other Enterprise Java subjects
-- they are listed below.
A prefect example of a naming service is the Domain Name System (DNS) used by
everyone on the World Wide Web. Internet Protocol (IP) addresses are made up of a
series of digits separated by "dots" ('.'). The address of jGuru.com, for example, is
216.217.9.172. IP address are great for routing messages among the millions of
computers on the Internet, but its not very user friendly. The DNS associates names
with these IP addresses so that it's easier for humans to remember addresses of
their favorite sites and access them on the Internet.
The rules that govern association of names with IP addresses are called the Domain
Naming System. The Berkley Internet Name Domain (BIND) server, which is a type
of server used to resolve names into IP addresses using DNS, is an example of a of a
naming service.
Naming services are common place in computing. The OS file system on a computer
is a type of naming service that associates the addresses of data blocks on a disk
drive with file and directory names. Network file systems are also naming services
and some, like NIS+ and Novell Netware are an advanced naming service called a
directory service.
RFC 2255 defines the basic structure of the LDAP URL. Its basic definition is:
"ldap://" [host [":" port] ] ["/" [dn
["?" [attributeList] ["?" [scope]
["?" [filterString] ["?" extensions]]]]]
A directory service has entries that are similar to the UNIX file structure. For e.g., in
Unix we have
/etc
/bin
/usr/bin
/usr/local
Where:
o is Organization
ou is the Organizational Unit
cn is the Common Name
Both of these entries relate to same person (John Zukowski), but in different sub-
trees (ou). One entry might have different permissions, rights, etc. when compared
to the other. So the only way we can distinguish these two entries is by using their
Distinguished names.
JNDI has classes provided by Sun that will help your application interact with an
LDAP server. JNDI applications work similarly to JDBC applications....Write an
application once and be free to use "drivers" from different vendors. Sun provides
the "driver" that will help interact with the LDAP server. Sun also provides "drivers"
for other naming services(like CORBA, Netscape)
What Sun has not written is a driver to interact with ADSI(win 2000)
Java/ADSI?
Author: David Pratt (http://www.jguru.com/guru/viewbio.jsp?EID=453513), Jul 11,
2001
Are there any solutions for connecting to Active Directory via Java?
It depends. Check out JNDI 1.2 Compatibility with JNDI 1.1 page.
Where is the official documentation for JNDI?
Location: http://www.jguru.com/faq/view.jsp?EID=25310
Created: Mar 16, 2000 Modified: 2000-03-17 00:00:20.539
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4)
And then take a look in the 'examples' diretory of the JNDI download.
Yes, check out The JNDI Tutorial online and/or buy a copy of it here.
Check out The JNDI Tutorial. It's also available on the web.
For other books that are relevant to JNDI, check out Are ther any books that provide
decent JNDI coverage?.
First of all, you have to create a javax.mail.Session like you would in accessing other
resources such as JDBC connections:
LDAP is the "Lightweight Directory Access Protocol" and is defined by RFC 2251. Very
basically, LDAP is a simpler take on the X.500 directory access protocol.
How can I use a database connection pool within a servlet or JSP page?
Location: http://www.jguru.com/faq/view.jsp?EID=112097
Created: Jul 26, 2000 Modified: 2001-02-13 12:32:02.875
Author: Ken Young (http://www.jguru.com/guru/viewbio.jsp?EID=58585) Question
originally posed by arun suresh
(http://www.jguru.com/guru/viewbio.jsp?EID=110596
If you are using a J2EE Server, you should be able to access a connection pool via
JNDI and retreive the a connection. If you are not using a J2EE Server, you can
download (or write) a connection pool, and install it into your JSP/Servlet application,
and share it via the application space.
Comments and alternative answers
For LDAP providers, you must encode a space character at the beginning or end of
the string, a sharp ("#") character at the beginning of the string, and all of: """, ",",
"\", "+", "<", ">", and ";" by preceding the special character using a backslash ("\").
For a more complete scoop on this, check out Handling Special Characters from the
JNDI API tutorial.
This depends on which EJB container / JNDI implementation that you are using.
Using the Inprise Application Server, it will do this automatically if you are within the
same subnet using the Smart Agent, or you can pass a command-line parameter into
the virtual machine.
You should refer to the documentation for the implementation that you are using for
the exact specifics.
How do I use JNDI to locate the home interface of an EJB running on a different
host?
Author: Sribha Jain (http://www.jguru.com/guru/viewbio.jsp?EID=484436), Aug 27,
2001
How do we do this using J2EE server and where is this property specified?
Re: How do I use JNDI to locate the home interface of an EJB running on a
different host?
Author: James Chiang (http://www.jguru.com/guru/viewbio.jsp?EID=341533),
Aug 29, 2001
Setting the following env. when instantiating InitialContext:
Properties env = new Properties();
env.put("java.naming.factory.initial",
"com.sun.jndi.cosnaming.CNCtxFactory");
env.put("java.naming.provider.url",
"iiop://hostname:1050");
InitialContext jndiCtx = new InitialContext(env);
Re: Re: How do I use JNDI to locate the home interface of an EJB running
on a different host?
Author: Sribha Jain (http://www.jguru.com/guru/viewbio.jsp?EID=484436),
Aug 29, 2001
Thanks, James...but will this work for all application servers...i am using J2EE
server currently. And how do we know whether our iiop port is 1050(as u have
given in code).
Re: Re: How do I use JNDI to locate the home interface of an EJB running
on a different host?
Author: Sribha Jain (http://www.jguru.com/guru/viewbio.jsp?EID=484436), Aug
29, 2001
I tried it out but it gives following error on running the client.
javax.naming.NameNotFoundException. Root exception is
org.omg.CosNaming.NamingC ontextPackage.NotFound at
org.omg.CosNaming.NamingContextPackage.NotFoundHelper.read(Unknown
So urce) at
org.omg.CosNaming.NamingContextPackage.NotFoundHelper.extract(Unknown
Source) at org.omg.CosNaming._NamingContextStub.resolve(Unknown Source)
at com.sun.jndi.cosnaming.CNCtx.callResolve(Unknown Source) at
com.sun.jndi.cosnaming.CNCtx.lookup(Unknown Source) at
com.sun.jndi.cosnaming.CNCtx.lookup(Unknown Source) at
javax.naming.InitialContext.lookup(Unknown Source) at
ConverterClient.main(ConverterClient.java:27)
Re: Re: Re: How do I use JNDI to locate the home interface of an EJB
running on a different host?
Author: James Chiang
(http://www.jguru.com/guru/viewbio.jsp?EID=341533), Aug 29, 2001
It's indeed port 1050 for SUN's j2ee RI server. You can type "j2ee -verbose"
to find the naming service port.
As to solve NotFoundException, just copy j2ee.jar (located at
%J2EE_HOME%\lib) to the client end and set into classpath.
Re: Re: Re: Re: How do I use JNDI to locate the home interface of an
EJB running on a different host?
Author: Sribha Jain
(http://www.jguru.com/guru/viewbio.jsp?EID=484436), Aug 29, 2001
I have already done that, but the problem persists...
Re: Re: Re: Re: Re: How do I use JNDI to locate the home interface
of an EJB running on a different host?
Author: moiroux matthieu
(http://www.jguru.com/guru/viewbio.jsp?EID=540275), Nov 6, 2001
i've just try it and it work tx !
Re[2]: How do I use JNDI to locate the home interface of an EJB running
on a different host?
Author: Vassilis Mokas (http://www.jguru.com/guru/viewbio.jsp?EID=855498),
Apr 26, 2002
Can you please tell me the corresponding code for Borland Application Server
4.5 or 5 ? I just want to locate an EJB in BAS using a servlet in Tomcat.
Re[3]: How do I use JNDI to locate the home interface of an EJB running
on a different host?
Author: Laurent Mihalkovic
(http://www.jguru.com/guru/viewbio.jsp?EID=407112), Jul 17, 2002
Hi
I was just going through the same discovery process with the Borland
AppServer, and found myself at the same place you must have been a while
ago...
javax.naming.Context context;
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
"com.inprise.j2ee.jndi.CtxFactory");
env.put(javax.naming.Context.URL_PKG_PREFIXES,
"com.inprise.j2ee");
context = new javax.naming.InitialContext(env);
The documentation states that URL_PKG_PREFIXES is necessary to support the
standard java:comp namespace.
Cheers,
laurent
Re[2]: How do I use JNDI to locate the home interface of an EJB running
on a different host?
Author: test sherchan (http://www.jguru.com/guru/viewbio.jsp?EID=962675),
Jul 24, 2002
I am getting the same problem and i am using J2EE server. Can u tell me plz
how to set that env.
Re[3]: How do I use JNDI to locate the home interface of an EJB running on a
different host?
Author: frank xing (http://www.jguru.com/guru/viewbio.jsp?EID=918691), Oct 23, 2002
The way to use JNDI to locate a home interface of an
EJB on remote host differs among different application servers.
As I am using WebLogic6.1, the steps are as follows:
1. at the client side, set the weblogic.jar in your classpath.
2. You have to prepare a Properties object for initialContext, that is:
Properties p = new Properties();
//weblogic's JNDI driver(provider)
p.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory")
And for other application servers, you need to obtain the corresponding JNDI
provider(driver) as step1, set the INITIAL_CONTEXT_FACTORY and PROVIDER_URL as
step2 and then follow step 3, 4, 5.
Re: How do I use JNDI to locate the home interface of an EJB running on
a different host? [JBoss]
Author: Edison Wang
(http://www.jguru.com/guru/viewbio.jsp?EID=1149288), Feb 25, 2004
I was about to post a new thread on the forums when I see this one... I sort of
understood how the looking up to another host is now, but which namespace
should I put in for this line? I'm also not sure whether the IIOP for JBoss is on
port 1050.
env.put("java.naming.factory.initial",
"com.sun.jndi.cosnaming.CNCtxFactory");
The authentication is provided when you create the InitialDirContext. Take a look
at the snippet below...
_env.put(Context.SECURITY_AUTHENTICATION, "simple");
How would I use that in a corporate env were different users are in different levels?
Iow, how would I be able to write a login program capable of being used by any user?
When (manually) deploying an EJB where do you specify the JNDI name
that the bean is bound to in the JNDI tree?
Location: http://www.jguru.com/faq/view.jsp?EID=132923
Created: Aug 23, 2000 Modified: 2000-08-24 18:56:25.582
Author: satyanarayana sairam
(http://www.jguru.com/guru/viewbio.jsp?EID=132906) Question originally posed by
Henrik Buch (http://www.jguru.com/guru/viewbio.jsp?EID=121686
[Questioner continues: According to the EJB1.1 spec there is no relation between the
<ejb-name> tag in the deployment descriptor (or assembly descriptor) and the JNDI
name. I can see that a client can use a "logical" name that can be mapped via
vendor specific deployment info (e.g. orion-application-client.xml).]
When you are deploying the application in using Web Logic 4.5.1 server, in the
deployment wizard you can specify the JNDI name and using the same name you can
look up from the client.
[Is there any standard way to do it? If not, can someone give feedback with info for
other servers? -Alex]
Where can I find the API documentation of the Java Naming and Directory
Interface (JNDI)?
Location: http://www.jguru.com/faq/view.jsp?EID=134137
Created: Aug 24, 2000 Modified: 2000-08-28 19:11:08.331
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4)
To cancel a search, you simply need to close the NamingEnumeration that is returned
from the context.search() method.
You can pick this up with the rest of the Novell Class Libraries for Java from the
Novell Developer Portal.
Are there any complete JNDI service provider (SPI) examples that use
federation?
Location: http://www.jguru.com/faq/view.jsp?EID=223319
Created: Oct 5, 2000 Modified: 2000-10-05 13:32:13.127
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4) Question
originally posed by Shane Jarych
(http://www.jguru.com/guru/viewbio.jsp?EID=130672
Hmm... I don't know if this is "complete" enough for you or not but as part of the
Building a Service Provider section of Sun's JNDI API Tutorial and Reference there is
a lesson which covers Adding Federation Support.
Can I have my JSP container access JSP pages which are not present in a
local file system by doing a JNDI lookup?
Location: http://www.jguru.com/faq/view.jsp?EID=231498
Created: Oct 18, 2000 Modified: 2001-02-13 12:30:53.181
Author: Serge Knystautas (http://www.jguru.com/guru/viewbio.jsp?EID=100012)
Question originally posed by Dmitri Paltchoun
(http://www.jguru.com/guru/viewbio.jsp?EID=41856
There is nothing in the specification that would prevent you from doing this. The
specification defines how requests should get mapped to resources, the syntax and
API for JSPs and servlets, and the internal dispatching of requests within a container.
It does not address where these are stored, whether the servlets come from a
remote class loader or if the JSPs are stored in an LDAP server or other remote
location. In fact, the Tomcat project has toyed with the idea of supporting JSPs that
come from a database.
The problem you will face though is that there are no implementations available yet
that support this. Nonetheless, there are open source projects (such as Tomcat) that
I'm sure would be happy to accept code or a patch that had this functionality where
you to write it.
Check out Sun's JNDI Tutorial's Security chapter, particularly the SSL and Custom
Sockets section.
When using JNDI with LDAP, how can I get the DN (Distinguished Name)
from a DirContext?
Location: http://www.jguru.com/faq/view.jsp?EID=260006
Created: Nov 22, 2000 Modified: 2000-11-30 19:24:03.068
Author: Fdo J. Rendón Quiles (http://www.jguru.com/guru/viewbio.jsp?EID=142691)
Question originally posed by Michael Dalrymple
(http://www.jguru.com/guru/viewbio.jsp?EID=201651
If you get the DN for a DirContext you have to use the method,
getNameInNamespace(). This method retrieves the full name of this context within its
own namespace. For example:
DirContext ctx;
// ...
ctx.getNameInNamespace();
Comments and alternative answers
To get an initial context from an applet, you need to pass the InitialContext
constructor a Hashtable with the Context.APPLET property ("java.naming.applet")
set:
Hashtable hash = new Hashtable()
// this is a reference to the applet
hash.put(Context.APPLET, this);
Context ctx = new InitialContext(hash);
The following JNDI parameters would then be read from the APPLET parameters:
• java.naming.factory.initial
• java.naming.factory.object
• java.naming.factory.state
• java.naming.factory.control
• java.naming.factory.url.pkgs
• java.naming.provider.url
• java.naming.dns.url
as in
<param
name="java.naming.factory.initial"
value="com.sun.jndi.ldap.LdapCtxFactory"
>
To use LDAP within Java (JSP or not), you must use JNDI (Java Naming and
Directory Interface).
A bit like JDBC, JNDI consists of
Thanks.
This assumes the password you want to use is stored in plain text or in digest
format that java can work with. How Tomcat currently works is it grabs the
password from ldap either in plain text or in a digest password, then it
compares the user submited password witht the retrieved password if they
match then it goes and looks to see if what groups (roles) the user is in. This
only works if:
1) The LDAP server is using a common Digest like SHA or MD5
2) The userPassword field isn't write_only, which it is in Microsoft Active
Directory.
Tomcat's JNDIRealm doesn't use a traditional ldap approach of trying to bind to
the directory to validate a user. If you want or need to do it this way it gets
more complicated.
To make all this work you must have JNDI setup and on the classpath
somewhere and the ldap.jar that comes with jndi somewhere on the classpath, if
you really want to use netscape's ldapjdk it gets alot more complicated.
if the above does all work for you then you need to tell tomcat what to protect
per container. So in the: $Tomcat_Home/webapps/app_name/WEB-
INF/web.xml create something like this:
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<security-constraint>
<web-resource-collection>
<web-resource-name>Entire Application</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>PUT_GROUP_NAME_HERE</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>BASIC</auth-method>
<realm-name>My Secure Realm</realm-name>
</login-config>
</web-app>
any changes to theese file requires a restart. LDAP debug information can be
found in:
$Tomcat_home/logs/catalina_log.2002-07-12.txt for what ever day it is.
once the user is authenticated you can get information about the user from the
supplied request object:
request.getUserPrincipal();
request.isUserInRole("some group name");
request.getUserPrincipal().getName();
If you want/need to use the Netscape ldapjdk.jar or you need to bind to the ldap
directory because of a non standard digest format or userPassword is a
write_only then you need do the following.
to make it use the more common bind technique for authentication you need to
rewrite/modify the
protected String getUserDN(DirContext dircontext, String s, String s1) funtion
s = username from browser
s1 = password user typed
Function needs to return users Full DN if authenticated or null if not.
Carl
I suspect that what your JNDI provider is telling you is that it cannot decrypt the
password in order to compare it to the value that you have supplied. I would cease
using the password as a filter.
You can't, unless the password is stored in cleartext in the directory (which would be
a bad idea). The passwords are encrypted using a strong 1-way hash function such
as MD5 or SHA1 (SHA1 being the most common and preferred function).
Are there any JNDI service providers which support Micrsoft's Windows
security/authentication services?
Location: http://www.jguru.com/faq/view.jsp?EID=344902
Created: Mar 5, 2001 Modified: 2001-03-15 15:50:20.522
Author: mark wilcox (http://www.jguru.com/guru/viewbio.jsp?EID=344899)
Question originally posed by John Mitchell PREMIUM
(http://www.jguru.com/guru/viewbio.jsp?EID=4
I too am looking for some code to access AD using jndi. If you have solved this it
would be helpful! Sorry I can't answer. Thanks
Where can I find a JNDI service provider which uses an SQL database as its
backing store?
Location: http://www.jguru.com/faq/view.jsp?EID=344908
Created: Mar 5, 2001 Modified: 2001-03-15 15:47:01.873
Author: mark wilcox (http://www.jguru.com/guru/viewbio.jsp?EID=344899)
Question originally posed by Fredrik Hultkrantz
(http://www.jguru.com/guru/viewbio.jsp?EID=265955
The answer to your question will depend upon what you're trying to do. If you're
looking for a LDAP server with a SQL server, then you should probably check out
Oracle's OID system which is Oracle's LDAP server. Most directory servers don't use
SQL because SQL is ineffecient for LDAP and unecessary. Most people believe you
need an SQL server for transactions to keep things stable. But there are several
flavors of embedded databases like Sleepycat's Berkeley Database (used by IPlanet
among others) which provides for large databases that are extremely quick and still
provide thing like transaction support (IPlanet uses this feature) so your directory
server can recover its databases from a crash.
Next, SQL is a relational model, while JNDI supports a heiararchical model. Perhaps
the better question is there an Object Database that supports JNDI? (And the answer
is not that I know of, but they *could* exist)
If you're looking for a better object support for your Java applications from your
databases, then you you should be looking into an object database or an API that
allows object wrappers around JDBC ops.
As for now there is no sevice provider for NIS+ but there is JNDI sevice provider for
NIS that is -- com.sun.jndi.nis.nisctyfactory.
How can I retrieve the results of a LDAP search in pages and also define
number of entries on each page?
Location: http://www.jguru.com/faq/view.jsp?EID=353054
Created: Mar 16, 2001 Modified: 2001-03-16 10:02:36.425
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4) Question
originally posed by venkat ravula
(http://www.jguru.com/guru/viewbio.jsp?EID=279259
Help
Author: Stefano Balloni (http://www.jguru.com/guru/viewbio.jsp?EID=1112879), Sep
4, 2003
I need a method to extract every deployed ejb because if i try to lookup my ejb i
receive an error. It says that the name of the ejb that i serch for is wrong. I'm sure that
the name is rigth... how can i get all the names of my deployed ejb? List() method
requires a string but i don't know what he want!! Help please!
Where can I learn (more) about sending email in Java and the JavaMail
library?
Location: http://www.jguru.com/faq/view.jsp?EID=431202
Created: May 30, 2001
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4)
Where can I learn (more) about Java's support for transaction processing?
Location: http://www.jguru.com/faq/view.jsp?EID=431948
Created: May 31, 2001
Author: John Mitchell (http://www.jguru.com/guru/viewbio.jsp?EID=4)
First, in the jar file of your applet you will need followin classes included:
1. Classes from the jar with the client portion of your specific jndi provider
classes
2. Classes from the the jar containing javax.naming standard extensions.
3. Classes from the jar containing javax.rmi.PortableRemoteObject (only if the
retrieved object are CORBA objecs)
4. The classes you want to lookup.
Then, the host where the lookup has to be done must be the same from wich your
applet has been downloaded (otherwise the applet must be signed).
The client browser must be able to open a connection to the port of where the
naming service is listening (be sure about proxy settings etc.).
The client browser must have Java 2 (Java Plugin 1.2.x)
Then the code is always the same: