OAAM 11g API code to create & configure security questions for user


import java.util.ArrayList;
import java.util.List;

import com.bharosa.vcrypt.auth.intf.*;
import com.bharosa.vcrypt.auth.util.VCryptAuthUtil;
import com.bharosa.vcrypt.common.util.VCryptResponse;

import com.bharosa.vcryptclient.proxy.exception.BharosaProxyException;
import com.bharosa.vcryptclient.proxy.intf.BharosaProxy;

/**
 * @author pokuri
 *
 */
public class CreateUser {

private BharosaProxy proxy = null;

public static void main(String[] args)
{
CreateUser cu = new CreateUser();
String response = null;
try
{
response = cu.createUser("pressi", "Default");
//response = cu.checkQuestionsStatus("siva.pokuri");
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("RESPONSE " + response);
}
   
    public String checkQuestionsStatus(String userName)
    {
    VCryptAuthUser user = null;

    System.out.println("Checking user: " + userName);
    user = new VCryptAuthUser();

user.setLoginId(userName);

try {

System.out.println("Questions Status " + user.getRegistrationStatus());

} catch (Exception e) {
System.out.println("Exception " +e);
return "QA_STATUS_CHECK_FAILED";
}
return "CHECKED_QA_STATUS";
    }
   
public String createUser(String userName, String primaryGroupName)
{
proxy = BharosaProxySingleton.getProxyInstance();

// try to find the user record in OAAM
   VCryptAuthUser user = null;

   System.out.println("Creating user: " + userName);
   user = new VCryptAuthUser();
   
   try{
    user.setLoginId(userName.trim());
   }
   catch (Exception e) {
System.out.println("Exception " + e);
}
   user.setCustomerId(userName.trim());

   user.setCustomerGroupId(primaryGroupName.trim());
   try
   {
    user = proxy.createUser(user);
   }
catch (Exception e)
{
System.out.println("Exception " +e);
return "CREATE_USER_FAILED";
}
proxy.setUser(user);

int status = proxy.getUserStatus(userName.trim());

System.out.println("User Status  before Security Questions ---- >> " + status);

String questionId1 = "41";
String questionText1 = "Who was your childhood hero?";
String answer1 = "pilot1";
String questionId2 = "42";
String questionText2 = "What is the name of your favourite childhood teacher?";
String answer2 = "pilot2";
String questionId3 = "43";
String questionText3 = "What was your dream job as a child?";
String answer3 = "pilot";
     
VCryptQuestion question1 = new VCryptQuestion();
VCryptQuestion question2 = new VCryptQuestion();
VCryptQuestion question3 = new VCryptQuestion();

List<String> answerList = new ArrayList<String>();
List<String> answerList1 = new ArrayList<String>();
List<String> answerList2 = new ArrayList<String>();

question1.setQuestionId(new Long(questionId1.trim()));
question1.setQuestion(questionText1.trim());
answerList.add(answer1.trim());
question1.setAnswerList(answerList);

question2.setQuestionId(new Long(questionId2.trim()));
question2.setQuestion(questionText2.trim());
answerList1.add(answer2.trim());
question2.setAnswerList(answerList1);
     
question3.setQuestionId(new Long(questionId3.trim()));
question3.setQuestion(questionText3.trim());
answerList2.add(answer3.trim());
question3.setAnswerList(answerList2);
     
try
{
VCryptAuth auth = VCryptAuthUtil.getVCryptAuthInstance();
VCryptAuth auth1 = VCryptAuthUtil.getVCryptAuthInstance();
VCryptAuth auth2 = VCryptAuthUtil.getVCryptAuthInstance();

VCryptResponse vr = null;
VCryptResponse vr1 = null;
VCryptResponse vr2 = null;

vr = auth.addQuestion(userName.trim(), question1);
vr1 = auth1.addQuestion(userName.trim(), question2);
vr2 = auth2.addQuestion(userName.trim(), question3);

System.out.println("Response Code " + vr.getResponseCode());
System.out.println("Response Code " + vr1.getResponseCode());
System.out.println("Response Code " + vr2.getResponseCode());

System.out.println("Successfully Created User & configured Sequrity questions");

proxy.setUserStatus(userName.trim(), 2);

System.out.println("User "+userName+" Status -->>"+proxy.getUserStatus(userName.trim()));

}
catch (Exception e)
{
System.out.println("Create user failed!!!! " + e);
}
return "CREATE_USER_SUCCESS";
}


}

-- Siva Pokuri

Comments

  1. Hi Siva,

    I am trying to create a User and set the challenge questions but getting the below error.

    saUserId=null, externalUserId='test8', externalGroupName='Default', loginId='test8', cookieSet=null, authUser=VCryptAuthUser{loginId='junk8', bharosaUserId='10004', customerGroupId='Default', customerId='test8', fullName='null', roles=null, securityPreferences={imagePath=$base/keypad/200207596-001.jpg, status=1, personalNote=fairly sea, passwordUpdateTime=1451543359574, userType=1, isLocked=false, imageStatus=1, phraseStatus=1, secondFactor=0, passwordStatus=1, isPinEnabled=false, pinUpdateTime=1451543359574, questionStatus=1, authType=2, pinStatus=1, authMode=0}}, questionText=null, off set='-5', map ={}, challengeFailureCntForSession = 0, challengeSuccesscntForSession = 0, challengeCntForSession = 0} , response=VCryptResponse{success=false, timeStamp=Thu 01:29:59 EST 2015, responseCode='52', errorMessage='Question (id=1) is not present in the pick set', errorMessageRBKey='kba.question.validation.questionNotInPickset.error', errorMessageParams='[Ljava.lang.String;@7444636', server='sampleHost/127.0.0.1', extendedDataMap=null, sess='null', transactionResponse='null}>


    Any Suggestions.

    ReplyDelete
  2. Hi Siva, Great article. Please could you provide your classpath used for compile-time and run-time

    ReplyDelete
    Replies
    1. Try running with jar files in class path

      commons-lang-2.0.jar
      iam-platform-utils.jar
      oaam_core.jar
      oaam_custom.properties
      oaam_soap_client.jar
      oaam_uio.jar
      oimclient.jar
      wlfullclient.jar
      commons-collections-3.1.jar
      fmw_audit.jar
      javax.persistence_1.0.0.0_1-0-2.jar
      jps-api.jar
      ojdbc5.jar
      org.eclipse.persistence_1.0.0.0_1-1-0.jar
      webserviceclient+ssl.jar
      wlclient.jar
      wljmxclient.jar
      xmlparserv2.jar

      -- Siva Pokuri.

      Delete
  3. Hi Siva -

    We need to implement the same, but when trying to execute getting below error. Can you please provide some more detailed steps so that I can get it executed from the eclipse. What all configuration is required to execute this code from eclipse.

    Any quick guidance will be highly appreciated !!

    Error: when trying to execute from the eclipse

    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.UserDefEnumFactory
    INFO: Creating new instance of UserDefEnumFactory
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.UserDefEnumFactory
    INFO: Loading Enums...
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfig
    INFO: Starting Initialization of BharosaConfig... hashCode [8297698] initDone [false] current thisInstance [null]
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfigCommonImpl
    INFO: Constructing BharosaConfigCommonImpl : with BharosaConfigLoadIntf [com.bharosa.common.util.BharosaConfigLoadPropsImpl@164debb]
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfigLoadPropsImpl
    INFO: Reloading BharosaConfig property files
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfigLoadPropsImpl
    INFO: Unable to load properties from file=oaam_core.properties
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfigLoadPropsImpl
    SEVERE: Couldn't load properties file oaam_core.properties
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfigLoadPropsImpl
    INFO: Unable to load properties from file=oaam_asa.properties
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfigLoadPropsImpl
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.UserDefEnum
    WARNING: Element id DESede not found for enum bharosa.cipher.encryption.algorithm.enum
    java.lang.Throwable
    at com.bharosa.common.util.UserDefEnum.getElementValue(UserDefEnum.java:586)
    at com.bharosa.common.util.UserDefEnum.getElementValue(UserDefEnum.java:614)

    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.UserDefEnum
    WARNING: Value -1 in enum bharosa.cipher.encryption.algorithm.enum not found. propertyName=keyRetrieval.classname
    java.lang.NullPointerException
    at com.bharosa.common.util.UserDefEnum.getPropertyByElementValue(UserDefEnum.java:1142)
    at com.bharosa.common.util.UserDefEnum.getPropertyByElementValue(UserDefEnum.java:1189)
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaCipher
    SEVERE: getSystemCipher classnull, lEncAlgo=DESede, lEncAlgoId=-1
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfigLoadCommonImpl
    WARNING: Error with encrypted properties
    java.lang.RuntimeException: Could not construct class [null]
    at com.bharosa.common.util.BharosaCipher.getSystemCipher(BharosaCipher.java:300)
    at com.bharosa.common.util.BharosaConfigLoadCommonImpl.decryptProperties(BharosaConfigLoadCommonImpl.java:79)
    at com.bharosa.common.util.BharosaConfigLoadCommonImpl.decryptProperties(BharosaConfigLoadCommonImpl.java:66)

    INFO: Loading class com.bharosa.vcrypt.auth.impl.VCryptAuthImpl
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.UserDefEnum
    WARNING: Enum id vcrypt.user.image.status.enum not found
    java.lang.Throwable
    at com.bharosa.common.util.UserDefEnum.getElementValue(UserDefEnum.java:617)
    at com.bharosa.vcrypt.auth.impl.VCryptAuthImpl.(VCryptAuthImpl.java:97)
    at java.lang.Class.forName0(Native Method)

    Thanks,
    Rakesh

    ReplyDelete
  4. Hi Siva - can you please respond to my last query, its very urgent. Thanks for your understading.

    ~Rakesh

    ReplyDelete
  5. Hi Siva - getting below error when trying to execute from eclipse or OAAM server ..

    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.UserDefEnumFactory
    INFO: Creating new instance of UserDefEnumFactory
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.UserDefEnumFactory
    INFO: Loading Enums...
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfig
    INFO: Starting Initialization of BharosaConfig... hashCode [8297698] initDone [false] current thisInstance [null]
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfigCommonImpl
    INFO: Constructing BharosaConfigCommonImpl : with BharosaConfigLoadIntf [com.bharosa.common.util.BharosaConfigLoadPropsImpl@164debb]
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfigLoadPropsImpl
    INFO: Reloading BharosaConfig property files
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfigLoadPropsImpl
    INFO: Unable to load properties from file=oaam_core.properties
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfigLoadPropsImpl

    SEVERE: Enum element bharosa.cipher.encryption.algorithm.enum.DESede_config doesn't have integer value. value=null
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.UserDefEnumFactory
    INFO: Loaded 1 user defined enums!!!
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.UserDefEnum
    WARNING: Element id DESede not found for enum bharosa.cipher.encryption.algorithm.enum
    java.lang.Throwable
    at com.bharosa.common.util.UserDefEnum.getElementValue(UserDefEnum.java:586)
    at com.bharosa.common.util.UserDefEnum.getElementValue(UserDefEnum.java:614)
    at com.bharosa.common.util.BharosaCipher.getSystemCipher(BharosaCipher.java:283)
    at com.bharosa.common.util.BharosaConfigLoadCommonImpl.decryptProperties(BharosaConfigLoadCommonImpl.java:79)
    at com.bharosa.common.util.BharosaConfigLoadCommonImpl.decryptProperties(BharosaConfigLoadCommonImpl.java:66)
    at com.bharosa.common.util.BharosaConfigCommonImpl.decryptProperties(BharosaConfigCommonImpl.java:40)

    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.UserDefEnum
    WARNING: Value -1 in enum bharosa.cipher.encryption.algorithm.enum not found. propertyName=keyRetrieval.classname
    java.lang.NullPointerException
    at com.bharosa.common.util.UserDefEnum.getPropertyByElementValue(UserDefEnum.java:1142)
    at com.bharosa.common.util.UserDefEnum.getPropertyByElementValue(UserDefEnum.java:1189)


    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaCipher
    SEVERE: getSystemCipher classnull, lEncAlgo=DESede, lEncAlgoId=-1
    Feb 10, 2016 3:46:20 PM com.bharosa.common.util.BharosaConfigLoadCommonImpl
    WARNING: Error with encrypted properties
    java.lang.RuntimeException: Could not construct class [null]
    at com.bharosa.common.util.BharosaCipher.getSystemCipher(BharosaCipher.java:300)
    at com.bharosa.common.util.BharosaConfigLoadCommonImpl.decryptProperties(BharosaConfigLoadCommonImpl.java:79)
    at com.bharosa.common.util.BharosaConfigLoadCommonImpl.decryptProperties(BharosaConfigLoadCommonImpl

    Any help will be highly appreciated.

    Thanks,
    Rakesh

    ReplyDelete
    Replies
    1. Make sure you have below list of jar files in your application class path.

      commons-lang-2.0.jar
      iam-platform-utils.jar
      oaam_core.jar
      oaam_custom.properties
      oaam_soap_client.jar
      oaam_uio.jar
      oimclient.jar
      wlfullclient.jar
      commons-collections-3.1.jar
      fmw_audit.jar
      javax.persistence_1.0.0.0_1-0-2.jar
      jps-api.jar
      ojdbc5.jar
      org.eclipse.persistence_1.0.0.0_1-1-0.jar
      webserviceclient+ssl.jar
      wlclient.jar
      wljmxclient.jar
      xmlparserv2.jar

      And i think from the error message i see that it's not able to load oaam_core.properties file. try add that in your class path too and test again.

      -- Siva Pokuri.

      Delete
  6. Hi,

    I am trying to write a simple code for OAAM to generate OTP and validate against OAAM.
    can you please guide how to proceed for that? do you have any saple code for this?

    ReplyDelete
  7. Hi Siva -

    We need to implement the same to get user session details, but when trying to execute getting below error. Can you please provide some more detailed steps so that I can get it executed from the eclipse. What all configuration is required to execute this code from eclipse.

    Any quick guidance will be highly appreciated !!

    oracle.security.jps.internal.config.util.BootstrapConfigurationUtil getCredentialFromBootstrapWallet
    SEVERE: A password credential is expected; instead found null for alias BOOTSTRAP_JPS and key bootstrap_tY1LLw8JRu1sZVb0m8mh/vpA3pA= at location C:\JDeveloper\mywork\oaamtest\oaamtest\config\bootstrap.
    May 29, 2017 11:25:23 AM oracle.security.jps.internal.config.util.BootstrapConfigurationUtil getLdapBootstrapCredential
    SEVERE: Ldap bootstrap credential retrieval failed. Reason:oracle.security.jps.JpsException: JPS-01016: A password credential is expected; instead found null for alias BOOTSTRAP_JPS and key bootstrap_tY1LLw8JRu1sZVb0m8mh/vpA3pA= at location C:\JDeveloper\mywork\oaamtest\oaamtest\config\bootstrap..
    May 29, 2017 11:25:23 AM oracle.security.jps.internal.credstore.ldap.LdapCredentialStore getBootstrapCredentials
    SEVERE: JPS-00071: Ldap bootstrap credential retrieval failed. Reason:oracle.security.jps.JpsException: JPS-01016: A password credential is expected; instead found null for alias BOOTSTRAP_JPS and key bootstrap_tY1LLw8JRu1sZVb0m8mh/vpA3pA= at location C:\JDeveloper\mywork\oaamtest\oaamtest\config\bootstrap..
    oracle.security.jps.JpsException: JPS-00071: Ldap bootstrap credential retrieval failed. Reason:oracle.security.jps.JpsException: JPS-01016: A password credential is expected; instead found null for alias BOOTSTRAP_JPS and key bootstrap_tY1LLw8JRu1sZVb0m8mh/vpA3pA= at location C:\JDeveloper\mywork\oaamtest\oaamtest\config\bootstrap..
    at oracle.security.jps.internal.config.util.BootstrapConfigurationUtil.getLdapBootstrapCredential(BootstrapConfigurationUtil.java:564)
    at oracle.security.jps.internal.credstore.ldap.LdapCredentialStore$1.run(LdapCredentialStore.java:127)
    at oracle.security.jps.internal.credstore.ldap.LdapCredentialStore$1.run(LdapCredentialStore.java:125)
    at java.security.AccessController.doPrivileged(Native Method)

    ReplyDelete
  8. Hi Siva,

    It appears that BharosaProxySingleton.getProxyInstance(); is deprecated in PS3. Do you know if there is another api for this?

    Thanks
    Pratima

    ReplyDelete
  9. I was integrated IDM(v11.1.1.1.1) Signup Module with java webapplication. Now planning to upgrade IDM(v11.1.2.0.0). I see following changes in OAAM API.
    OAAM API Changes:
    1. Removed BharosaSession
    2. Removed BharosaHelper.

    I successfully upgraded source code without BharosaSession& BharosaHelper and used following method to retireve customerId of user account.

    String customerId=VCryptAuthUtil.getVCryptAuthInstance().getUserByLoginId(userName).getCustomerId(); -- Calling this code snippet after creating account in OIM.

    Above code snippet is returning null value. Can you please provide me the way to retrieve customerId from OAAM.

    Also provide me the way to set randomImageAndCaption in OAAM.

    Thanks in advance...

    Thanks,
    Ranga Rao

    ReplyDelete

Post a Comment