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;
}

}