Showing posts with label ldap. Show all posts
Showing posts with label ldap. Show all posts

Monday, October 10, 2011

Java JNDI based client for OJMS

To work with Java Naming and Directory Interface (JNDI) in OJMS , which is the JMS interface for AQ, we need to register the oracle database with LDAP server. JMS administrator can register ConnectionFactory objects in a LDAP server.
Lets check following sample code, which is used to register the connection factory objects @ LDAP server.

void register_Factory_in_LDAP() throws Exception {
        Hashtable env = new Hashtable();
        // ldap settings
        env.put(Context.INITIAL_CONTEXT_FACTORY, AQjmsConstants.INIT_CTX_FACTORY);
        env.put(Context.PROVIDER_URL, "ldap://localhost:10389/");
        env.put(AQjmsConstants.SERVER_DN, "cn=ORCL,cn=OracleContext,ou=Services, o=sgi,c=us");
        env.put(Context.SECURITY_PRINCIPAL, "uid=ratha,ou=Services, o=sgi,c=us");
        env.put(Context.SECURITY_CREDENTIALS, "secret");
        env.put(Context.SECURITY_AUTHENTICATION, "simple");

        String url = "jdbc:oracle:thin:@localhost:1521/orcl";
        Properties properties = new Properties();
        properties.setProperty("user", "ratha");
        properties.setProperty("password", "ratha");
        try {
            AQjmsFactory.registerConnectionFactory(env, "test_queue_factory", url, properties,
                                                   "queue");
            System.out.println("Connection factory craeted ");

        } catch (Exception e) {
            e.printStackTrace();
          }
    }

// DO lookup

 void get_Factory_from_LDAP() throws Exception {

        Hashtable env = new Hashtable();
        env.put(Context.INITIAL_CONTEXT_FACTORY, AQjmsConstants.INIT_CTX_FACTORY);
        // ldapserver is your LDAP host and 389 is your port
        env.put(Context.INITIAL_CONTEXT_FACTORY, AQjmsConstants.INIT_CTX_FACTORY);
        env.put(Context.PROVIDER_URL, "ldap://localhost:10388/");
        env.put(Context.SECURITY_PRINCIPAL, "uid=ratha,ou=Services, o=sgi,c=us");
        env.put(Context.SECURITY_CREDENTIALS, "secret");

        DirContext inictx = new InitialDirContext(env);
        inictx = (DirContext) inictx.lookup("cn=ORCL,cn=OracleContext,ou=Services, o=sgi,c=us");
        // go to the connection factory holder cn=OraclDBConnections
        DirContext connctx = (DirContext) inictx.lookup("cn=oracledbconnections");

        // get connection factory "test_queue_factory"
        QueueConnectionFactory qc_fact = (QueueConnectionFactory) connctx.lookup("cn=ratha");

        System.out.println("Factory look up success " + qc_fact.toString());
        QueueConnection QCon = qc_fact.createQueueConnection();
        System.out.println("Connection created " + QCon.toString());
       DirContext destctxQF = (DirContext) inictx.lookup("cn=OracleDBQueues");
        System.out.println("OracleDBQueues look up success " + destctxQF.toString());
        Queue queue = (Queue) destctxQF.lookup("cn=ratha.test");
        System.out.println("Queue look up success :" + queue.toString());

        Session session = QCon.createQueueSession(true, QueueSession.AUTO_ACKNOWLEDGE);
        QCon.start();
        QueueSender sender = ((QueueSession) session).createSender(queue);
        System.out.println("Sender creation success :" + sender.toString());
    
       String msg = "test";
       TextMessage message = session.createTextMessage(msg);

       sender.send(message);
       // MessageConsumer consumer = session.createConsumer(queue);
       // TextMessage msg2 = (TextMessage) consumer.receive();
       // System.out.println("MESSAGE RECEIVED " + msg2.getText());

}

Thursday, October 6, 2011

Creating partitions in ApacheDS

With ApacheDS as you may know, we can create our  customized partitions in order to keep our data according to  our requirements.
Lets have a look on creating partitions..

Steps
  • As I mentioned in my previous post , install and create a connection for the LDAP server.
  •  Double click on server link. You will see the server.xml's graphical view. From that select 'Partitions' tab

  • Under partitions section you will see default two partitions are listed out
    • System
    • example
  • Click on the 'Add' button. You will see a new partition will be created. Provide ID and suffix. Click on 'Save' button @ toolbar.

  • You can do this @ server.xml by adding new .Go to the ApcheDS installation directory find the server.xml and copy one of the existing "example" partition.
  • Now you  created a new partition called "acme.com". But you can not view the partition at LDAP browser. For that you have to create a new 'context entry' for the newly created partition.
  • Go to LDAP browser,'Root DSE '-->Right click->'New Context entry' .Select 'Create entry from scratch' option.
  • Select 'ObjectClass' as 'Domain' click  'Add' so you will see added object classes at your right pane.

  • Now enter the DN as you provided when you create the partition.
    • eg: dc=acme,dc=com
  • Click 'next' and Finish.You will see the newly created entry at LDAP browser .

  • When you try to make connections to newly created partition , You have to create a user/uid for this partition .

Installing and configuring ApacheDS

ApacheDS is an open source project, which provides directory server , which is LDAP v3 compliant. You can download ApcheDS here, which comes with eclipse based LDAP browser + LDAP server. So, you don't need to use extrernal LDAP browsers (eg: JXplorer)  to configure your directory server.

Steps
  • Download , install and start the Apache Directory Studio™ (v1.5.3)
  •  Go to 'File' menu and click 'New'. Select 'ApcheDS' server. Go to 'next' page.
  •  Provide a unique name to identify your LDAP server instance.(eg: ServerA) Click 'Finish'
  • You will see your newly created server @ servers panel.
  •  Double click on ServerA's link.You will see a window which lists all options to configure the server.

  •  At the 'General' tab, you can provide the port numbers for different protocols. Here leave the default port numbers as it is.
    •  LDAP =10389
    • LDAPS=10636
  •  Go to 'servers' panel and click the 'start' button.

  • Now, server instance created. We have to create a connection for that server.(ie:ServerA)
  • Go to 'LDAP' menu and select 'New Connection'
  • Provide 
    • Connection name - Connection A
    • Hostname - localhost
    • Port no -10389 (This is the port number ServerA instance running)

  • Click 'Next'. 
    • Authentication Method - "Simple Authentication"
    • Bind DN - "ou=system,uid=admin" (this is the one by default available partition and the user)
    • Bind password - 'secret' (default  passoword)
  • If you provide all the above parameters correctly , your connection will start successfully. You can see the available partitions at LDAP browser.
That is it for installation and starting the server.