How to Bind EJBs under COS Naming Service

Hi,
I want bind EJBs under COS Naming serices and
how to lookup those EJBs from java clients.
I am using Weblogic 5.1.
thanks,
-Ramesh

Can you give a complete example of this? I'm having the same issue. We
have CORBA clients that we want to redirect to EJB implementations
instead of ORB servers. How do I bind the CORBA objects in CosNaming?
The example provided with WLS seems to cover RMI/IIOP but doesn't cover
CORBA client to EJB.
Thanks,
Andy Piper wrote:
"Ramesh Raju" <[email protected]> writes:
You can only bind CORBA objects in CosNaming, so you would have to
bind RMI-IIOP stubs.
andy
Hi,
I want bind EJBs under COS Naming serices and
how to lookup those EJBs from java clients.
I am using Weblogic 5.1.
thanks,
-Ramesh--

Similar Messages

  • How to Connect to the Visibroker Naming Service using the Servlet

    Hi
    I am facing Problem in finding the Initial JNDI Context.
    It is giving me ClassCastException.
    In our Application the Tomcat is Integrated with One of the Partitions. And the EJB' are registered on Visibroker Naming Service (on the same machine).
    I want to Access one of the EJB's.
    Following is my Client Code in the Servlet.
    ==============================================================================
    public void doPost(HttpServletRequest request, HttpServletResponse res)
    throws IOException, ServletException
    res.setContentType("text/html");
    PrintWriter pw = res.getWriter();
    pw.println("<html>");
    try{
    Enumeration e= super.getInitParameterNames();
    while(e.hasMoreElements())
    String paramName= (String)super.getInitParameterNames().nextElement();
    String paramValue=super.getInitParameter(paramName);
    pw.println("paramName="+paramName);
    Context ic;
    java.util.Properties props = new java.util.Properties();
    props.putContext.INITIAL_CONTEXT_FACTORY, "com.inprise.j2ee.jndi.CtxFactory");
    props.put(Context.URL_PKG_PREFIXES, "com.inprise.j2ee.jndi");
    ic = new InitialContext();
    pw.println("Initial Context"+ ic);
    ========================================================================
    And I am getting following Error while getting the Inital Context.
    ============================
    ERROR - javax.naming.NoInitialContextException: Cannot instantiate class: com.inprise.j2ee.jndi.CtxFactory [Root exception is java.lang.ClassCastException]
    2006-09-30 05:16:27,461 ERROR - at javax.naming.spi.NamingManager.getInitialContext(Unknown Source)
    2006-09-30 05:16:27,461 ERROR - at javax.naming.InitialContext.getDefaultInitCtx(Unknown Source)
    2006-09-30 05:16:27,461 ERROR - at javax.naming.InitialContext.init(Unknown Source)
    2006-09-30 05:16:27,461 ERROR - at javax.naming.InitialContext.<init>(Unknown Source)
    2006-09-30 05:16:27,461 ERROR - at com.lucent.omcran.servlet.OmcRanTpuGuiReDirectServlet.doPost(OmcRanTpuGuiReDirectServlet.java:56)
    2006-09-30 05:16:27,461 ERROR - at com.lucent.omcran.servlet.OmcRanTpuGuiReDirectServlet.doGet(OmcRanTpuGuiReDirectServlet.java:33)
    2006-09-30 05:16:27,461 ERROR - at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
    2006-09-30 05:16:27,461 ERROR - at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
    2006-09-30 05:16:27,461 ERROR - at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:248)
    2006-09-30 05:16:27,461 ERROR -
    ===========================================
    Below are the Parameters that I use to Start my Partition
    =============================================================================
    -Diems.locator.localzonetype=presentation -Diems.arm.context=presentation -XX:+DisableExplicitGC= -XX:+UseCMSInitiatingOccupancyOnly= -DAPPNAME=appl1 -DContextId=1 -DCOMMONPATH=/omcsw/common -DIEMSPATH=/omcsw/28.0.1.22.00 -Djava.util.prefs.PreferencesFactory=com.lucent.iems.platform.util.prefs.spi.IEMSPreferencesFactory -Dcom.lucent.iems.prefs.PrefsDirectory=/omcsw/28.0.1.22.00/data/registry -Dorg.omg.CORBA.ORBClass=com.inprise.vbroker.orb.ORB -Dorg.omg.CORBA.ORBSingletonClass=com.inprise.vbroker.orb.ORBSingleton -Djavax.rmi.CORBA.StubClass=com.inprise.vbroker.rmi.CORBA.StubImpl -Djavax.rmi.CORBA.PortableRemoteObjectClass=com.inprise.vbroker.rmi.CORBA.PortableRemoteObjectImpl -Djavax.rmi.CORBA.UtilClass=com.inprise.vbroker.rmi.CORBA.UtilImpl -Diems.arm.factory=com.lucent.iems.platform.util.arm.impl1.ARMFactoryImpl1 -Dcom.lucent.iems.platform.util.intfc.maxnumofobjects=25 -DGUMDBPOOLNAME=GUMdb -Dvbroker.orb.enableKeyId=false
    ==============================================
    Does Any one have Idea what is going wrong..
    Ankit

    You can check whether any cookies were sent in the request to your servlet:
    Cookie cookies[] = request.getCookies();
    if cookies is not null (cookies != null) then the browser sending you the request suppoerts cookies.
    If it is null then you would need to do a little extra work. Basically add a cookie to the response going back to the browser. Then send a redirect back to this same servlet. You then would have to add code to check to see whether the cookie was sent back.
    // Servlet named myServlet
    String test = request.getParameter("TEST");
    Cookie cookies[] = request.getCookies();
    if (test == null || !test.equals("TRUE")
    if (cookies == null)
    response.addCookie("testCookies","testCookies");
    response.sendRedirect("myServlet?TEST=TRUE");
    else
    // cookies were sent in the initial request, so
    // browser supports cookies
    else
    // This is the redirect. Check the for the presence of
    // our testCookie
    Hope this helps.

  • How corba client and server find Naming service

    hello
    i want to ask how corba client and server find the Naming service ?
    10x

    By using a well-known port (I think the default for JavaIDL's NS is 1049) on a well-known address (localhost).
    As these values are not really standard, you can specify them when starting the server and client (+-ORBInitialPort 1050 -ORBInitialHost localhost+). See the documentation .

  • How to bind list data to XML Web service request

    How do I bind specific columns in a DataGrid to the Web
    service request? I'm having trouble finding any documentation that
    addresses that specific pattern, i.e. sending a complex list to the
    server via a Flex Web service send() command. I'm fairly new to
    Flex programming and don't know if what I want to do is possible.
    Here what I've been able to do so far.
    1. Using a Web service called a service on the server and
    retrieved a complex list.
    2. Poplulated a DataGrid with the result
    3. The user has selected multiple rows from the DataGrid
    using a checkbox column
    4. The user pressed a button that calls a Web service send().
    This Web service should only send data from only two columns and
    only for those rows the user has checked.
    5. I can loop over the DataGrid and find the selected rows
    and put them in another ArrayCollection called 'selectedRows'.
    The issue is that I don't know how to bind 'selectedRows' to
    the Web service. Right now I'm reading up on "Working with XML" in
    the Programming with ActionScript 3.0 chapter. But I'm just fishing
    here. No bites yet.

    Don't bind. Build the request object programatically, as you
    are doing with your selectedRows AC, and send(myObject) that.
    Tracy

  • Cos Naming & WLS Naming Service problem in distributed Tuxedo application

    Hi,
    we have been starting our investigation into using the distributed application feature of Tuxedo (multiple machines running under 1 Tuxedo domain which make up the entire Tuxedo Application).
    when trying to access WLS EJB object references from Tuxedo, we hit a road block.
    we have been using the standard method of searching through Cos Naming for a bind context which refers to WLS Naming Service. (this method is documented online and in dev2dev samples) Under non distributed application setup (1 Tux domain with 1 machine as in all examples), everything works fine and I can see into 1 WLS server's JNDI tree. But when in distributed application setup where we want to have two (for example) machines and we also want two WLS managed server with each running on their own machine, it seems that there are some unexpected problems:
    1. - only one set of GWADM/GWTDOMAIN is running
    - each WLS managed server has its own WTC server
    - each WTC server has its own LOCAL ACCESS POINTs
    - each WTC server uses the single REMOTE ACCESS POINT
    (since only one GWTDOMAIN is running in this scenario)
    --> problem: only one of the managed server's JNDI tree can be traversed into, and only one of the WTC link works for Cos Naming -> WLS Naming Service resolution
    2. - each machine is running their set of GWADM/GWTDOMAIN
    - in dmconfig, two local Tux domain-ids are defined, for the
    two groups of GW
    - WTC server setup is identical to above; except
    each of the WTC is pointing to separate REMOTE ACCESS POINTs
    - when DOMAINID in ubbconfig is not defined, the same Cos Naming to WLS Naming Service search fails.
    - when DOMAINID in ubbconfig is defined, the same Cos naming to WLS Naming Service search fails with an CORBA:INTERNAL error.
    Does anyone know how to get Cos Naming -> WLS Naming Service working properly under a distributed Tuxedo application setup and also with multiple sets of GWADM/GWTDOMAIN?
    Thanks.
    Edited by a_tam at 04/17/2008 11:34 AM

    Hi,
    we have been starting our investigation into using the distributed application feature of Tuxedo (multiple machines running under 1 Tuxedo domain which make up the entire Tuxedo Application).
    when trying to access WLS EJB object references from Tuxedo, we hit a road block.
    we have been using the standard method of searching through Cos Naming for a bind context which refers to WLS Naming Service. (this method is documented online and in dev2dev samples) Under non distributed application setup (1 Tux domain with 1 machine as in all examples), everything works fine and I can see into 1 WLS server's JNDI tree. But when in distributed application setup where we want to have two (for example) machines and we also want two WLS managed server with each running on their own machine, it seems that there are some unexpected problems:
    1. - only one set of GWADM/GWTDOMAIN is running
    - each WLS managed server has its own WTC server
    - each WTC server has its own LOCAL ACCESS POINTs
    - each WTC server uses the single REMOTE ACCESS POINT
    (since only one GWTDOMAIN is running in this scenario)
    --> problem: only one of the managed server's JNDI tree can be traversed into, and only one of the WTC link works for Cos Naming -> WLS Naming Service resolution
    2. - each machine is running their set of GWADM/GWTDOMAIN
    - in dmconfig, two local Tux domain-ids are defined, for the
    two groups of GW
    - WTC server setup is identical to above; except
    each of the WTC is pointing to separate REMOTE ACCESS POINTs
    - when DOMAINID in ubbconfig is not defined, the same Cos Naming to WLS Naming Service search fails.
    - when DOMAINID in ubbconfig is defined, the same Cos naming to WLS Naming Service search fails with an CORBA:INTERNAL error.
    Does anyone know how to get Cos Naming -> WLS Naming Service working properly under a distributed Tuxedo application setup and also with multiple sets of GWADM/GWTDOMAIN?
    Thanks.
    Edited by a_tam at 04/17/2008 11:34 AM

  • How to keep multiple function modules under one Web service

    Hi Experts,
    I have Three RFC function modules and i need to create one web service for these three RFC function modules. I know How to crearte a web service for one function module.
    please suggest me How to keep multiple function modules under one Web service.
    Thanks in advance
    Lakshminarayana

    Hi Lakshmi,
    The best way to do it is to assign all the three RFC Enabled FM's to one function group. Later on the top menu in Utilities you get an option to Create a Webservice from a Function Group.
    You can create one single Webservice using all the the 3 FM's.
    I hope this helps.
    Thanks,
    Manu

  • Under reset subscriber services on the iPad, how do I learn the passcode when I never set one?

    Under reset subscriber services on the iPad, how do I learn the passcode when I never set one?

    Assuming that you have created a user pin? As its that.

  • How to bind complex input/output types in web service data control

    Hi,
    I have created data control using external web service for simple input & output data type and its working fine.
    But I don't know how it can be done for complex data types.
    My external Web services have complex input & output types. Such as java object which contains another java object again it contains another java object or arry or java collection etc.
    Each my service has one complex input data type and for this no user input is require so how I can do it without using any component for it.
    I want to bind my page components with this input & output type.
    What is the best approach to do this and how to bind screen component.
    Regards,
    Devang

    Hi,
    Thanks frank.
    I already check this link before posting this so if you have any other link then kindly reply.
    Regards,
    Devang

  • How to run Naming service in WebAs server using telnet

    Hi
       i have a requirement to start a naming service in WebAs server.I have seen all the services running in server using telnet.But i haven't find naming service.So i have to start it.so pls send me the command and the way how to start it.

    Hello Bhogi,
    The naming service is a core service so it should always be started. You can check it via telnet using lss command on the server shell or in the visual administrator if you navidate to server-> services -> JNDI Registry.
    I suspect that you have not seen the naming service via telnet as you were on the dispatcher node instead of on the server.
    Best Regards
    Vyara

  • Please tell me How to access the COS NAMING?

    In COS Naming, I create a new context as follows:
    Initial context
    |
    QuerryApp (a new Context)
    |
    OrderQuery (a object)
    But I don't know how to access the "OrderQuery"(using jdk 1.3.1).
    Please help me!!
    email: [email protected]

    Please do not crosspost your questions.

  • How To Run OIM Under Weblogic As A Windows Service?

    Hi
    does anyone know how to run OIM under Weblogic as a windows service?
    Many thanks in advance,
    Evanela

    Hi
    Does anyone know how to run OIM under Weblogic as a windows service?
    I have used "Setting Up a WebLogic Server Instance as a Windows Service" (http://download.oracle.com/docs/cd/E12839_01/web.1111/e13708/winservice.htm#START143), but It doesn't work because OIM use the xlStartWLS.cmd file and not startWebLogic.cmd.
    thanks!
    Edited by: user13082223 on Sep 29, 2010 9:09 AM

  • How to use Tomcat for naming services

    Hi,
    I want to use Tomcat server for a naming service,but how??.
    What i want to do is
    It will register 2 services to a the naming server.
    Later lookup for it from another code.
    I want to know how i can register the same using Tomcat...
    Thanks in Advance
    Mandrake

    http://tomcat.apache.org/tomcat-5.0-doc/jndi-resources-howto.html

  • How to connect server using naming service IOR and server IOR in java

    I need to connect server code from my client code using naming service IOR and server IOR. what are the steps have to be followed to bind the server.
    please help me.

    Connection refused means that you can't reach the server or that the server isn't listening.
    Kaj

  • How to bind to REST web services?

    The REST web services don't provide WSDL. How to bind this kind of services?
    Thanks.

    Melvin, not yet (in fact it's on my plate) - what I usually argue for is to abstract these pieces into services (much like what I did in the rest sample, and then expose them .. )
    In any case - I will start collecting ideas (that is topics) for best practices soon .. Let me know if you have any specific wishes.
    cheers

  • JNDI Naming services

    Im currently working on some code and Im really in need of a naming service, preferably one with a service provider for JNDI. In essence what Im looking for is a very basic name server, although knowing little about the suject at this point Im thinking that ldap, nis are really not well suited to my needs as my key goal is mapping names to references( under dynamic contexts), which Ive allready half implemented. As things are getting more complex and what Ive implemented of rather poor design, Im starting to feel like Im going to have a rough month or two ahead of me!! I dont want to re-invent the wheel and I know in my heart someone has allready coded the software I need!!! Unfortunately My search has been fruitless. Id greatly appreciate it if someone can steer me in the right direction. In the meantime I think Ill be pulling my hair out trying to figure out how to code the software I need.... Sorry for not fully explaining what Im after, if not enough info just let me know and Ill try to provide more detail.............

    Hi Prisco,
    You can go very well fo JNDI. And you can use Netscape or Iplanet Directory server as LDAP server.
    Please Download the Directory Server from this URL.
    http://www.iplanet.com/downloads/download/2087.html
    Also here with I am giving you a simple Authentication program, which makes use of JNDI and Netscape Directory server. If you follow these steps, you will get a good idea about JNDI.
    DESCRIPTION:
    I am trying to use LDAP to control access to a HTML page. I want an authentication
    box to pop up, allowing the user to authenticate to the HTML page through a LDAP server.
    If they succesfully authenticate, I need to check their username against a list
    of valid usernames that's stored in a database, then give access to the page
    based on that list. How can I implement this solution?
    SOLUTION:
    The best way is to use Basic Authentication solution with JNDI and LDAP server,
    Netscape Directory server(for example) with a simple servlet program. Java Naming
    and Directory Interface (JNDI) API is standardized, and enable to use different
    directory services such as Netscape Directory server. LDAP server can be used
    for storing some common data's used in the sample solution.
    It can be done through a servlet to check the user and its password which is
    stored in the LDAP server.
    In order to demonstrate a sample solution, I will use the Netscape Directory
    Server 4.13 as the LDAP server, which is loaded my own LDIF file with customized
    attributes. The basic authentication algorithm will be used in this sample
    solution.
    The following steps are to implement this sample solution:
    1. Creating our own LDAP data Interchange format (LDIF) file.
    2. Loading(Import) the Ldif file in Netscape Directory Server.
    3. Creation of user schema files for customized attributes.
    4. Load the user schema files in the Netscape Directory Server.
    5. Restart the Directory Server
    6. A simple servlet program for basic authentication.
    7. A sample HTML file is given last, used in servlet program.
    Here are the detail description of the above steps:
    STEP 1: Creating our own LDAP data Interchange format (LDIF) file:
    Here is the LDIF (LDAP data Interchange format) file is a text based format used to work
    on LDAP data, with both our application and end users.
    Through this LDIF file, I am having an attribute "customerid: timb" for which I will
    be preparing the authentication, which will have its own password
    "userpassword: bakrudeen", through which it can be maintained in a common place.
    Here again in the same LDIF file, other information related to the "customerid: timb"
    such as common name "cn: Tim Briggs", sur name "sn: Briggs" etc are maintained.
    The data in LDAP is organized in a tree, called a Directory Information tree(DIT).
    Each leaf in DIT is called an entry. The first entry in DIT is called the root entry.
    Here is a sample LDIF File which is used in our sample solution:-
    Here the DIT is maintained in such a way data is organized in LDAP, is fairly simple. In this
    sample we store all of our entries in a common root o=fedup.com, with the following branches
    Customers - Customer Entries with " customer id: timb" , userpassword: bakrudeen, and other
    information related to this customer is kept in a common place.
    dn: uid=timb,ou=Customers,o=fedup.com
    changetype:add
    objectclass: customer
    objectclass: inetorgperson
    objectclass: organizationalPerson
    objectclass: person
    objectclass: top
    cn: Tim Briggs
    uid: timb
    givenname: Tim
    customerid: timb
    sn: Briggs
    facsimiletelephonenumber: 4101
    telephonenumber: 4145
    creatorsname: uid=admin,ou=Administrators,ou=TopologyManagement,o=NetscapeRoot
    createtimestamp: 20000501084001Z
    aci: (target="ldap:///uid=timb,ou=Customers,o=fedup.com")(targetattr="*")(version 3.0; acl "unknown"; allow (all)(userdn = "ldap:///anyone");)
    ou: Customers
    mail:
    userpassword: bakrudeen
    modifiersname: uid=admin,ou=Administrators,ou=TopologyManagement,o=NetscapeRoot
    modifytimestamp: 20000605084001Z
    STEP 2: Loading(Import) the Ldif file in Netscape Directory Server:-
    Once after creating the above sample LDIF File, it should be added in Netscape Directory Server.
    It should be imported in order to add the neccessary atributes in the Netscape Directory server,
    so that we can make use of the Common data.
    Steps for Importing the LDIF file in the Directory Server:-
    1) Create an instance of the Directory Server.
    2) Bind it to the different port with different organizational unit
    (Here in this program, it is 1124).
    3) Press the Configuration from the menu.
    4) Then select import from the Console menu.
    5) Choose the LDIF file you are going to import.
    6) There also you have to provide a file for rejected entries, ie it will list all the entries
    which is not added while loading.
    STEP 3: Creation of our own USER SCHEMA Files:-
    It is necessary for adding the attributes which are not defined in the
    Netscape directory server. In the above, customerid which is defined in ldif
    file is not existing in the directory server.
    Here is the Schema file for attributes:(ie for defining for eg customer id).
    The name of the file is slapd.user_at.conf:-
    attribute customerid customerid-oid cis single
    attribute packageid packageid-oid cis single
    attribute receivedate receivedate-oid cis single
    attribute shipdate shipdate-oid cis single
    attribute shipperid shipperid-oid dn single
    attribute receiveid receiveid-oid dn single
    #Java Attributes
    # Schema for storing java objects and java object references
    attribute javaClassName 1.3.6.1.4.1.42.2.27.4.1.1 ces single
    attribute javaCodebase 1.3.6.1.4.1.42.2.27.4.1.6 ces
    attribute javaSerializedData 1.3.6.1.4.1.42.2.27.4.1.7 bin single
    attribute javaRemoteLocation 1.3.6.1.4.1.42.2.27.4.1.8 ces single
    attribute javaFactory 1.3.6.1.4.1.42.2.27.4.1.4 ces single
    attribute javaReferenceAddress 1.3.6.1.4.1.42.2.27.4.1.3 ces
    Here is Schema file for your own object classes:-
    The name of the file is Slapd.user_oc.conf:-
    In the similar way as above there are no "customer" class in the object classes
    defined in the LDAP, so we will have to create our own "customer" Object class.
    Also it extends inetOrgPerson to add some new attributes such as "customerid".
    The object class of an entry specifies what attributes are required and what
    attributes are allowed in a particular entry.
    Also for eg, Package classes in the object class is created.
    Here is the sample file for creating the above:-
    objectclass package
    oid package-oid
    superior top
    requires
    packageid,
    receiveid,
    shipdate,
    shipperid
    allows
    description,
    ou,
    receivedate
    objectclass customer
    oid customer-oid
    superior inetorgperson
    requires
    customerid
    allows
    c
    #JAVA Schema
    # Schema for storing java objects and java object references
    objectclass javaContainer
    oid 1.3.6.1.4.1.42.2.27.4.2.1
    superior top
    requires
    cn
    objectclass javaObject
    oid 1.3.6.1.4.1.42.2.27.4.2.4
    superior top
    requires
    javaClassName
    allows
    javaCodebase
    objectclass javaSerializedObject
    oid 1.3.6.1.4.1.42.2.27.4.2.5
    superior javaObject
    requires
    javaSerializedData
    objectclass javaRemoteObject
    oid 1.3.6.1.4.1.42.2.27.4.2.6
    superior javaObject
    requires
    javaRemoteLocation
    objectclass javaNamingReference
    oid 1.3.6.1.4.1.42.2.27.4.2.7
    superior javaObject
    requires
    javaReferenceAddress,
    javaFactory
    STEP 4: Loading the USER SCHEMA files in Directory Server:-
    All the attributes created above should be added to the corresponding directory server,
    in order to make it as a common attribute.
    Steps for adding the User Schema files to the Directory Server:-
    1. Copy the above user schema files to the appropriate instance of Netscape Directory Server
    created above so that the existing LDIF file which is used in the Netscape directory
    server is not appended or overwritten.
    2. For eg, put it in "NetscapeServer/slapd-HostName/config" to replace the empty
    files "slapd.user_at.conf" and "slapd.user_oc.conf" by default.
    3. Then restart the Directory Server.
    STEP 5: Simple Servlet Program for BASIC AUTHENTICATION.
    Here is the simple servlet program for Basic Authentication:-
    Here the way the LDAP authentication works is by attempting to the server with a
    DN and a password. No user in their right mind will remember their DN, so we use
    some other attribute such as user-id. Then we search in the LDAP server to find
    an entry that contains the attribute. Here we are maintaining SUBTREE_SCOPE using
    JNDI, which starts its search starting from the base entry, and searches
    everything below it including the base entry. Also I am maintaining Global
    variables for LDAP setting.
    // Importing the necessary Packages
    import java.io.*;
    import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import javax.naming.*;
    import javax.naming.directory.*;
    public class AuthServ extends HttpServlet {
    // Here are our global variables of our LDAP Settings.
    public static String MY_CUSTOMER_BASE = "ou=Customers,o=fedup.com";
    public static String INITCTX = "com.sun.jndi.ldap.LdapCtxFactory";
    public static int MY_PORT = 1124;
    public static String MY_HOST = "ldap://sundts1.india.sun.com:" + MY_PORT;
    public static String MY_MGR = "cn=Directory Manager";
    public static String MY_PWD = "password";
    public static String MY_SEARCHBASE = "o=fedup.com";
    Hashtable env = new Hashtable();
    // Using the Get Method of Servlet
    public void doGet(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException {
    res.setContentType("text/html");
    // To Check to See if there is any data in the "Authorization" Http header from the browser.
    // If not it will prompt for username and password.
    String auth = req.getHeader("Authorization");
    // Do we allow the user
    if (!allowedUser(auth) ) {
    // Not Allowed, so report unauthorized
    res.setStatus(res.SC_UNAUTHORIZED);
    res.setHeader("WWW-Authenticate", "BASIC realm=\"users\"");
    // User is allowed in
    else
    // Using SSI to include and display the content of a Simple HTML Page
    RequestDispatcher rd= this.getServletContext().getRequestDispatcher("/auth.html");
    rd.include(req,res);
    // This method checks to see whether the user exist in the LDAP database.
    protected boolean allowedUser(String auth) throws IOException {
    Hashtable env = new Hashtable();
    boolean status = false;
    try {
    // No Authorization
    if (auth == null) return false;
    // Basic Authentication is Handled, Other possibilities are MD5 hash or SSL Certificates.
    if (!auth.toUpperCase().startsWith("BASIC ")) {
    return false; //only do BASIC
    // Get encoded user and password, comes after BASIC
    String userpassEncoded = auth.substring(6);
    // Decode it, using any base 64 decoder
    sun.misc.BASE64Decoder dec = new sun.misc.BASE64Decoder();
    String userpassDecoded = new String(dec.decodeBuffer(userpassEncoded));
    StringTokenizer st = new StringTokenizer(userpassDecoded,":");
    String customerid = st.nextToken();
    String pwd = st.nextToken();
    Please Note:
    LDAP Authentication works by attempting to bind to the server with a DN and a password.
    No user will remember their DN so we use some other attribute such as user-id.
    Then we search in the LDAP server to find an entry in the LDAP server to find an entry
    that contains the attribute.
    For a Secure System, we should use an attribute that will be unique per entry such as
    uid, in our case the "customerid" attribute.
    // Prepare for context
    env.put(Context.INITIAL_CONTEXT_FACTORY, INITCTX);
    env.put(Context.PROVIDER_URL, MY_HOST);
    // Get a reference to a directory context
    DirContext ctx = new InitialDirContext(env);
    // Specify the scope of the search
    SearchControls constraints = new SearchControls();
    constraints.setSearchScope(SearchControls.SUBTREE_SCOPE);
    // Perform the actual search
    // We give it a searchbase, a filter and the constraints
    // containing the scope of the search
    NamingEnumeration results =
    ctx.search(MY_CUSTOMER_BASE, "(customerid=" + customerid + ")", constraints);
    String dn = null;
    If it does not throw an exception,
    then it is considered to be an Successful Authentication
    // Now step through the search results
    while (results != null && results.hasMore()) {
    SearchResult sr = (SearchResult) results.next();
    dn = sr.getName() + "," + MY_CUSTOMER_BASE;
    env.put(Context.SECURITY_AUTHENTICATION, "simple");
    env.put(Context.SECURITY_PRINCIPAL, dn);
    env.put(Context.SECURITY_CREDENTIALS, pwd);
    try {
    DirContext ctx2 = new InitialDirContext(env);
    status = true;
    } catch (AuthenticationException e) {
    log(e.toString());
    } catch (NamingException x) {
    log(x.toString());
    return status;
    STEP 6: Simple HTML file used in Servlet Program:-
    Here is the Simple HTML File we are including in RequestDispatcher of the above program:-
    <html>
    <head>
    <title> Authorisation</title>
    </head>
    <body>
    <h1> Your Authorisation is Successful </h1>
    </body>
    </html>
    I hope this will help you.
    Thanks
    Bakrudeen

Maybe you are looking for

  • Error in updating R-tree index

    Hi, I want to update a geometry column with a R-tree index on it with a statement like: update xxx set xxx.geometry = (select yyy.geometry... All geometries in the updated table are NULL before. I get the following error: ORA-29877: failed in the exe

  • Ipad 2 music not playing correctly through ipod dock

    When I connect my ipad 2 using the ipod dock in my car, there is a LOT of background noise when listening to the music. It almost sounds like a soft static. It doesn't do this for my ipod or my iphone. I have checked, and the cable is correctly plugg

  • Composite Foreign Keys

    How do I map a composite foreign key using toplink? I can reference a particular record in mytable using the following sql statement: SELECT * FROM mytable m WHERE m.foreign_id = x AND m.type = y; Where x represents the primary key in my entity and y

  • Profit n loss statement n balance sheet reports

    Hi, I need to develop PNL and Balance sheet reports. Could anyone please guide me how-tos about it and the pit holes need to b avoided? Thanks, DP

  • Adobe Reader & DirectX 11

    Operating system is Win Vista Home Premium 32 bit.  After installing DirectX 11 some months ago I can no longer view a particular PDF though have no problem with others.  Current Adobe Reader is 9.3 which shows the Preferred Renderer opertions as Dir