Monday, May 22, 2017

WebLogic ASE Encryption & Decryption

(A) Encrypt or Decrypt  weblogic AES password using WLST
           cd $OIM_HOME/common/bin
            ./wlst.sh
domain = "$USER_PROJECTS/domains/$DOMAIN_NAME"
service = weblogic.security.internal.SerializedSystemIni.getEncryptionService(domain)
encryption = weblogic.security.internal.encryption.ClearOrEncryptedService(service)
encryption.encrypt("password")
encryption.decrypt("{AES}abc/pH/mQ3wVaSzk+2U8weGH6LVCcRteFh24PCqnoY=")




(B)Encrypt or Decrypt  weblogic AES password using Java
Jar needed –
            $WL_HOME/server/lib/wlfullclient.jar
            $WL_HOME/server/lib/cryptoj.jar

Create a new folder 'C:\\weblogic_file' and put 'SerializedSystemIni.dat' file from $DOMAIN/security

import weblogic.security.internal.SerializedSystemIni;
import weblogic.security.internal.encryption.ClearOrEncryptedService;
import weblogic.security.internal.encryption.EncryptionService;

public class EncryptDecrypt {

       public static void main(String[] args) {

        EncryptionService encryptionService = SerializedSystemIni.getEncryptionService("C:\\weblogic_file");
        ClearOrEncryptedService clearOrEncryptedService = new ClearOrEncryptedService(encryptionService);

System.out.println("Encrypted password: " + clearOrEncryptedService.encrypt("password"));

System.out.println("Clear text password: " + clearOrEncryptedService.decrypt("{AES}abc/pH/mQ3wVaSzk+2U8weGH6LVCcRteFh24PCqnoY="));
       }
}

Thursday, April 20, 2017

OIM Jar Management from API

/*Jar needed - wlfullclient-10.3.6.0.jar, spring.jar, oimclient.jar, jrf-api-11.1.1.0.0.jar & commons-logging-1.2.jar

Steps to run below code
       Update Host, Port & password, jar name & Jar path from OIM Machine in belwo code
       Get the authwl.conf file from designconsole/config folder and then run below method

Refer link to setup design console in your local.
Refer link to login in OIM from API.
*/

package com.test;

import java.util.HashSet;
import java.util.Hashtable;
import java.util.Set;

import javax.security.auth.login.LoginException;

import oracle.iam.platform.OIMClient;
import oracle.iam.platformservice.api.PlatformUtilsService;
import oracle.iam.platformservice.vo.JarElement;

public class ManageJar {

static PlatformUtilsService platformUtilsServe = null;

/*
Enter the jar type
1.JavaTasks
2.ScheduleTask
3.ThirdParty
4.ICFBundle
*/

public static void main(String[] args) throws Exception {
OIMClient oimClient = login(".\\Input\\authwl.conf", "t3://host:port/", "xelsysadm", "password", false, "");
platformUtilsServe = oimClient.getService(PlatformUtilsService.class);
uploadJar("JavaTasks", "temp/Custom_Java.jar");
uploadJar("ScheduleTask", "temp/Custom_Sch.jar");
uploadJar("ThirdParty", "temp/Custom_ThirdParty.jar");
uploadJar("ICFBundle", "temp/Custom_ICFBundle.jar");

deleteJar("JavaTasks", "Custom_Java.jar");
purgeCache();

oimClient.logout();
}


  public static void purgeCache() throws Exception
   {
  platformUtilsServe.purgeCache("ALL");
       System.out.println("Successfully purged the cache.");
   }
 

   public static void uploadJar(String jarType, String jarPath) throws Exception
   {
    System.out.println( "Going to uploaded jar: "+jarPath);
       JarElement jarElement = new JarElement();
       jarElement.setType(jarType);
       jarElement.setPath(jarPath);
     
       Set<JarElement> jarElements = new HashSet<JarElement>();
       jarElements.add(jarElement);
     
       platformUtilsServe.uploadJars(jarElements);
       System.out.println( "Successfully uploaded jar: "+jarPath);
   }
 

   public static void deleteJar(String jarType, String jarName) throws Exception
   {
       JarElement jarElement = new JarElement();
       jarElement.setType(jarType);
       jarElement.setName(jarName);
     
       Set<JarElement> jarElements = new HashSet<JarElement>();
       jarElements.add(jarElement);
     
       platformUtilsServe.deleteJars(jarElements);
       System.out.println( "Successfully deleted jar: "+ jarName);
   }
 

   public static void updateJar(String jarType, String jarPath) throws Exception
   {
       JarElement jarElement = new JarElement();
       jarElement.setType(jarType);
       jarElement.setPath(jarPath);
     
       Set<JarElement> jarElements = new HashSet<JarElement>();
       jarElements.add(jarElement);
     
       platformUtilsServe.updateJars(jarElements);
       System.out.println( "Successfully updated jar:" + jarPath);
   }
 

   public static void downloadJar(String jarType, String jarName, String destinationPath) throws Exception
   {
       JarElement jarElement = new JarElement();
       jarElement.setType(jarType);
       jarElement.setName(jarName);
       jarElement.setPath(destinationPath);
     
       Set<JarElement> jarElements = new HashSet<JarElement>();
       jarElements.add(jarElement);
     
       platformUtilsServe.downloadJars(jarElements);
       System.out.println("Successfully downloaded jar: " + destinationPath);
   }
 
public static OIMClient login(String authwlPath, String oimProviderURL,
String userId, String password, boolean isSSL, String trustKeystorePath){

       System.setProperty("java.security.auth.login.config", authwlPath);
       System.setProperty("APPSERVER_TYPE", "wls");
     
       if(isSSL)
           System.setProperty("weblogic.security.SSL.trustedCAKeyStore", trustKeystorePath);

       Hashtable<String, String> env = new Hashtable<String, String>();
       env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
       env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, oimProviderURL);
       OIMClient oimClient = new OIMClient(env);
     
       try {
oimClient.login(userId, password.toCharArray());
       System.out.println("Login Done!!!");
} catch (LoginException e) {
e.printStackTrace();
}

return oimClient;
}


}

OIM API Login

/*Jar needed - wlfullclient-10.3.6.0.jar, spring.jar, oimclient.jar, jrf-api-11.1.1.0.0.jar & commons-logging-1.2.jar

Steps to run below code
      Update Host, Port & password in belwo code
       Get the authwl.conf file from designconsole/config folder and then run below method

Refer link  to setup design console in your local.
*/




package com.test;

import java.util.Hashtable;
import oracle.iam.platform.OIMClient;

public class OIMLogin {

static OIMClient oimClient = null;
static String authFile = ".\\Input\\authwl.conf";
public static void main(String[] args) {
login( authFile, "t3://host:port/", "xelsysadm", "password", false, "");
oimClient.logout();
}


public static OIMClient login(String oimProviderURL, String userId, String password){
return login(authFile, oimProviderURL, userId, password, false, "");
}

public static OIMClient login(String authwlPath, String oimProviderURL,
String userId, String password, boolean isSSL, String trustKeystorePath){

        System.setProperty("java.security.auth.login.config", authwlPath);
        System.setProperty("APPSERVER_TYPE", "wls");
     
        if(isSSL)
            System.setProperty("weblogic.security.SSL.trustedCAKeyStore", trustKeystorePath);

        Hashtable<String, String> env = new Hashtable<String, String>();
        env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, "weblogic.jndi.WLInitialContextFactory");
        env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, oimProviderURL);
        oimClient = new OIMClient(env);
     
        try {
oimClient.login(userId, password.toCharArray());
       System.out.println("Login Done!!!");
} catch (Exception e) {
e.printStackTrace();
}

return oimClient;
}

}

Thursday, September 22, 2016

MDS export import delete

WLST command to export, import or delete OIM MDS files.


Connect WLST -
           cd $OIM_HOME/common/bin
           ./wlst.sh
           connect('weblogic',  'password', 't3://host:port')

* You have to give Weblogic Admin server host & port in above command
* Replace the server name with actual WebLogic managed server name in belwo command


(1) MDS Export command

All Files - exportMetadata(application='OIMMetadata',server='WLS_OIM',toLocation='/tmp/MDS/OIM0710')

One Particular File - exportMetadata(application='OIMMetadata',server='WLS_OIM',docs='/file/User.xml',toLocation='/tmp/MDS/OIM0710')


(2) MDS Import command
All Files - importMetadata(application='OIMMetadata',server='WLS_OIM',fromLocation='/tmp/MDS/OIM0710')

One Particular File -importMetadata(application='OIMMetadata',server='WLS_OIM',docs='/file/User.xml',fromLocation='/tmp/MDS/OIM0710')

(3) MDS Delete command

Delete all files and particular folder -
deleteMetadata(application='OIMMetadata',server='WLS_OIM',docs='/custom/metadata/AD User/**')

Delete files only from any particular folder -
deleteMetadata(application='OIMMetadata',server='WLS_OIM',docs='/custom/metadata/AD User/*')

Delete one file -
deleteMetadata(application='OIMMetadata',server='WLS_OIM',docs='/custom/metadata/ADUser/ADForm.xml')


Exist WLST -
          exit()



To export SOA or OIM-UI MDS files, just change the application name in command with belwo value

exportMetadata(application='soa-infra',server='WLS_SOA',toLocation='/tmp/MDS/SOA0710')

exportMetadata(application='oracle.iam.console.identity.self-service.ear',server='WLS_OIM',toLocation='/tmp/MDS/OIMUI0710')


Thursday, July 14, 2016

Opatch command to get OIM environment details

Get OIM env details using Optach and other commnad [Java & Weblogic]


* Plz change the middle-ware folder structure as per installed env

(1) Get java version and home
java -version
echo $JAVA_HOME

(2) Get the snap shot of opatch applied in Oracle Common
export ORACLE_HOME=/apps/oracle/product/Middleware1036/oracle_common
cd /apps/oracle/product/Middleware1036/oracle_common/OPatch
./opatch lsinventory -detail


(3) Get the snap shot of opatch applied in SOA Home
export ORACLE_HOME=/apps/oracle/product/Middleware1036/Oracle_SOA
cd /apps/oracle/product/Middleware1036/Oracle_SOA/OPatch
./opatch lsinventory -all

(4) Get the snap shot of opatch applied in OIM Home
export ORACLE_HOME=/apps/oracle/product/Middleware1036/Oracle_OIM
cd /apps/oracle/product/Middleware1036/Oracle_OIM/OPatch
./opatch lsinventory


(4) Get the WebLogic Patch version -
cd /apps/oracle/product/Middleware1036/utils/bsu
./bsu.sh -view -patch_download_dir=/apps/oracle/product/Middleware1036/utils/bsu/cache_dir/ -status=applied -verbose -prod_dir=/apps/oracle/product/Middleware1036/wlserver_10.3/

Sunday, June 12, 2016

Bind TIBCO Queue or Topic with WebLogic Server

Bind TIBCO Queue or Topic with WebLogic Server

Get below details from TIBCO EMS system. Example values are shown for understanding only.
      JMS Server Name : tibjmsnaming://host:port
      Queue Name :  JMS.TEST.Q
      Connection Factory :- QueueConnectionFactory                                      
      UserName: userId
      Password : password

Step 1 - Copy tibjms.jar & jms-2.0.jar in WebLogic domain lib folder and add in class path if required. By default WebLogic picks new jar from domain lib folder after restart.

Step 2 - Perform below Config action in WebLogic to bind the Queue or Topic
(a) Create New JMS Module
WebLogic Path:- Services - Messaging - JMS Modules
Name: TIBCOJMSModule.

Note - Keep all other field as default blank and save it.

(b) Create Foreign Server inside newly created JMS module
Name: TIBCOJMSFServer
JNDI Initial Context Factory: com.tibco.tibjms.naming.TibjmsInitialContextFactory
JNDI Connection URL: tibjmsnaming://host:port
JNDI Properties Credential: password
JNDI Properties: java.naming.security.principal=userId

Note - Put tibjms.jar in WebLogic domain lib folder for initial context factory class.

(c) Create Destinations inside newly created Foreign Server
  Name: TIBCOJMSQ
  Local JNDI Name: JMS.TEST.Q.Local
  Remote JNDI Name: JMS.TEST.Q

  Note - You can keep local JNDI same as remote or different. Use the local name in WebLogic ear xml.

(c) Create Connection Factories inside newly created Foreign Server
  Name: TIBCOJMSConnectionFactory
  Local JNDI Name: QueueConnectionFactoryLocal
  Remote JNDI Name: QueueConnectionFactory
  User Name: userId
  Password: password

  Note - You can keep local JNDI same as remote or different. Use the local name in WebLogic ear xml.


Step 3 - Deploy MDB listener EAR in WebLogic

(a) Sample MDB Listener class
public class MyListenerMDB implements MessageDrivenBean, MessageListener
{
 public void onMessage(Message message)
 {
try {
 TextMessage msg;
 if ((message instanceof TextMessage))
 {      
msg = (TextMessage)message;
System.out.println("Message is : " + msg.getText());
 }
} catch (JMSException e){
 e.printStackTrace();
}
 }

 public void setMessageDrivenContext(MessageDrivenContext messageDrivenContext) {}
 public void ejbRemove() {}
 public void ejbCreate() {}
}

(b) Sample weblogic-ejb-jar file
<weblogic-ejb-jar>
 <weblogic-enterprise-bean>
<ejb-name>My_TIBCO_TEST_MDB</ejb-name>
<message-driven-descriptor>
 <pool>
<max-beans-in-free-pool>1</max-beans-in-free-pool>
<initial-beans-in-free-pool>1</initial-beans-in-free-pool>
 </pool>
 <destination-jndi-name>JMS.TEST.Q.Local</destination-jndi-name>
 <connection-factory-jndi-name>QueueConnectionFactoryLocal</connection-factory-jndi-name>
</message-driven-descriptor>
<enable-call-by-reference>True</enable-call-by-reference>
 </weblogic-enterprise-bean>
</weblogic-ejb-jar>

(c) Sample ejb-jar file [If ejb class file is in package folder structure then give full path like com.test.MyListenerMDB]
<ejb-jar>
<enterprise-beans>
<message-driven>
 <ejb-name>My_TIBCO_TEST_MDB</ejb-name>
 <ejb-class>MyListenerMDB</ejb-class>    
 <transaction-type>Container</transaction-type>    
 <message-driven-destination>
<destination-type>javax.jms.Queue</destination-type>
 </message-driven-destination>    
</message-driven>
 </enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>MDB_Name</ejb-name>
<method-name>*</method-name>
 </method>
 <trans-attribute>NotSupported</trans-attribute>
</container-transaction>
 </assembly-descriptor>
</ejb-jar>

TIBCO Queue Sender and Receiver client

TIBCO Queue Sender and Receiver client

// Required jar - jms-2.0.jar, tibjms.jar

package com.test;

import javax.jms.*;
import com.tibco.tibjms.TibjmsQueueConnectionFactory;

public class TibcoSendListen {

public static void main(String[] args) throws Exception {
        String serverUrl = "tcp://host:port"; // Replace host & Port with actual
        String userName = "userId";           // Replace userId with actual
        String password = "password";         // Replace password with actual
        String queueName = "JMS.TEST.Q";      // Replace Q name with actual
               
        QueueConnectionFactory factory = new TibjmsQueueConnectionFactory(serverUrl);
        QueueConnection connection = factory.createQueueConnection(userName, password);
        QueueSession session = connection.createQueueSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);

        // Sending message into Queue
        Queue queue = session.createQueue(queueName);
        QueueSender sender = session.createSender(queue);
        TextMessage jmsMessage = session.createTextMessage();
        jmsMessage.setText("Sample Message from Rajesh!");
        sender.send(jmsMessage);
        System.out.println("Message Sent Successfully");

        // Reading message from Queue
        QueueReceiver receiver = session.createReceiver(queue);
   connection.start();
   TextMessage message = (TextMessage) receiver.receive();
   System.out.println("Received message: " + message.getText());

   sender.close();
   receiver.close();
   session.close();
        connection.close();
}
}