OIM OIA Custom Code Integration via Web Services

This post covers the OIM OIA custom integration via web services.
What this integration code does is listen for create or modify event in OIM and if that change is detected for a user profile then propagates it to OIA user in real time.

If a user is created in OIM, then create the user in OIA.
If a user is modified in OIM, then modify the user in OIA. 

OIM changes are detected via Event Handler.
OIA web services are invoked to create or modify the user in OIA.

OIM Event Handler

  1 package com.dubey.deepak.oim.oia.intg;
  2 
  3 import Thor.API.Exceptions.tcAPIException;
  4 import Thor.API.Exceptions.tcStaleDataUpdateException;
  5 import Thor.API.Exceptions.tcUserNotFoundException;
  6 
  7 import com.dubey.deepak.oim.oia.intg.ItResourceObj;
  8 import com.dubey.deepak.oim.oia.intg.OIADBConnector;
  9 import com.dubey.deepak.oim.oia.intg.OIAIntegrationConstants;
 10 import com.dubey.deepak.oim.oia.intg.OIARequest;
 11 import com.dubey.deepak.oim.oia.intg.OIA_OIM_Util;
 12 import com.thortech.util.logging.Logger;
 13 import com.thortech.xl.client.events.tcBaseEvent;
 14 import com.thortech.xl.dataaccess.tcDataProvider;
 15 import com.thortech.xl.dataobj.tcDataObj;
 16 
 17 import java.util.HashMap;
 18 import java.util.Iterator;
 19 import java.util.Map;
 20 import java.util.Set;
 21 
 22 import Thor.API.Operations.tcUserOperationsIntf;
 23 import Thor.API.tcResultSet;
 24 import Thor.API.tcUtilityFactory;
 25 
 26 public class OIAEventHandler extends tcBaseEvent {
 27 
 28  private static Logger logger = OIAIntegrationConstants.logger;
 29 
 30  public OIAEventHandler() {
 31   super();
 32   setEventName("OIAEventHandler");
 33  }
 34 
 35  protected void implementation() throws Exception {
 36   logger.debug("oia event handler");
 37   tcDataObj dataObj = getDataObject();
 38   tcDataProvider dataProvider = getDataBase();
 39   OIA_OIM_Util oIA_OIM_Util = new OIA_OIM_Util();
 40   ItResourceObj itResourceObj = oIA_OIM_Util.initITResourceObj(
 41     dataProvider, OIAIntegrationConstants.ITRESOURCENAME);
 42   Map oimOiaAttributeMap = oIA_OIM_Util.loadMetaDataLookup(dataProvider);
 43   logger.debug("   oimOiaAttributeMap  --->  " + oimOiaAttributeMap);
 44   Map<String, String> oiaAttributeValueMap = getOimAttributeValues(
 45     dataObj, oimOiaAttributeMap);
 46   logger.debug("   oiaAttributeValueMap  --->  " + oiaAttributeValueMap);
 47   OIARequest oIARequest = new OIARequest(itResourceObj);
 48   try {
 49    String oimLoginName = dataObj
 50      .getString(OIAIntegrationConstants.OIMUSERLOGINATTRIBUTE);
 51    String oldOIMLoginName = dataObj
 52      .getCurrentString(OIAIntegrationConstants.OIMUSERLOGINATTRIBUTE);
 53    logger.debug("oldOIMLoginName -> " + oldOIMLoginName);
 54    if (!(oimLoginName.equalsIgnoreCase(oldOIMLoginName))) {
 55     OIADBConnector oIADBConnector = new OIADBConnector();
 56     if (oIADBConnector.updateUserName(itResourceObj,
 57       oldOIMLoginName, oimLoginName)) {
 58      logger.debug("User Name renamed in OIA");
 59     }
 60    }
 61    String oimUsrKey = dataObj
 62      .getString(OIAIntegrationConstants.OIMUSERKEYATTRIBUTE);
 63    String oiaID = dataObj
 64      .getString(OIAIntegrationConstants.OIAIDATTRIBUTE);
 65    logger.debug("oimLoginName---->" + oimLoginName);
 66    oiaAttributeValueMap.put(OIAIntegrationConstants.USR_KEY_ATTRIBUTE,
 67      oimUsrKey);
 68 
 69    if ((oiaID != null) && (!(oiaID.trim().equalsIgnoreCase("")))) {
 70     logger.debug("OIM User already linked with OIA User so calling updateUser web service");
 71     Map oiaUsrMap = oIARequest.findUser(oimLoginName);
 72     boolean isUserUpdated = oIARequest.updateUser(oimLoginName,
 73       oiaUsrMap, oiaAttributeValueMap);
 74     if (isUserUpdated) {
 75      logger.debug("User Updated in OIA");
 76     }
 77    } else {
 78     logger.debug("OIM User not linked with OIA User so calling createUser web service");
 79     boolean isUserCreated = oIARequest.createUser(oimLoginName,
 80       oiaAttributeValueMap);
 81     if (isUserCreated) {
 82      logger.debug("User Created in OIA");
 83      OIADBConnector oIADBConnector = new OIADBConnector();
 84      oiaID = oIADBConnector.getID(itResourceObj, oimLoginName);
 85      logger.debug("oiaID recieved from oia-->" + oiaID);
 86      boolean isUserUpdInOIM = updateUserInOIM(dataProvider,
 87        oimLoginName, oiaID);
 88      if (isUserUpdInOIM) {
 89       logger.debug("OIA ID Set for the user in OIM");
 90      }
 91     }
 92    }
 93    logger.debug("Exiting implementation() of OIAEventHandler");
 94   } catch (Exception ex) {
 95    logger.error("Error in main()---->" + ex.getMessage());
 96    ex.printStackTrace();
 97   } finally {
 98    if ((dataProvider != null) && dataProvider.isOpen()) {
 99     dataProvider.close();
100    }
101    if (dataObj != null) {
102     dataObj = null;
103    }
104   }
105   return;
106  }
107 
108  private Map<String, String> getOimAttributeValues(tcDataObj dataObj,
109    Map oiaOimAttributeMap) {
110   logger.debug("Entering getOimAttributeValues(tcDataObj dataObj, Map oiaOimAttributeMap) of OIAEventHandler");
111   Map<String, String> oiaAttributeMap = null;
112   try {
113    oiaAttributeMap = new HashMap<String, String>();
114    Set set = oiaOimAttributeMap.keySet();
115    Iterator iterator = set.iterator();
116    while (iterator.hasNext()) {
117     String oiaAttrKey = iterator.next().toString();
118     String oimAttrName = (String) oiaOimAttributeMap
119       .get(oiaAttrKey);
120     String oimAttrValue = dataObj.getString(oimAttrName);
121     logger.debug("oiaAttrKey->" + oiaAttrKey);
122     logger.debug("oimAttrName->" + oimAttrName);
123     logger.debug("oimAttrValue->" + oimAttrValue);
124     oiaAttributeMap.put(oiaAttrKey.toString(),
125       oimAttrValue.toString());
126 
127    }
128   } catch (Exception e) {
129    logger.error("Error in getOimAttributeValues(Map oiaOimAttributeMap) ->"
130      + e.getMessage());
131    e.printStackTrace();
132   }
133   logger.debug("Exiting getOimAttributeValues(tcDataObj dataObj, Map oiaOimAttributeMap) of OIAEventHandler");
134   return oiaAttributeMap;
135  }
136 
137  public boolean updateUserInOIM(tcDataProvider dataProvider,
138    String oimLoginName, String oiaID) {
139   boolean flag = false;
140   tcUserOperationsIntf userIntf = null;
141   try {
142    userIntf = (tcUserOperationsIntf) tcUtilityFactory.getUtility(
143      dataProvider, "Thor.API.Operations.tcUserOperationsIntf");
144    Map mhSearchCriteria = new HashMap();
145    mhSearchCriteria.put("Users.User ID", oimLoginName);
146    tcResultSet userRSet = userIntf.findUsers(mhSearchCriteria);
147    int rowcount = userRSet.getRowCount();
148    if (rowcount == 1) {
149     HashMap phAttributeList = new HashMap();
150     phAttributeList.put(OIAIntegrationConstants.OIAIDATTRIBUTE,
151       oiaID);
152     userRSet.goToRow(0);
153     userIntf.updateUser(userRSet, phAttributeList);
154    }
155   } catch (tcUserNotFoundException ex) {
156    logger.error("Exception occurred --->" + ex.getMessage());
157   } catch (tcStaleDataUpdateException ex) {
158    logger.error("Exception occurred --->" + ex.getMessage());
159   } catch (tcAPIException ex) {
160    logger.error("Exception occurred --->" + ex.getMessage());
161   } catch (Exception ex) {
162    logger.error("Exception occurred --->" + ex.getMessage());
163   } finally {
164    if (userIntf != null) {
165     userIntf.close();
166    }
167   }
168   return flag;
169  }
170 }
171 
 
 
OIARequest class contains webservices code  it invokes the OIA webservices
 
  1 package com.dubey.deepak.oim.oia.intg;
  2 
  3 import java.net.URL;
  4 import java.util.HashMap;
  5 import java.util.Iterator;
  6 import java.util.Map;
  7 import java.util.Set;
  8 
  9 import javax.xml.namespace.QName;
 10 import javax.xml.soap.MessageFactory;
 11 import javax.xml.soap.Node;
 12 import javax.xml.soap.SOAPBody;
 13 import javax.xml.soap.SOAPBodyElement;
 14 import javax.xml.soap.SOAPConnection;
 15 import javax.xml.soap.SOAPConnectionFactory;
 16 import javax.xml.soap.SOAPElement;
 17 import javax.xml.soap.SOAPFault;
 18 import javax.xml.soap.SOAPHeader;
 19 import javax.xml.soap.SOAPMessage;
 20 
 21 import org.w3c.dom.NodeList;
 22 
 23 import com.thortech.util.logging.Logger;
 24 
 25 //import com.thortech.util.logging.Logger;
 26 
 27 public class OIARequest {
 28 
 29  private static Logger logger = OIAIntegrationConstants.logger;
 30 
 31  private String ENDPOINT_URL = null;
 32 
 33  private String OIA_SYSACCOUNT = null;
 34  private String OIA_PWD = null;
 35 
 36  public OIARequest(ItResourceObj itResourceObj) {
 37   // logger.debug("Entering OIARequest");
 38 
 39   String host = itResourceObj.getAppHost();
 40   String port = itResourceObj.getAppPort();
 41   ENDPOINT_URL = "http://" + host + ":" + port + "/rbacx/ws/userService";
 42   OIA_SYSACCOUNT = itResourceObj.getAppUser();
 43   OIA_PWD = itResourceObj.getAppUserPassword();
 44  }
 45 
 46  public void handleBusinessLogic(String username, Map userMap) {
 47   Map existingOIAMap = findUser(username);
 48   if (existingOIAMap == null) {
 49    createUser(username, userMap);
 50   } else {
 51    updateUser(username, existingOIAMap, userMap);
 52   }
 53  }
 54 
 55  public Map findUser(String username) {
 56   logger.debug("Entering findUser(String username)");
 57   Map origOiaAttrValueMap = new HashMap();
 58   try {
 59    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory
 60      .newInstance();
 61    SOAPConnection connection = soapConnectionFactory
 62      .createConnection();
 63    MessageFactory messageFactory = MessageFactory.newInstance();
 64    SOAPMessage message = messageFactory.createMessage();
 65    SOAPHeader header = message.getSOAPHeader();
 66    SOAPBody body = message.getSOAPBody();
 67    QName bodyName = new QName(
 68      OIAIntegrationConstants.OIA_SERVICE_NAMESPACE, "findUsers",
 69      "ser");
 70    SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
 71    QName name = new QName("in0");
 72    SOAPElement symbol = bodyElement.addChildElement(name);
 73    symbol.addTextNode(username);
 74    //
 75    // Add security header.
 76    //
 77    QName securityQName = new QName(
 78      OIAIntegrationConstants.SECURITY_NAMESPACE, "Security");
 79    SOAPElement security = header.addChildElement(securityQName);
 80 
 81    QName tokenQName = new QName(
 82      OIAIntegrationConstants.SECURITY_NAMESPACE, "UsernameToken");
 83    SOAPElement token = security.addChildElement(tokenQName);
 84 
 85    QName userQName = new QName(
 86      OIAIntegrationConstants.SECURITY_NAMESPACE, "Username");
 87    SOAPElement userName = token.addChildElement(userQName);
 88    userName.addTextNode(OIA_SYSACCOUNT);
 89 
 90    QName pwdQName = new QName(
 91      OIAIntegrationConstants.SECURITY_NAMESPACE, "Password");
 92    SOAPElement password = token.addChildElement(pwdQName);
 93    password.setAttribute("Type", OIAIntegrationConstants.PWD_TYPE);
 94    password.addTextNode(OIA_PWD);
 95    //
 96    // Connect to endpoint, send SOAP request and receive response.
 97    //
 98    URL endpoint = new URL(ENDPOINT_URL);
 99    SOAPMessage response = connection.call(message, endpoint);
100    connection.close();
101    SOAPBody soapBody = response.getSOAPBody();
102    SOAPFault fault = soapBody.getFault();
103    if (fault != null) {
104     throw new Exception(fault.getFaultString());
105    }
106    String soapBodyString = soapBody.getNodeValue();
107    org.w3c.dom.Node subChildNode = null;
108    logger.debug("Node Value--->" + soapBodyString);
109    NodeList nodes = soapBody.getChildNodes();
110 
111    String[] customPropList = new String[20];
112    for (int i = 0; i < nodes.getLength(); i++) {
113     org.w3c.dom.Node node = nodes.item(i);
114     logger.debug("node.getLocalName()--->" + node.getLocalName());
115     logger.debug("node.getTextContent().trim()---> "
116       + node.getTextContent().trim());
117     if (node.getLocalName().equalsIgnoreCase("findUsersResponse")) {
118      String nodeText = node.getTextContent().trim();
119      if ((nodeText != null)
120        && (!(nodeText.equalsIgnoreCase("")))) {
121       logger.debug("User Exist in OIA");
122      } else {
123       logger.debug("User Does not Exist in OIA");
124       return null;
125      }
126     }
127     if (node.getNodeType() == Node.ELEMENT_NODE) {
128      NodeList childNodes = node.getChildNodes();
129      for (int j = 0; j < childNodes.getLength(); j++) {
130       org.w3c.dom.Node childNode = childNodes.item(j);
131 
132       logger.debug("childNode.getLocalName()--->"
133         + childNode.getLocalName());
134       logger.debug("childNode.getTextContent().trim()---> "
135         + childNode.getTextContent().trim());
136       NodeList subChildNodes = childNode.getChildNodes();
137       for (int k = 0; k < subChildNodes.getLength(); k++) {
138        subChildNode = subChildNodes.item(k);
139        logger.debug("subChildNode.getLocalName() ---> "
140          + subChildNode.getLocalName());
141        logger.debug("subChildNode.subSubChildNode.getNodeType()---> "
142          + subChildNode.getNodeType());
143        logger.debug("subChildNode.getTextContent().trim()---> "
144          + subChildNode.getTextContent().trim());
145        NodeList subSubChildNodes = subChildNode
146          .getChildNodes();
147        for (int l = 0; l < subSubChildNodes.getLength(); l++) {
148         org.w3c.dom.Node subSubChildNode = subSubChildNodes
149           .item(l);
150         String subSubChildNodeLocalName = subSubChildNode
151           .getLocalName().trim();
152         String subSubChildNodeText = subSubChildNode
153           .getTextContent().trim();
154         logger.debug("subSubChildNode.subSubChildNode.getNodeType()---> "
155           + subSubChildNode.getNodeType());
156         logger.debug("subSubChildNode.getLocalName()---> "
157           + subSubChildNodeLocalName);
158         logger.debug("subSubChildNode.getTextContent().trim()---> "
159           + subSubChildNodeText);
160         if ((subSubChildNodeLocalName != null)
161           && (!(subSubChildNodeLocalName
162             .equalsIgnoreCase(OIAIntegrationConstants.CUSTOMPROPATTRIBUTE)))) {
163          origOiaAttrValueMap.put(
164            subSubChildNodeLocalName,
165            subSubChildNodeText);
166         }
167         NodeList thirdChildNodes = subSubChildNode
168           .getChildNodes();
169         // Below logic iterates custom properties and
170         // sets it in the right index
171         int index = 0;
172         for (int m = 0; m < thirdChildNodes.getLength(); m++) {
173          org.w3c.dom.Node thirdChildNode = thirdChildNodes
174            .item(m);
175          if (thirdChildNode != null) {
176           String thrdChildNodeName = thirdChildNode
177             .getLocalName();
178           String thrdChildNodeNameText = thirdChildNode
179             .getTextContent().trim();
180           logger.debug("thrdChildNodeName---> "
181             + thrdChildNodeName);
182           logger.debug("thrdChildNodeNameText---> "
183             + thrdChildNodeNameText);
184           if ((thrdChildNodeName != null)
185             && (thrdChildNodeName
186               .equalsIgnoreCase("string"))) {
187            logger.debug("index-->" + index);
188            customPropList[index] = thrdChildNodeNameText;
189            index = index + 1;
190           }
191           origOiaAttrValueMap
192           .put(OIAIntegrationConstants.CUSTOMPROPATTRIBUTE,
193             customPropList);
194          }
195         }// End of Below logic iterates custom
196         // properties and sets it in the right index
197        }
198       }
199      }
200     }
201    }
202    logger.debug("oiaAttrValueMap--->" + origOiaAttrValueMap);
203   } catch (Exception ex) {
204    ex.printStackTrace();
205   }
206   return origOiaAttrValueMap;
207  }
208 
209  public boolean createUser(String username,
210    Map<String, String> oiaAttrValueMap) {
211   boolean flag = false;
212   try {
213    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory
214      .newInstance();
215    SOAPConnection connection = soapConnectionFactory
216      .createConnection();
217    MessageFactory messageFactory = MessageFactory.newInstance();
218    SOAPMessage message = messageFactory.createMessage();
219    SOAPHeader header = message.getSOAPHeader();
220    SOAPBody body = message.getSOAPBody();
221    QName bodyName = new QName(
222      OIAIntegrationConstants.OIA_SERVICE_NAMESPACE,
223      "createUser", "ser");
224    SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
225    QName name = new QName("http://domain.api.rbacx.vaau.com", "in0");
226    SOAPElement symbol = bodyElement.addChildElement(name);
227 
228    // ///////////////////////////////////////////////////////////////////
229    Set attrSet = oiaAttrValueMap.keySet();
230    Iterator iterator = attrSet.iterator();
231    while (iterator.hasNext()) {
232     String attributeName = iterator.next().toString().trim();
233     if (OIAIntegrationConstants.allowedAttrSet
234       .contains(attributeName)) {
235      logger.debug("attributeName--->" + attributeName);
236      QName attrNameQ = new QName(attributeName);
237      SOAPElement attrNameElement = symbol
238        .addChildElement(attrNameQ);
239      String attrValue = oiaAttrValueMap.get(attributeName)
240        .toString();
241      logger.debug("attrValue--->" + attrValue);
242      attrNameElement.addTextNode(attrValue);
243     }
244    }
245    QName customPropNameQ = new QName(
246      OIAIntegrationConstants.CUSTOMPROPATTRIBUTE);
247    SOAPElement customPropertyElement = symbol
248      .addChildElement(customPropNameQ);
249    String[] customPropList = new String[20];
250    SOAPElement stringElement = null;
251    QName stringQ = new QName("string");
252    for (int i = 0; i < customPropList.length; i++) {
253     stringElement = customPropertyElement.addChildElement(stringQ);
254     String string = "";
255     if (i == 19) {
256      string = oiaAttrValueMap.get(
257        OIAIntegrationConstants.USR_KEY_ATTRIBUTE)
258        .toString();
259     }
260     logger.debug("custom prop-->" + i + "--->" + string);
261     if (string != null) {
262      stringElement.addTextNode(string);
263     }
264     logger.debug("added custom prop-->" + i);
265    }
266 
267    QName securityQName = new QName(
268      OIAIntegrationConstants.SECURITY_NAMESPACE, "Security");
269    SOAPElement security = header.addChildElement(securityQName);
270    QName tokenQName = new QName(
271      OIAIntegrationConstants.SECURITY_NAMESPACE, "UsernameToken");
272    SOAPElement token = security.addChildElement(tokenQName);
273    QName userQName = new QName(
274      OIAIntegrationConstants.SECURITY_NAMESPACE, "Username");
275    SOAPElement userName = token.addChildElement(userQName);
276    userName.addTextNode(OIA_SYSACCOUNT);
277    QName pwdQName = new QName(
278      OIAIntegrationConstants.SECURITY_NAMESPACE, "Password");
279    SOAPElement password = token.addChildElement(pwdQName);
280    password.setAttribute("Type", OIAIntegrationConstants.PWD_TYPE);
281    password.addTextNode(OIA_PWD);
282 
283    URL endpoint = new URL(ENDPOINT_URL);
284    SOAPMessage response = connection.call(message, endpoint);
285    connection.close();
286    SOAPBody soapBody = response.getSOAPBody();
287    SOAPFault fault = soapBody.getFault();
288    if (fault != null) {
289     throw new Exception(fault.getFaultString());
290    } else {
291     flag = true;
292    }
293    logger.debug("Done creating");
294   } catch (Exception e) {
295    e.printStackTrace();
296   }
297   return flag;
298  }
299 
300  public boolean updateUser(String username, Map origOiaAttrValueMap,
301    Map changedMap) {
302   boolean flag = false;
303   try {
304    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory
305      .newInstance();
306    SOAPConnection connection = soapConnectionFactory
307      .createConnection();
308    MessageFactory messageFactory = MessageFactory.newInstance();
309    SOAPMessage message = messageFactory.createMessage();
310    SOAPHeader header = message.getSOAPHeader();
311    SOAPBody body = message.getSOAPBody();
312    QName bodyName = new QName(
313      OIAIntegrationConstants.OIA_SERVICE_NAMESPACE,
314      "updateUser", "ser");
315    SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
316    QName name = new QName("http://domain.api.rbacx.vaau.com", "in0");
317    SOAPElement symbol = bodyElement.addChildElement(name);
318    Set attrSet = origOiaAttrValueMap.keySet();
319    Iterator iterator = attrSet.iterator();
320    while (iterator.hasNext()) {
321     String attributeName = iterator.next().toString().trim();// .toString().trim();
322     logger.debug("attributeName--->" + attributeName);
323     if (OIAIntegrationConstants.allowedAttrSet
324       .contains(attributeName)) {
325      QName attrNameQ = new QName(attributeName);
326      SOAPElement attrNameElement = symbol
327        .addChildElement(attrNameQ);
328      if (attributeName
329        .equalsIgnoreCase(OIAIntegrationConstants.CUSTOMPROPATTRIBUTE)) {
330       String[] customPropList = (String[]) origOiaAttrValueMap
331         .get(attributeName);
332       logger.debug("customPropList in updateUser -->"
333         + customPropList);
334       for (int i = 0; i < customPropList.length; i++) {
335        QName stringQ = new QName("string");
336        SOAPElement stringElement = attrNameElement
337          .addChildElement(stringQ);
338        String string = null;
339        if ((changedMap
340          .containsKey(OIAIntegrationConstants.USR_KEY_ATTRIBUTE))
341          && (i == 19)) {
342         string = changedMap
343           .get(OIAIntegrationConstants.USR_KEY_ATTRIBUTE)
344           .toString();
345        } else {
346         string = customPropList[i];
347        }
348        logger.debug("custom prop-->" + i + "--->" + string);
349        stringElement.addTextNode(string);
350        logger.debug("added custom prop-->" + i);
351       }
352      }
353      String attrValue = null;
354      if (changedMap.containsKey(attributeName)) {
355       logger.debug("changedMap.containsKey(attributeName)->"
356         + attributeName);
357       attrValue = changedMap.get(attributeName).toString()
358         .trim();
359      } else {
360       attrValue = origOiaAttrValueMap.get(attributeName)
361         .toString().trim();
362      }
363      logger.debug("attrValue-->" + attrValue);
364      if ((attrValue != null)
365        && (!(attrValue.equalsIgnoreCase("")))) {
366       attrNameElement.addTextNode(attrValue);
367      }
368 
369     }
370    }
371 
372    QName securityQName = new QName(
373      OIAIntegrationConstants.SECURITY_NAMESPACE, "Security");
374    SOAPElement security = header.addChildElement(securityQName);
375    QName tokenQName = new QName(
376      OIAIntegrationConstants.SECURITY_NAMESPACE, "UsernameToken");
377    SOAPElement token = security.addChildElement(tokenQName);
378    QName userQName = new QName(
379      OIAIntegrationConstants.SECURITY_NAMESPACE, "Username");
380    SOAPElement userName = token.addChildElement(userQName);
381    userName.addTextNode(OIA_SYSACCOUNT);
382    QName pwdQName = new QName(
383      OIAIntegrationConstants.SECURITY_NAMESPACE, "Password");
384    SOAPElement password = token.addChildElement(pwdQName);
385    password.setAttribute("Type", OIAIntegrationConstants.PWD_TYPE);
386    password.addTextNode(OIA_PWD);
387    URL endpoint = new URL(ENDPOINT_URL);
388    SOAPMessage response = connection.call(message, endpoint);
389    connection.close();
390    SOAPBody soapBody = response.getSOAPBody();
391    SOAPFault fault = soapBody.getFault();
392    if (fault != null) {
393     throw new Exception(fault.getFaultString());
394    } else {
395     flag = true;
396    }
397    logger.debug("Done updating");
398 
399   } catch (Exception e) {
400    e.printStackTrace();
401   }
402   return flag;
403  }
404 }
405 

 
 
OIADBConnector class contains some operations related to OIA DB pertaining to custom properties



 1 /*
  2  * To change this template, choose Tools | Templates
  3  * and open the template in the editor.
  4  */
  5 package com.dubey.deepak.oim.oia.intg;
  6 
  7 import java.sql.Connection;
  8 import java.sql.DriverManager;
  9 import java.sql.PreparedStatement;
 10 import java.sql.ResultSet;
 11 import java.sql.SQLException;
 12 
 13 import com.thortech.util.logging.Logger;
 14 
 15 /**
 16  * 
 17  * @author ddubey002
 18  */
 19 public class OIADBConnector {
 20 
 21  private static Logger logger = OIAIntegrationConstants.logger;
 22 
 23  private Connection getConnection(ItResourceObj itResourceObj) {
 24   logger.debug("Entering getConnection(ItResourceObj itResourceObj) of OIADBConnector");
 25   Connection connection = null;
 26   try {
 27    Class.forName(OIAIntegrationConstants.ORACLEDRIVER);
 28    // jdbc:oracle:thin:@localhost:1521:ORCL;
 29    String jdbcURL = "jdbc:oracle:thin:@" + itResourceObj.getDBHost()
 30      + ":" + itResourceObj.getDBPort() + ":"
 31      + itResourceObj.getDBSid();
 32    connection = DriverManager.getConnection(jdbcURL,
 33      itResourceObj.getDBUser(),
 34      itResourceObj.getDBUserPassword());
 35   } catch (SQLException ex) {
 36    logger.debug("SQLException  ocurred in getConnection -->"
 37      + ex.getMessage());
 38    ex.printStackTrace();
 39   } catch (ClassNotFoundException ex) {
 40    logger.debug("ClassNotFoundException  ocurred in getConnection -->"
 41      + ex.getMessage());
 42    ex.printStackTrace();
 43   }
 44   logger.debug("Exiting getConnection(ItResourceObj itResourceObj) of OIADBConnector");
 45   return connection;
 46  }
 47 
 48  private void closeConnection(Connection connection) {
 49   logger.debug("Entering closeConnection()");
 50   try {
 51    if ((connection != null) && (!(connection.isClosed()))) {
 52     connection.close();
 53    }
 54   } catch (SQLException sQLException) {
 55    logger.debug("SQLException  ocurred in getConnection -->"
 56      + sQLException.getMessage());
 57    sQLException.printStackTrace();
 58   }
 59   logger.debug("Exiting closeConnection()");
 60  }
 61 
 62  public boolean updateUserName(ItResourceObj itResourceObj,
 63    String oldUserName, String newUserName) {
 64   logger.debug("Entering updateUserName(ItResourceObj itResourceObj , String oldUserName , String newUserName)");
 65   logger.debug("oldLoginName in updateUserName -->" + oldUserName);
 66   logger.debug("newUserName in updateUserName -->" + newUserName);
 67   PreparedStatement preparedStatement = null;
 68   PreparedStatement preparedStatement2 = null;
 69   String updateQueryGlobal = "UPDATE RBACXSERVICE.GLOBALUSERS set USERNAME = ? WHERE USERNAME = ?";
 70   String updateQueryRBX = "UPDATE RBACXSERVICE.RBX_USERS set USERNAME = ? WHERE USERNAME = ?";
 71   Connection connection = null;
 72   boolean flag = false;
 73   try {
 74    connection = getConnection(itResourceObj);
 75    preparedStatement = connection.prepareStatement(updateQueryGlobal);
 76    preparedStatement2 = connection.prepareStatement(updateQueryRBX);
 77 
 78    logger.debug("before preparedStatement");
 79    preparedStatement.setString(1, newUserName);
 80    preparedStatement2.setString(1, newUserName);
 81    preparedStatement.setString(2, oldUserName);
 82    preparedStatement2.setString(2, oldUserName);
 83    int result = preparedStatement.executeUpdate(); // executeUpdate();
 84    preparedStatement2.executeUpdate();
 85    logger.debug("after preparedStatement execute result-->" + result);
 86    preparedStatement.close();
 87    preparedStatement2.close();
 88    connection.commit();
 89    if (result == 1)
 90     flag = true;
 91 
 92   } catch (SQLException ex) {
 93    logger.debug("SQLException  ocurred in updateUserName -->"
 94      + ex.getMessage());
 95    ex.printStackTrace();
 96   } catch (Exception ex) {
 97    logger.debug("Exception  ocurred in updateUserName -->"
 98      + ex.getMessage());
 99    ex.printStackTrace();
100   } finally {
101    try {
102     preparedStatement.close();
103    } catch (SQLException ex) {
104     logger.debug("error closing preparedStatement-->"
105       + ex.toString());
106    }
107    closeConnection(connection);
108   }
109   logger.debug("Exiting  updateUserName(ItResourceObj itResourceObj , String oldUserName , String newUserName)");
110   return flag;
111  }
112 
113  public String getID(ItResourceObj itResourceObj, String oimLoginName) {
114   logger.debug("Entering getID(ItResourceObj itResourceObj, String oimLoginName)");
115   String oiaID = null;
116   PreparedStatement preparedStatement = null;
117   ResultSet resultSet = null;
118   String selectQuery = "SELECT GLOBALUSERKEY FROM GLOBALUSERS WHERE USERNAME=?";
119   Connection connection = null;
120   try {
121    connection = getConnection(itResourceObj);
122    preparedStatement = connection.prepareStatement(selectQuery);
123    logger.debug("before preparedStatement");
124    preparedStatement.setString(1, oimLoginName);
125    resultSet = preparedStatement.executeQuery();
126    logger.debug("after preparedStatement execute");
127    while (resultSet.next()) {
128     oiaID = resultSet.getString("GLOBALUSERKEY");
129     logger.debug("oiaID in DB Connector-->" + oiaID);
130    }
131   } catch (SQLException ex) {
132    logger.debug("SQLException  ocurred in getID -->" + ex.getMessage());
133    ex.printStackTrace();
134   } catch (Exception ex) {
135    logger.debug("Exception  ocurred in getConnection -->"
136      + ex.getMessage());
137    ex.printStackTrace();
138   } finally {
139    closeConnection(connection);
140   }
141   logger.debug("Exiting getID ( String oimUSKKey , String oimLoginName)");
142   return oiaID;
143 
144  }
145 }
146 
 
  
 
OIA_OIM_Util Class
 
  1 /*
  2  * To change this template, choose Tools | Templates
  3  * and open the template in the editor.
  4  */
  5 package com.dubey.deepak.oim.oia.intg;
  6 
  7 import java.util.HashMap;
  8 import java.util.Hashtable;
  9 import java.util.Map;
 10 
 11 import Thor.API.tcResultSet;
 12 import Thor.API.tcUtilityFactory;
 13 import Thor.API.Exceptions.tcAPIException;
 14 import Thor.API.Exceptions.tcColumnNotFoundException;
 15 import Thor.API.Exceptions.tcInvalidLookupException;
 16 import Thor.API.Operations.tcLookupOperationsIntf;
 17 
 18 //import java.util.logging.Level;
 19 //import java.util.logging.Logger;
 20 import com.thortech.util.logging.Logger;
 21 import com.thortech.xl.dataaccess.tcDataProvider;
 22 import com.thortech.xl.util.adapters.tcUtilXellerateOperations;
 23 
 24 public final class OIA_OIM_Util {
 25 
 26  private static Logger logger = OIAIntegrationConstants.logger;
 27 
 28  public OIA_OIM_Util() {
 29   // this.dataProvider = dataProvider;
 30  }
 31 
 32  // private tcDataProvider dataProvider = null;
 33 
 34  public ItResourceObj initITResourceObj(tcDataProvider dataProvider,
 35    String itResourceName) {
 36   logger.debug("Entering initITResourceObj(String itResourceName)");
 37   ItResourceObj itResourceObj = null;
 38   try {
 39    Hashtable itResourceMap = tcUtilXellerateOperations
 40      .getITAssetProperties(dataProvider, itResourceName);
 41    logger.debug(" Got the itResourceMap -->" + itResourceMap);
 42    itResourceObj = new ItResourceObj();
 43 
 44    itResourceObj.setAppHost(itResourceMap.get("AppHost").toString());
 45    itResourceObj.setAppPort(itResourceMap.get("AppPort").toString());
 46    itResourceObj.setAppUser(itResourceMap.get("AppUser").toString());
 47    itResourceObj.setAppUserPassword(itResourceMap.get(
 48      "AppUserPassword").toString());
 49    // logger.debug(itResourceName)
 50 
 51    itResourceObj.setDBHost(itResourceMap.get("DBHost").toString());
 52    itResourceObj.setDBPort(itResourceMap.get("DBPort").toString());
 53    itResourceObj.setDBType(itResourceMap.get("DBType").toString());
 54    itResourceObj.setDBSid(itResourceMap.get("DBSid").toString());
 55    itResourceObj.setDBUser(itResourceMap.get("DBUser").toString());
 56    itResourceObj.setDBUserPassword(itResourceMap.get("DBUserPassword")
 57      .toString());
 58 
 59   } catch (Exception ex) {
 60    logger.debug("Exception occurred in initITResourceObj -->"
 61      + ex.getMessage());
 62    ex.printStackTrace();
 63   }
 64   logger.debug("Exiting initITResourceObj(String itResourceName)");
 65   return itResourceObj;
 66 
 67  }
 68 
 69  private boolean isNullOrBlank(String pstrToCheck) {
 70   if (pstrToCheck == null || pstrToCheck.trim().equals("")) {
 71    return true;
 72   }
 73   return false;
 74  }
 75 
 76  public Map loadMetaDataLookup(tcDataProvider dataProvider) throws Exception {
 77   logger.debug("Entering loadMetaDataLookup(tcDataProvider dataProvider) of OIA_OIM_Util");
 78 
 79   tcResultSet MetadataMappings = null;
 80 
 81   Map metaDataHash = null;
 82   tcLookupOperationsIntf lookupIntf = null;
 83 
 84   try {
 85    lookupIntf = (tcLookupOperationsIntf) tcUtilityFactory.getUtility(
 86      dataProvider, OIAIntegrationConstants.thorLookOperations);
 87    MetadataMappings = lookupIntf
 88      .getLookupValues(OIAIntegrationConstants.lkupMetadataMappings);
 89    metaDataHash = new HashMap();
 90    for (int i = 0; i < MetadataMappings.getRowCount(); i++) {
 91     MetadataMappings.goToRow(i);
 92     metaDataHash
 93     .put(MetadataMappings
 94       .getStringValue(OIAIntegrationConstants.LOOKUPDECODEVALUE),
 95       MetadataMappings
 96       .getStringValue(OIAIntegrationConstants.LOOKUPCODEKEY));
 97    } // for close
 98   } catch (tcAPIException ex) {
 99    logger.debug("Exception occurred in loadMetaDataLookup -->"
100      + ex.getMessage());
101    ex.printStackTrace();
102   } catch (tcInvalidLookupException ex) {
103 
104    logger.debug("Exception occurred in loadMetaDataLookup -->"
105      + ex.getMessage());
106    ex.printStackTrace();
107 
108   } catch (tcColumnNotFoundException ex) {
109 
110    logger.debug("Exception occurred in loadMetaDataLookup -->"
111      + ex.getMessage());
112    ex.printStackTrace();
113 
114   } catch (Exception ex) {
115    logger.debug("Exception occurred in loadMetaDataLookup -->"
116      + ex.getMessage());
117    ex.printStackTrace();
118 
119   }
120   logger.debug("Exiting loadMetaDataLookup(tcDataProvider dataProvider) of OIA_OIM_Util");
121   return metaDataHash;
122  }
123 }
124 
 

 
 
ItResourceObj model class representing an IT Resource Object
 
  1 /*
  2  * To change this template, choose Tools | Templates
  3  * and open the template in the editor.
  4  */
  5 
  6 package com.dubey.deepak.oim.oia.intg;
  7 
  8 /**
  9  * 
 10  * @author ddubey002
 11  */
 12 public class ItResourceObj {
 13  private String AppHost = "localhost";
 14  private String AppPort = "9080";
 15  private String AppUser = "rbacxadmin";
 16  private String AppUserPassword = "password";
 17  private String DBHost = "localhost";
 18  private String DBPort = "1521";
 19  private String DBUser = "rbacxservice";
 20  private String DBUserPassword = "rbacxservice";
 21  private String DBSid = "orcl";
 22  private String DBType = "oracle";
 23 
 24  /**
 25   * @return the AppHost
 26   */
 27  public String getAppHost() {
 28   return AppHost;
 29  }
 30 
 31  /**
 32   * @param AppHost
 33   *            the AppHost to set
 34   */
 35  public void setAppHost(String AppHost) {
 36   this.AppHost = AppHost;
 37  }
 38 
 39  /**
 40   * @return the AppPort
 41   */
 42  public String getAppPort() {
 43   return AppPort;
 44  }
 45 
 46  /**
 47   * @param AppPort
 48   *            the AppPort to set
 49   */
 50  public void setAppPort(String AppPort) {
 51   this.AppPort = AppPort;
 52  }
 53 
 54  /**
 55   * @return the AppUser
 56   */
 57  public String getAppUser() {
 58   return AppUser;
 59  }
 60 
 61  /**
 62   * @param AppUser
 63   *            the AppUser to set
 64   */
 65  public void setAppUser(String AppUser) {
 66   this.AppUser = AppUser;
 67  }
 68 
 69  /**
 70   * @return the AppUserPassword
 71   */
 72  public String getAppUserPassword() {
 73   return AppUserPassword;
 74  }
 75 
 76  /**
 77   * @param AppUserPassword
 78   *            the AppUserPassword to set
 79   */
 80  public void setAppUserPassword(String AppUserPassword) {
 81   this.AppUserPassword = AppUserPassword;
 82  }
 83 
 84  /**
 85   * @return the DBHost
 86   */
 87  public String getDBHost() {
 88   return DBHost;
 89  }
 90 
 91  /**
 92   * @param DBHost
 93   *            the DBHost to set
 94   */
 95  public void setDBHost(String DBHost) {
 96   this.DBHost = DBHost;
 97  }
 98 
 99  /**
100   * @return the DBPort
101   */
102  public String getDBPort() {
103   return DBPort;
104  }
105 
106  /**
107   * @param DBPort
108   *            the DBPort to set
109   */
110  public void setDBPort(String DBPort) {
111   this.DBPort = DBPort;
112  }
113 
114  /**
115   * @return the DBUser
116   */
117  public String getDBUser() {
118   return DBUser;
119  }
120 
121  /**
122   * @param DBUser
123   *            the DBUser to set
124   */
125  public void setDBUser(String DBUser) {
126   this.DBUser = DBUser;
127  }
128 
129  /**
130   * @return the DBUserPassword
131   */
132  public String getDBUserPassword() {
133   return DBUserPassword;
134  }
135 
136  /**
137   * @param DBUserPassword
138   *            the DBUserPassword to set
139   */
140  public void setDBUserPassword(String DBUserPassword) {
141   this.DBUserPassword = DBUserPassword;
142  }
143 
144  /**
145   * @return the DBSid
146   */
147  public String getDBSid() {
148   return DBSid;
149  }
150 
151  /**
152   * @param DBSid
153   *            the DBSid to set
154   */
155  public void setDBSid(String DBSid) {
156   this.DBSid = DBSid;
157  }
158 
159  /**
160   * @return the DBType
161   */
162  public String getDBType() {
163   return DBType;
164  }
165 
166  /**
167   * @param DBType
168   *            the DBType to set
169   */
170  public void setDBType(String DBType) {
171   this.DBType = DBType;
172  }
173 
174 }
175 
  

OIAIntegrationConstants 
 
 
  1 /*
  2  * To change this template, choose Tools | Templates
  3  * and open the template in the editor.
  4  */
  5 package com.dubey.deepak.oim.oia.intg;
  6 
  7 import java.util.Arrays;
  8 import java.util.HashSet;
  9 
 10 import com.thortech.util.logging.Logger;
 11 
 12 /**
 13  * 
 14  * @author ddubey002
 15  */
 16 public interface OIAIntegrationConstants {
 17 
 18  public static final String OIAIDATTRIBUTE = "USR_UDF_OIAID";
 19  public static final Logger logger = Logger.getLogger("OIAUSERSYNC");
 20  public static final String USR_KEY_ATTRIBUTE = "customProperty20";
 21  public static final String CUSTOMPROPATTRIBUTE = "customProperties";
 22  public static final String[] allowedStringAttributes = { "username",
 23   "firstName", "lastName", "fullName", "middleName", "employeeId",
 24   "employeeType", "jobCodes", "title", "officeName", "building",
 25   "businessApprover", "city", "comments", "countryOrRegion",
 26   CUSTOMPROPATTRIBUTE, "delegate", "department", "description",
 27   "extension", "fax", "location", "manager", "mobile", "pager",
 28   "phone", "primaryEmail", "secondaryEmail",
 29   "serviceDeskTicketNumber", "stateOrProvince", "street",
 30  "zipOrPostalCode" };
 31  // ,"","","","","","","","","","","",""};
 32  public static final HashSet<String> allowedAttrSet = new HashSet<String>(
 33    Arrays.asList(allowedStringAttributes));
 34  public static final String SECURITY_NAMESPACE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";
 35  public static final String PWD_TYPE = "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText";
 36  public static final String OIA_SERVICE_NAMESPACE = "http://service.api.rbacx.vaau.com";
 37  /**
 38   * Constant String which hold the name of metadatamappings lookup
 39   */
 40  public static final String lkupMetadataMappings = "Lookup.oim.oia.metadatamappings";
 41  /**
 42   * Constant string which holds the name of the class which will be used for
 43   * lookup operations
 44   */
 45  public static final String thorLookOperations = "Thor.API.Operations.tcLookupOperationsIntf";
 46  public static final String OIMUSERLOGINATTRIBUTE = "USR_LOGIN";
 47  public static final String OIMUSERKEYATTRIBUTE = "USR_KEY";
 48  public static final String LOOKUPCODEKEY = "Lookup Definition.Lookup Code Information.Code Key";
 49  public static final String LOOKUPDECODEVALUE = "Lookup Definition.Lookup Code Information.Decode";
 50  public static final String ITRESOURCENAME = "OIA IT Server";
 51  public static final String ORACLEDRIVER = "oracle.jdbc.driver.OracleDriver";
 52  public static final String building = "building";
 53  public static final String businessApprover = "businessApprover";
 54  public static final String city = "city";
 55  public static final String comments = "comments";
 56  public static final String countryOrRegion = "countryOrRegion";
 57  public static final String createDate = "createDate";
 58  public static final String createUser = "createUser";
 59  public static final String customProperties = "customProperties";
 60  public static final String delegate = "delegate";
 61  public static final String deletedDate = "deletedDate";
 62  public static final String department = "department";
 63  public static final String description = "description";
 64  public static final String disabledDate = "disabledDate";
 65  public static final String employeeId = "employeeId";
 66  public static final String employeeType = "employeeType";
 67  public static final String enabledDate = "enabledDate";
 68  public static final String endDate = "endDate";
 69  public static final String extension = "extension";
 70  public static final String fax = "fax";
 71  public static final String firstName = "firstName";
 72  public static final String fullName = "fullName";
 73  public static final String id = "id";
 74  public static final String jobCodes = "jobCodes";
 75  public static final String lastName = "lastName";
 76  public static final String location = "location";
 77  public static final String manager = "manager";
 78  public static final String middleName = "middleName";
 79  public static final String mobile = "mobile";
 80  public static final String name = "name";
 81  public static final String officeName = "officeName";
 82  public static final String pager = "pager";
 83  public static final String phone = "phone";
 84  public static final String primaryEmail = "primaryEmail";
 85  public static final String secondaryEmail = "secondaryEmail";
 86  public static final String serviceDeskTicketNumber = "serviceDeskTicketNumber";
 87  public static final String startDate = "startDate";
 88  public static final String stateOrProvince = "stateOrProvince";
 89  public static final String statusKey = "statusKey";
 90  public static final String street = "street";
 91  public static final String suspended = "suspended";
 92  public static final String suspendedDate = "suspendedDate";
 93  public static final String technicalApprover = "technicalApprover";
 94  public static final String title = "title";
 95  public static final String updateDate = "updateDate";
 96  public static final String updateUser = "updateUser";
 97  public static final String userData = "userData";
 98  public static final String username = "username";
 99  public static final String zipOrPostalCode = "zipOrPostalCode";
100 }
101 

 
 
Finally the Tester Class to test everything standalone. 

     
  1 /*
  2  * To change this template, choose Tools | Templates
  3  * and open the template in the editor.
  4  */
  5 
  6 package com.dubey.deepak.oim.oia.intg;
  7 
  8 
  9 /**
 10  * 
 11  * @author ddubey002
 12  */
 13 public class Tester {
 14  public static void main(String[] args) {
 15 
 16   OIADBConnector oIADBConnector = new OIADBConnector();
 17   oIADBConnector.updateUserName(new ItResourceObj(), "DEMOUSER4",
 18     "qwerty");
 19 
 20   // OIARequest oIARequest = new OIARequest(new ItResourceObj());
 21   // String username = "werergert";
 22   // Map userMap = new HashMap();
 23   // userMap.put("username", username);
 24   // userMap.put("firstName", "ggggggggg");
 25   // userMap.put("lastName", "opopopo");
 26   //
 27   // userMap.put("fullName", "Value123");
 28   // userMap.put("middleName", "Value123");
 29   // userMap.put("employeeId", "Value123");
 30   // userMap.put("employeeType", "Value123");
 31   // userMap.put("jobCodes", "Value123");
 32   // userMap.put("title", "Value123");
 33   // userMap.put("officeName", "Value123");
 34   // userMap.put("city", "jiojjijijo");
 35   // userMap.put("comments", "okopkopsfsd");
 36   // userMap.put(OIAIntegrationConstants.USR_KEY_ATTRIBUTE, "USR_KEY");
 37   // oIARequest.handleBusinessLogic(username, userMap);
 38 
 39  }
 40 
 41 }
 42 

Comments

Popular posts from this blog

OIM 11g R2 PS2 : SOA Approval Workflow Sample

OHS 12c (12.1.3) webgate deployment and configuration

Oracle Identity Manager (OIM) Interview Questions