Search This Blog

Monday, 31 August 2015

WebLogic Security - Boot Identity

When you first time installed and configured a WebLogic Server in production domain it will prompt you for username and password, when you start the server using startWebLogic.sh or startWebLogic.cmd in command line it will wait as follows:

cd $DOMAIN_HOME/
./startWebLogic.sh

Without Boot identity production mode startWebLogic prompting
Start WebLogic server without prompting for user credentials

Create security folder in the AdminServer folder which is in the $DOMAIN_HOME/servers/

mkdir security

Create security folder in the AdminServer folder
You can use any editor to to create the boot identity here I m using vi.

 vi boot.properties

Enter the two lines int the boot.properties file.

username=weblogic
password=welcome1
Create Boot identity: boot.properties

After boot identity creation server starts using stored boot.properties
 WebLogic server when it is first time reads the clear text username, password from the boot identity file it will over writes into the same boot.properties file with the encrypted values for username, password. You can verify that using

cat boot.properties
After starting the server WebLogic encrypts the boot idenity with AES algorithm
Certification Question: 
[This can be interesting interview question as well!]
If an Administrator changes the weblogic password from the Admin Console. what would happen to boot identity? Does the next restart works fine? else you need to modify anything in the boot identity?
Changing the password for weblgoic user

enter new password, confirm password and save
After the changing the password you can stop the server and start the server.
When I've started the server got the the following security error:
    
The fix for this issue is you need to reenter the username,password in the boot.properties file.
start the AdminServer.... it will re-run the encryption and will  identifies the boot identity again :)


Thursday, 27 August 2015

JMS Foreign Servers on WebLogic for JMS Destination as Topic

JMS Foreign Server configuration

In WebLogic we have various choice to do cross domain communication. where it is depends on the application needs, reliable communication or unreliable.

Prerequisites:
  • Two WebLogic domains or two JMS Providers
  • JMS Module with ConnectionFactory, Destination on the remote domain
Lets start configure the Foreign server on WebLogic Domain.
Step 1: Login to WebLogic Admin Console on which you wish to run the Foreign Server. Configure JMS Server as we have done earlier.

Step 2: Configure the JMS Module where select the resource to configure - Foreign Server as below:
Create a JMS System Module named FSMod (Optional) you can work within existing Module as well

Select Foreign Server configuration in the JMS module

Step 3: Name of the Foreign Server, Enter the remote machine JNDI Connection URL

JMS Foreign Server Configuration - Name, Connection URL

Step 4: Next table you can find the Connection Factory enter them to conenct to the remote machine JMS Connection objects accordingly.
Enter the Connection Factory mapping from remote JNDI name with local JNDI name

Steop 5: Configure JMS Foreign destination here we have example with Topic - TestTopic which can be foreign reference created as FSTestTopic.
JMS Destination here it is TestTopic mapping to local FSTestTopic


After the Foreign Server configuration it looks like this

Validate your Foreign Server configurations on targeted JNDI Name visible in target server


You can test these Foreign Server configuration with the "TopicSend.java" mapping where newly configured Foreign Server hosted.

In the "TopicReceiver.java" program remain with the remote machine configurations.
We have tested this experiment check this on your setup and do this exciting lab exercise.

Cheers!!!


Friday, 21 August 2015

JDBC Datasource creation on Precise Ubuntu box using Vagrant Oracle XE

Preparation 
  • Download Ubuntu-Vagrant-Oracle-xe
  • Modify the Vagrantfile
The major changes in the vagrangfile are Oracle XE on Vagrant Ubuntu box
  • Memory size 1024MB 
  • Select the hostonly network adapter with a private IP. 
 The vagrant file:

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|
  config.vm.box = "precise64"
  config.vm.box_url = "http://files.vagrantup.com/precise64.box"
  config.vm.hostname = "oracle.vybhava.com"
  config.vm.synced_folder ".", "/home/vagrant/vagrant-ubuntu-oracle-xe", :mount_options => ["dmode=777","fmode=666"]
  config.vm.network "private_network", ip: "192.168.33.105"
  config.vm.network :forwarded_port, guest: 1521, host: 1521

  config.vm.provider :virtualbox do |vb|
    vb.customize ["modifyvm", :id,
                  "--name", "oracle",
                  # Oracle claims to need 512MB of memory available minimum
                  "--memory", "1024",
                  # Enable DNS behind NAT
                  "--natdnshostresolver1", "on"]
  end

  config.vm.provision :shell, :inline => "echo \"America/New_York\" | sudo tee /etc/timezone && dpkg-reconfigure --frontend noninteractive tzdata"
  config.vbguest.auto_update = false
  ....
... # remain code as it is no changes
end

Configure DataSource on WebLogic administration console

Step-by-Step JDBC Datasource creation process is as follows
  1. login to your WebLogic domain and navigate to the domain structure section select datasource
1. Select Datasource in the work area select New button

1.a Select Generic Data source

2. Enter JDBC Datasource properties : name, JNDI name, Database type

3. Select Database driver

4.XA driver selection nothing to select in the transaction



5. Connection pool parameters

6.a. Connection pool Test confirmation

6.c. Test Configuration Message - Succeeded

7. Target the data source to Cluster for HA

8. Completion of Datasource configuration

Sample Java program to validate the datasource given below:

package vybhava.technologies.jdbc;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;

/**
 * This example demonstrates obtaining a database connection using a
 * DataSource object.
 * Create a DataSource using any DB name it as myDs and its JNDI as jdbc/myDs
 * To compile:  javac -d . SimpleSql.java
 * Execute : java vybhava.technologies.jdbc.SimpleSql
 */
public class SimpleSql {

  public static void main(String argv[])
      throws Exception {

    java.sql.Connection conn = null;
    java.sql.Statement stmt = null;
    ResultSet rs = null;

    try {

      // ============== Get a database connection ==================

      Context ctx = null;

      // Put connection properties in to a hashtable.
      Hashtable ht = new Hashtable();
      ht.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
      ht.put(Context.PROVIDER_URL, "t3://192.168.33.104:7011,192.168.33.104:7012");

      // Get a context for the JNDI lookup
      ctx = new InitialContext(ht);
      // Look up the data source
      javax.sql.DataSource ds = (javax.sql.DataSource) ctx.lookup("jdbc/myDs1");
      //Get a database connection from the data source
      conn = ds.getConnection();
      conn.setAutoCommit(true);

      System.out.println("Making connection...\n");

      // ============== Execute SQL statements ======================
      stmt = conn.createStatement();

      try {
        stmt.execute("drop table empdemo");
        System.out.println("Table empdemo dropped.");
      } catch (SQLException e) {
        System.out.println("Table empdemo doesn't need to be dropped.");
      }

      stmt.execute("create table empdemo (empid int, name varchar(30), dept int)");
      System.out.println("Table empdemo created.");

      int numrows = stmt.executeUpdate("insert into empdemo values (0, 'John Smith', 12)");
   numrows = stmt.executeUpdate("insert into empdemo values (1, 'Pavan Devarakonda', 12)");
   numrows = stmt.executeUpdate("insert into empdemo values (2, 'Suresh', 13)");
      System.out.println("Number of rows inserted = " + numrows);

      stmt.execute("select * from empdemo");

      rs = stmt.getResultSet();
      System.out.println("Querying data...");
      while (rs.next()) {
        System.out.println("  ID: " + rs.getString("empid") +
            "\n  Name: " + rs.getString("name") +
            "\n  Dept: " + rs.getString("dept"));
      }

      numrows = stmt.executeUpdate("delete from empdemo where empid = 0");
      System.out.println("Number of rows deleted = " + numrows);
    } catch (Exception e) {
      System.out.println("Exception was thrown: " + e.getMessage());
    } finally {
   // ========== Close JDBC objects, including the connection ======= 
      try {
        if (stmt != null) {
          stmt.close();
          stmt = null;
        }
      } catch (SQLException e) {
        throw e;
      } finally {
        try {
          if (conn != null) {
            conn.close();
            conn = null;
          }
        } catch (SQLException e) {
          throw e;
        }
      }
    }
  }
}
 Finally you need to compile the above program and execute that. You can see the commands in the comments.

JDBC Datasource validating  with SimpleSql.java compile and execution

WebLogic Books

  • Oracle WebLogic Server 12c: Administration Handbook
  • WebLogic Diagnostic Framework
  • Advanced WebLogic Server Automation
  • Oracle SOA Suite 11g Administrator's Handbook

Popular Posts