Java8 Lambda Examples


 Overview

    Java8 introduces the new feature named "Lambda Expression". This is not the new term which we are hearing, this is basically related to the same Lambda calculus which we learn in Mathematics. Basically, java supports the lambda expressions through the @FunctionInterface annotation. This enables functional programming in Java.

Functional Interface and the corresponding Annotation

    Java8 introduces lots of Functional Interfaces under java.util.function package. The functional interface is the interface that has only one method called Singel Abstract Method (SAM) interfaces. Any interface which has a single abstract method can be called the functional interface. But if we really want to create the new functional interface you better annotate that class with @FunctionalInterface. Look at the below example.




This package has interfaces that can be used for basic now and then use cases. We rarely need to create the new functional interface but if we want to we should use the @FunctionalInterface annotation.

Lambda Examples

    We will see how we can use the existing functional interfaces to code lambdas.

Predicate<?> : boolean test(T t);
    The predicates represent the operation that tests the conditions. It evaluates the condition on the given object and returns the boolean result,

Function<?> : R apply(T t)
    Functions represent the operations that transform the object to some other type by applying some logic.

Consumer<?> : void accept(T t)
    Consumers represent the operation that takes the single input element and returns nothing.

Supplier<?> : T get()
    The Supplier represents the operation that supplies the objects.

Below is the example of the above.



In the above example, we saw the enhanced version of Consumer lambda that is Method reference (::). When we have a method call in the lambda that exactly has a similar method signature as the used functional interface then we can replace the lambda with method reference to write the concise code.

OIM Logging configurations

To debug any custom-developed scheduled task, event-handlers and plugin need to enable the logging. Use the below procedure to enable logging in OIM11g

  1. Login to EM Console.
  2. Go to Identity And Access folder, under OIM, right-click on the OIM and select Log configuration.
  3. In the logger tab, select Logger with the persistent state as a drop-down value. It will ask the logger name to create give the logger name and the trace option for logger and click apply.
  4. Go to the log files tab and click the create button. 
  5. Give the log file name and the full path. Also, give the details for the logger name and rotation of the logger.
  6. Click ok.
  7. That's it you have created the logger file.
  8. Verify the logger file gets created at the mentioned location.



Can't find resource for bundle java.util.PropertyResourceBundle

Problem: Something went wrong while creating User UDF which results in below error on OIM UI page.

Effect of error on OIM UI :

  1. Cannot create the user from UI.
  2. Cannot search all users or specific users.
  3. The sysadmin console doesn't respond and is blank.
Solution
  1. Export User.xml.
  2. Now open the User.xml file using any text editor and remove the UDF which you have created.
  3. Again import the modified file import export functionality.
[Note: For Export and Import use Export-Import functionality.]


java.Lang.NoClassDefFoundError(oracel/jrf/PortabilityLayerException)

Problem: Error while opening design console. Getting "java.Lang.NoClassDefFoundError".

Solution:

  1. Copy "jrf-api.jar" file from below OIM Server location to "designconsole/ext" directory.                                                                   $MW_HOME/oracle_common/modules/oracle.jrf_11.1.1/jrf-api.jar                                            
  2. Open "classpath.bat" file using any editor and add ";.\ext\jrf-api.jar" in classpath.

Change UDF size OIM 11g R2 PS3


  • Login to sysadmin console. Click on the Sandbox link present at top right corner.

  • It will display below page. Click on the Create Sandbox button.


  • It will ask for the name and description for the sandbox. Enter the appropriate name and description.

  • Click on Save and close button, it will activate the sandbox.

  • Now click on User link from the left panel.

  • It will open all user UDF’s, search for the desired field which is SSN No here.

  • You can see maximum length is set 8 characters.  

  • Change the length to desired values as per your requirement. And click on the Save and Close button.

  • Close the Manage User tab. And again go to Sandbox tab by clicking earlier top sandbox link.

  • Now click on export to take backup of the selected sandbox for future references.
  • Publish the sandbox by clicking Publish Sandbox button. 

OIM schema user password expire

  • Problem: - OIM schema user password expires.
  • Solution:-
    • Check the status of accounts expiration of all schema users by executing following command

select USERNAME, EXPIRY_DATELOCK_DATE, ACCOUNT_STATUS from dba_users where    USERNAME like '%<SCHEMA_PREFIX>%';

    • It will display the account summary information for all schema users.

    • Now change the password those users whose passwords have been expired by executing following command.

         alter user USERNAME identified by <Password>;

Access policy harvesting in OIM 11g

The post describes the Access Policy Harvesting feature introduced in the OIM11gR2PS2 release.

What is Access Policy harvesting?

I will explain it by example.

Let's consider organization XYZ has role-based provisioning / de-provisioning mechanism. The organization has multiple target resources the user may get according to his role. The organization decides to have roles and access policies to make it work. But what about the users existing accounts. Yes, we can reconcile those accounts but they will not be linked to the appropriate access policies. As these accounts are not created through access policy they will never get modified through access policy. (Revoke/Disable)

Access policy harvesting feature enables us to link the existing reconciled accounts to access policies.

How to enable Access Policy harvesting?

By default, this feature is disabled in OIM. Here is the procedure to enable access to policy harvesting.
  1. Set the values of XL.AllowAPHarvesting and XL.AllowAPBasedMultipleAccountProvisioning system properties to TRUE.
  2. Set retrofit flag to YES for all applicable access policies who's accounts needs to be linked.
  3. Populate IT Resource field in access policy by default.
  4. Identify a field on process form as the discriminator and set Account Discriminator property to True. Populate access policy by default for account discriminator field also. (If you want to provision multiple instances of the same resource then identify unique field which distinguishes two resource instances and make it discriminator field otherwise make IT Resource as discriminator field)
How to link the reconciled accounts using Access Policy Harvesting?

Now make sure below sequence must be followed to link the account via harvesting.

  1. Reconcile all accounts for the user(s) which are part of access policy and make sure all accounts get linked to the user(s).
  2. Run 'Evaluate User Policies' job.
  3. Use the below query to check if harvesting is done or not.


You can verify the OIU_PROV_MECHANISM='AP HARVESTED' and OIU.POL_KEY has been populated with some integer value.

 Please see the below result.


In the above result, the only 1st account was reconciled another account is provisioned through access policy. So the account got successfully harvested using access policy harvesting.

Error while creating user java.lang.IllegalArgumentException: Password configuration property is empty

Problem Statement: Error while Provisioning DBAT resource to user throwing java.lang.IllegalArgumentException: Password configuration property is empty.

Solution: Check whether Password parameter in DBAT connector IT Resource has some value, it should not be blank.

Error while creating user java.lang.IndexOutOfBoundsException: Invalid attribute name - DBAT Connector

Problem Statement: Error while Provisioning DBAT resource to user throwing java.lang.IndexOutOfBoundsException: Invalid attribute name

Solution: The error is due to improper mapping in Lookup.<ITResourceName>.UM.ProvAttrMap lookup. Check whether the target DB columns to process form attributes mapping are done properly for all required attributes.

Listener configuration for Oracle 11g OIM Database

After Installing the Oracle 11g OIM Database you need to configure it for accessing it outside with help of third-party applications like SQL Developer

For this, you need to change two configuration files that were created after installation. Download the listener files zip from here. Use IDM as the password to open zip files.

After that change <HOSTNAME>, <PORT> & <SERVICENAME> from those files.

Build ant script to build jars and zip files for scheduled Task.

In Oracle Identity Management for our implementation purpose, we write many schedules. But many times we want the only custom set of classes to register in the system, for that we always need to go and do changes in metadata plugin XML files and then registered the schedulers.

Here a small ant script that we can use to compile a set of custom classes, build Jar, and zip file of those custom classes which we need to register in our environment.


Please find below the folder structure.




  src = Contains all scheduled tasks java classes.
  build = All compile classes will be generated in this folder.
  lib = Jar file will be stored here.
  META-INF your custom scheduled task XML

Steps to be done before running the script.
  1. You need to create a tmp folder.
  2. Prepare your custom set of metadata and plugin XML like scheduledTask_Set1.xml and plugin_Set1.xml and put those XMLs in the tmp folder.
  3. The script will runtime pick that XMLs according to target which we'll be running.

build.xml

<project name="MyCustomScheduledTasks" basedir="." default="main">


 <property name="src.dir"     value="src"/>

 <property name="build.dir"   value="build"/>
 <property name="classes.dir" value="${build.dir}/classes"/>
 <property name="lib.dir" value="lib"/>
 <property name="meta-inf.dir" value="META-INF"/>
 <property name="tmp.dir" value="tmp"/>
 <property name="set1.dir" value="set1"/>
 <property name="set2.dir" value="set2"/>
<property file ="build.properties"/>

 <target name="clean">

  <delete dir="${build.dir}"/>
  <delete dir="${meta-inf.dir}"/>
  <delete dir="${lib.dir}"/>
  <delete file="plugin.xml"/>
 </target>

 <target name="compile">

  <mkdir dir="${classes.dir}"/>
  <javac srcdir="${src.dir}" destdir="${classes.dir}"/>
 </target>

 <target name="set1" depends="compile">

  <mkdir dir="${lib.dir}" />
  <mkdir dir="${meta-inf.dir}" />
  <mkdir dir="${set1.dir}" />
  <jar destfile="${lib.dir}/${ant.project.name}.jar" basedir="${classes.dir}" incluedes="${set1.classes}">
  </jar>
  <copy file="${tmp.dir}/plugin_Set1.xml" tofile="plugin.xml" />
  <copy file="${tmp.dir}/ScheduledTasks_Set1.xml" tofile="${meta-inf.dir}/ScheduledTasks.xml" />
  <zip destfile="${set1.dir}/${ant.project.name}.zip" basedir=".">
   <include name="plugin.xml" />
   <include name="${meta-inf.dir}/ScheduledTasks.xml" />
   <include name="${lib.dir}/${ant.project.name}.jar" />
  </zip>
 </target>

 <target name="set2" depends="compile">

  <mkdir dir="${lib.dir}" />
  <mkdir dir="${meta-inf.dir}" />
  <mkdir dir="${set2.dir}" />
  <jar destfile="${lib.dir}/${ant.project.name}.jar" basedir="${classes.dir}" includes="${set2.classes}" >
  </jar>
  <copy file="${tmp.dir}/plugin_Set2.xml" tofile="plugin.xml"/>
  <copy file="${tmp.dir}/ScheduledTasks_Set2.xml" tofile="${meta-inf.dir}/ScheduledTasks.xml"/>
  <zip destfile="${set1.dir}/${ant.project.name}.zip" basedir=".">
   <include  name="plugin.xml"/>
   <include name="${meta-inf.dir}/ScheduledTasks.xml"/>
   <include name="${lib.dir}/${ant.project.name}.jar"/>
  </zip>
 </target>

 <target name="main" depends="clean"/>


</project>

In build.properties file you have to mention the comma-separated set of custom classes.

build.properties looks like this,

set1.classes com/myTask/DisableUser.class,com/myTask/CreateUser.class

set2.classes com/myTask/EnableUser.class,com/myTask/UpdateUserParameters.class

I am still working on this script. If any suggestions then those are always welcome.


Happy Coding. 



How to add new Tab in OIM PS3 and How to hide it from end user

  1. Login to identity console.
  2. Create & activate sandbox in Identity console.
  3. Go to Manage->users. List of users will be displayed
  4. Click on user login of any user and you will be able to see details of that particular user
  5. You will see various tabs on that page like 'Attributes' 'Roles' 'Entitlements' 'Accounts' 'Organizations' 'Admin Roles'
  6. Now we need to add one new tab named “Personal Information” after “Admin Roles” tab
  7. Click on customize button
  8. Click on structure present on the leftmost upper corner
  9. Click on the area where you want to add a new tab
  10. A prompt window will open then click on Edit.
  11. On the right side of the window, you will see the below vertical window
  12. In above vertical window we can see the parent tab i.e. PanelTabbedAbove
  13. Click on it and then click on the edit button which is the leftmost second option on customize page.
  14. Below window will open.
  15. Click on Add Tab button
  16. New Tab gets created. Change the name of it.
  17.       Enter the name as 'Personal Information'
  18. Click on Apply
  19.       As we want this tab at last position then use Reorder the tabs field. with the help of down arrows, we can adjust the position of the newly created tab.
  20.       Then click on OK.
  21.       You will see that the new tab is added on the page after the “Admin Roles” tab

  1.    To add information or attributes under  this new tab do the following steps
  • Click on ‘Personal Information’ in customize window
  • Click on ‘+’ i.e. add the symbol. Below window will appear

  • Open Web components tab which is the last option in the list

  • Select and add Panel Group Layout option from the list
  • Then click on this added layout tab and click on edit

  • Select the layout as vertical. 
  • Apply and OK
  • Click on the layout that we have rightly created and click on add symbol
  • Go to web components and add ‘show header details
  •  Change the name of the header by clicking on edit symbol
  • Give the name ‘Personal Information’ instead of ‘Header
  • Apply and OK
  • Now add ‘PanelFormLayout’ same manner as we added ‘ShowDetailHeader
  • Edit PanelFormLayout as below
  • Apply and OK
  • For adding attributes under this tab click on PanelFormLayout and click on add
  • Add Panel label with the message from Web Components
  • Change the name of that label. Here label is the name of an attribute that we want to add under the tab 'Personal Information'
  • Apply and OK
  • Click on PanelLabelAndMessage tab and click on add
  • Open Data Component-Manage Users
  • Open UserVO1 tab
  • Select the required attribute from the list
  •  Add that attribute
     
  • Here I am selecting 'City' attribute
  • Select ADF OutputText from list
                           
                             
  •  We can add any number of attributes that we want to add under 'Personal Information' tab i.e. First Name, Common Name, Email, etc. by following above-mentioned procedure.

2.  To hide Tab from End User do the following steps

  • Click on the ‘Personal Information’ tab
  • Click on edit and scroll down
  • Click on show component
  • Click on Expression Builder
  • Remove true and paste below EL(Expression Language)
  • #{oimcontext.currentUser.roles['SYSTEM ADMINISTRATORS'] != null}
  • Click on Test
  • After successful test click on ok
  • Click on apply and OK
  • Close customization window
  • Publish sandbox
  • 'Personal Information' tab only visible to Administrator. It will be invisible for end users.




Login fails in OIM

Login fails in OIM and if sysadmin user is locked 

  1. Shut down all servers.
  2. Go to /home/oracle/Oracle/Middleware/user_projects/domains/base_domain/servers
    Delete all  tmp, logs, data/store files from Adminserver, oim_server1, soa_server1
  3. Check the boot.properties file present in/home/oracle/Oracle/Middleware/user_projects/domains/base_domain/servers/security 
    folder of all servers.
    replace username with weblogic and password with your server
  4. Now login to SQL and execute follwoing command.
    update DEV_OIM.usr set usr_locked=0, usr_login_attempts_ctr=0 where usr_login='XELSYSADM';
  5. After doing all steps start all servers.

Java Regex

In this post, you will learn Java REGX and its example.

regular expression defines a pattern for a String. Regular Expressions can be used to search, edit or manipulate text. Regular expressions are not language specific but they differ slightly for each language. 

Here are some rules to be followed while creating a regular expression.







E.g.

Regular expression for validating the email id is:

^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$


^ // start of the line
[_A-Za-z0-9-\\+]+ //   must start with string in the bracket [ ], must contains one or more (+)
( //      start of group #1
  \\.[_A-Za-z0-9-]+ //     follow by a dot "." and string in the bracket [ ], must contains one or more (+)
)* //     end of group #1, this group is optional (*)
  @ //     must contains a "@" symbol
   [A-Za-z0-9-]+              //     follow by string in the bracket [ ], must contains one or more (+)
    ( //      start of group #2 - first level TLD checking
     \\.[A-Za-z0-9]+   //      follow by a dot "." and string in the bracket [ ], must contains one or more (+)
    )* //       end of group #2, this group is optional (*)
    ( //       start of group #3 - second level TLD checking
     \\.[A-Za-z]{2,}           //       follow by a dot "." and string in the bracket [ ], with minimum length                                                    of 2
    ) //       end of group #3
$         //       end of the line


Exporting and Importing Metadata files in Oracle Identity Manager


1.      Go to $OIM_ORACLE_HOME/server/bin.
(Set $OIM_ORACLE_HOME= /home/oracle/Oracle/Middleware/Oracle_IDM1)

2.      Edit the weblogic.properties file.

3.      To Export file change the following fields.

wls_servername=oim_server1
application_name=OIMMetadata
metadata_from_loc=@From_location
metadata_to_loc=<path where to export>
metadata_files=<relative path to file>

4.      Then run ./weblogicExportMetadata.sh
Username= weblogic
Password= (your password)
URL: t3://Host:port (e.g. t3://host:14000)


5.      Then again to import change following fields in weblogic.properties.

wls_servername=oim_server1
application_name=OIMMetadata
metadata_from_loc=”path from where to import”
metadata_to_loc=@To_location

metadata_files=<file name>

For importing you have to give the path from where you want to import the file