Showing posts with label OIM getSystemChallengeQuestions. Show all posts
Showing posts with label OIM getSystemChallengeQuestions. Show all posts

Friday, December 7, 2012

API to get all Enabled Security Questions in OIM

The Default getSystemChallengeQuestions() API Provided by OIMClient's UnauthenticatedSelfService will not filter out the disabled security questions. In order to get only the enabled security Questions we can use the following API.

Note: If you specify the order in which the questions have to displayed the following API will return them in the same order.



  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
import Thor.API.Exceptions.tcAPIException;
import Thor.API.Exceptions.tcColumnNotFoundException;
import Thor.API.Exceptions.tcInvalidLookupException;
import Thor.API.Operations.tcLookupOperationsIntf;
import Thor.API.tcResultSet;

import java.util.HashMap;
import java.util.Map;
import java.util.Hashtable;

import oracle.iam.platform.OIMClient;

public class OIMClientTest {

 private OIMClient oimClient;
 private tcLookupOperationsIntf lookupOps = null;

    private void oimLogin(){
        try {
            System.out.println("Prototype for invoking an OIM API from a SOA Composite");
         
            String oimUserName = "xelsysadm";
            char[] oimpass = "password".toCharArray();
         
          
            String oimURL = "t3://oimhost:oimport";
            // set the initial context factory
            String oimInitialContextFactory = "weblogic.jndi.WLInitialContextFactory";
         
            // set up the environment for making the OIM API invocation
            Hashtable env = new Hashtable();
                       
            System.setProperty("APPSERVER_TYPE", "wls");
            System.setProperty("java.security.auth.login.config","C:\\config\\authwl.conf");//server or client
            
            env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_FACTORY_INITIAL, oimInitialContextFactory);
            env.put(oracle.iam.platform.OIMClient.JAVA_NAMING_PROVIDER_URL, oimURL);
            env.put(oracle.iam.platform.OIMClient.APPSERVER_TYPE_WEBLOGIC, "WEBLOGIC");
            
            // get reference to OIMClient and perform login
            
            oimClient = new oracle.iam.platform.OIMClient(env);           
            oimClient.login(oimUserName, oimpass, env);        
            System.out.println("Login Successful");     
         
        } catch (Exception e) {
            e.printStackTrace();
        }  
 } 
      
    public String[] getEnabledQuestions() {
        
        lookupOps = oimClient.getService(tcLookupOperationsIntf.class);
        String[] lookUp = null;
        System.out.println("Inside getEnabledQuestions() : ");
        
        try {
            
            Map poFilters = new HashMap();
            poFilters.put("LKV_DISABLED", "0");
            tcResultSet result = lookupOps.getLookupValues("Lookup.WebClient.Questions", poFilters);  
            
            lookUp = new String[result.getTotalRowCount()];
            
            for (int i = 0; i < result.getTotalRowCount(); i++) {
                result.goToRow(i);                
                lookUp[i] = result.getStringValueFromColumn(3);               
            }
        } catch (tcAPIException e) { 
            System.out.println("tcAPIException: " +e.getMessage()); 
            e.printStackTrace();
           
        } catch (tcInvalidLookupException e) {
            System.out.println("tcInvalidLookupException: " +e.getMessage()); 
            e.printStackTrace();
            
        } catch (tcColumnNotFoundException e) {
            System.out.println("tcColumnNotFoundException: " +e.getMessage()); 
            e.printStackTrace();
          
        } catch (Exception e) {
            System.out.println("GENERIC Exception: "+e.getMessage()); 
            e.printStackTrace();
          
        }
        System.out.println("Number  of  questions returned : " + lookUp.length);   
       
        for (String key : lookUp) {
             System.out.println("Question is: " + key);
        }

        return lookUp;
    }
  
  
 public static void main(String[] args) {
  OIMClientTest test = new OIMClientTest();
 
  test.oimLogin();
  test.getEnalbedQuestions();
        
 }

}

Note: The following Jar files need to be in the class path.


Commons-logging.jar
Eclipselink.jar
Oimclient.jar
Spring.jar
Wlfullclient.jar
Jrf-api.jar

If the Eclipselink.jar from the OIMClient.zip folder is not working get the jar from the MIDDLEWARE_HOME/MiddlewareIDM/oracle_common/modules/oracle.toplink_11.1.1 folder.