What this application does is facilitate Account Claim Process.
Users has been migrated from some other IAM product to OIM and exist in disabled state and hence cannot login to perform Self Service operations.
User needs to identify themselves by providing their personal details like personal identification number, zip code and dob etc.
After successfully Identifying themselves they will be able to set a new password and set their challenge questions and answers.
During this process the application will activate their account and set the new password and QnA.
At the end of the process, they will be able to login OIM with their new password set.
The application has been developed using JDeveloper using ADF technology to render user interfaces and MVC design pattern to keep the concerns separate.
Application Structure
web.xml
1 <?xml version="1.0" encoding="UTF-8"?> 2 <web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> 3 <context-param> 4 <param-name>javax.faces.STATE_SAVING_METHOD</param-name> 5 <param-value>client</param-value> 6 </context-param> 7 <context-param> 8 <description>If this parameter is true, there will be an automatic check of the modification date of your JSPs, and saved state will be discarded when JSP's change. It will also automatically check if your skinning css files have changed without you having to restart the server. This makes development easier, but adds overhead. For this reason this parameter should be set to false when your application is deployed.</description> 9 <param-name>org.apache.myfaces.trinidad.CHECK_FILE_MODIFICATION</param-name> 10 <param-value>false</param-value> 11 </context-param> 12 <context-param> 13 <description>Whether the 'Generated by...' comment at the bottom of ADF Faces HTML pages should contain version number information.</description> 14 <param-name>oracle.adf.view.rich.versionString.HIDDEN</param-name> 15 <param-value>false</param-value> 16 </context-param> 17 <filter> 18 <filter-name>trinidad</filter-name> 19 <filter-class>org.apache.myfaces.trinidad.webapp.TrinidadFilter</filter-class> 20 </filter> 21 <filter> 22 <filter-name>ServletADFFilter</filter-name> 23 <filter-class>oracle.adf.share.http.ServletADFFilter</filter-class> 24 </filter> 25 <filter> 26 <filter-name>ADFLibraryFilter</filter-name> 27 <filter-class>oracle.adf.library.webapp.LibraryFilter</filter-class> 28 </filter> 29 <filter-mapping> 30 <filter-name>trinidad</filter-name> 31 <servlet-name>Faces Servlet</servlet-name> 32 <dispatcher>FORWARD</dispatcher> 33 <dispatcher>REQUEST</dispatcher> 34 </filter-mapping> 35 <filter-mapping> 36 <filter-name>ServletADFFilter</filter-name> 37 <servlet-name>Faces Servlet</servlet-name> 38 <dispatcher>FORWARD</dispatcher> 39 <dispatcher>REQUEST</dispatcher> 40 </filter-mapping> 41 <filter-mapping> 42 <filter-name>ADFLibraryFilter</filter-name> 43 <url-pattern>/*</url-pattern> 44 <dispatcher>FORWARD</dispatcher> 45 <dispatcher>REQUEST</dispatcher> 46 </filter-mapping> 47 <servlet> 48 <servlet-name>Faces Servlet</servlet-name> 49 <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> 50 <load-on-startup>1</load-on-startup> 51 </servlet> 52 <servlet> 53 <servlet-name>resources</servlet-name> 54 <servlet-class>org.apache.myfaces.trinidad.webapp.ResourceServlet</servlet-class> 55 </servlet> 56 <servlet> 57 <servlet-name>BIGRAPHSERVLET</servlet-name> 58 <servlet-class>oracle.adfinternal.view.faces.bi.renderkit.graph.GraphServlet</servlet-class> 59 </servlet> 60 <servlet> 61 <servlet-name>BIGAUGESERVLET</servlet-name> 62 <servlet-class>oracle.adfinternal.view.faces.bi.renderkit.gauge.GaugeServlet</servlet-class> 63 </servlet> 64 <servlet> 65 <servlet-name>MapProxyServlet</servlet-name> 66 <servlet-class>oracle.adfinternal.view.faces.bi.renderkit.geoMap.servlet.MapProxyServlet</servlet-class> 67 </servlet> 68 <servlet> 69 <servlet-name>GatewayServlet</servlet-name> 70 <servlet-class>oracle.adfinternal.view.faces.bi.renderkit.graph.FlashBridgeServlet</servlet-class> 71 </servlet> 72 <servlet> 73 <servlet-name>adflibResources</servlet-name> 74 <servlet-class>oracle.adf.library.webapp.ResourceServlet</servlet-class> 75 </servlet> 76 <servlet-mapping> 77 <servlet-name>Faces Servlet</servlet-name> 78 <url-pattern>/faces/*</url-pattern> 79 </servlet-mapping> 80 <servlet-mapping> 81 <servlet-name>resources</servlet-name> 82 <url-pattern>/adf/*</url-pattern> 83 </servlet-mapping> 84 <servlet-mapping> 85 <servlet-name>resources</servlet-name> 86 <url-pattern>/afr/*</url-pattern> 87 </servlet-mapping> 88 <servlet-mapping> 89 <servlet-name>BIGRAPHSERVLET</servlet-name> 90 <url-pattern>/servlet/GraphServlet/*</url-pattern> 91 </servlet-mapping> 92 <servlet-mapping> 93 <servlet-name>BIGAUGESERVLET</servlet-name> 94 <url-pattern>/servlet/GaugeServlet/*</url-pattern> 95 </servlet-mapping> 96 <servlet-mapping> 97 <servlet-name>MapProxyServlet</servlet-name> 98 <url-pattern>/mapproxy/*</url-pattern> 99 </servlet-mapping> 100 <servlet-mapping> 101 <servlet-name>resources</servlet-name> 102 <url-pattern>/bi/*</url-pattern> 103 </servlet-mapping> 104 <servlet-mapping> 105 <servlet-name>GatewayServlet</servlet-name> 106 <url-pattern>/flashbridge/*</url-pattern> 107 </servlet-mapping> 108 <servlet-mapping> 109 <servlet-name>adflibResources</servlet-name> 110 <url-pattern>/adflib/*</url-pattern> 111 </servlet-mapping> 112 <mime-mapping> 113 <extension>swf</extension> 114 <mime-type>application/x-shockwave-flash</mime-type> 115 </mime-mapping> 116 <welcome-file-list> 117 <welcome-file>/index.jsp</welcome-file> 118 </welcome-file-list> 119 </web-app>
adfc-config.xml
adfc-config.xml Source
1 <?xml version="1.0" encoding="windows-1252" ?> 2 <adfc-config xmlns="http://xmlns.oracle.com/adf/controller" version="1.2"> 3 <view id="AccountClaim"> 4 <page>/view1.jspx</page> 5 </view> 6 <view id="view2"> 7 <page>/view2.jspx</page> 8 </view> 9 <view id="view3"> 10 <page>/view3.jspx</page> 11 </view> 12 <view id="view4"> 13 <page>/view4.jspx</page> 14 </view> 15 <view id="view5"> 16 <page>/view5.jspx</page> 17 </view> 18 <view id="ChangePassword"> 19 <page>/ChangePassword.jspx</page> 20 </view> 21 <view id="ClaimSuccess"> 22 <page>/ClaimSuccess.jspx</page> 23 </view> 24 <control-flow-rule id="__5"> 25 <from-activity-id id="__6">AccountClaim</from-activity-id> 26 <control-flow-case id="__15"> 27 <from-outcome id="__20">false</from-outcome> 28 <to-activity-id id="__14">AccountClaim</to-activity-id> 29 </control-flow-case> 30 <control-flow-case id="__22"> 31 <from-outcome id="__23">cancel</from-outcome> 32 <to-activity-id id="__21">view3</to-activity-id> 33 </control-flow-case> 34 <control-flow-case id="__7"> 35 <from-outcome id="__9">true</from-outcome> 36 <to-activity-id id="__8">ChangePassword</to-activity-id> 37 </control-flow-case> 38 </control-flow-rule> 39 <control-flow-rule id="__17"> 40 <from-activity-id id="__16">*</from-activity-id> 41 <control-flow-case id="__19"> 42 <to-activity-id id="__18">AccountClaim</to-activity-id> 43 </control-flow-case> 44 </control-flow-rule> 45 <control-flow-rule id="__53"> 46 <from-activity-id id="__54">ChangePassword</from-activity-id> 47 <control-flow-case id="__55"> 48 <from-outcome id="__57">true</from-outcome> 49 <to-activity-id id="__56">ClaimSuccess</to-activity-id> 50 </control-flow-case> 51 <control-flow-case id="__59"> 52 <from-outcome id="__60">false</from-outcome> 53 <to-activity-id id="__58">view3</to-activity-id> 54 </control-flow-case> 55 <control-flow-case id="__62"> 56 <from-outcome id="__63">NO_USER_FOUND</from-outcome> 57 <to-activity-id id="__61">view4</to-activity-id> 58 </control-flow-case> 59 <control-flow-case id="__64"> 60 <from-outcome id="__66">CLAIMED_EARLIER</from-outcome> 61 <to-activity-id id="__65">view2</to-activity-id> 62 </control-flow-case> 63 <control-flow-case id="__68"> 64 <from-outcome id="__69">MULTIPLE_USER_FOUND</from-outcome> 65 <to-activity-id id="__67">view5</to-activity-id> 66 </control-flow-case> 67 </control-flow-rule> 68 <managed-bean id="__1"> 69 <managed-bean-name id="__2">backing_view1</managed-bean-name> 70 <managed-bean-class id="__4">view.resources.backing.View1</managed-bean-class> 71 <managed-bean-scope id="__3">backingBean</managed-bean-scope> 72 <!--oracle-jdev-comment:managed-bean-jsp-link:1view1.jspx--> 73 </managed-bean> 74 <managed-bean id="__10"> 75 <managed-bean-name id="__12">backing_view2</managed-bean-name> 76 <managed-bean-class id="__11">view.resources.backing.View2</managed-bean-class> 77 <managed-bean-scope id="__13">backingBean</managed-bean-scope> 78 <!--oracle-jdev-comment:managed-bean-jsp-link:1view2.jspx--> 79 </managed-bean> 80 <managed-bean id="__35"> 81 <managed-bean-name id="__37">backing_view4</managed-bean-name> 82 <managed-bean-class id="__34">view.resources.backing.View4</managed-bean-class> 83 <managed-bean-scope id="__36">backingBean</managed-bean-scope> 84 <!--oracle-jdev-comment:managed-bean-jsp-link:1view4.jspx--> 85 </managed-bean> 86 <managed-bean id="__44"> 87 <managed-bean-name id="__41">backing_view5</managed-bean-name> 88 <managed-bean-class id="__43">view.resources.backing.View5</managed-bean-class> 89 <managed-bean-scope id="__42">backingBean</managed-bean-scope> 90 <!--oracle-jdev-comment:managed-bean-jsp-link:1view5.jspx--> 91 </managed-bean> 92 <managed-bean id="__46"> 93 <managed-bean-name id="__47">backing_ChangePassword</managed-bean-name> 94 <managed-bean-class id="__45">view.resources.backing.ChangePassword</managed-bean-class> 95 <managed-bean-scope id="__48">backingBean</managed-bean-scope> 96 <!--oracle-jdev-comment:managed-bean-jsp-link:1ChangePassword.jspx--> 97 </managed-bean> 98 <managed-bean id="__51"> 99 <managed-bean-name id="__50">challengeQnABean</managed-bean-name> 100 <managed-bean-class id="__49">view.resources.backing.ChallengeQnABean</managed-bean-class> 101 <managed-bean-scope id="__52">none</managed-bean-scope> 102 </managed-bean> 103 </adfc-config> 104
Screen 1 - view1.jspx
Source
1 <?xml version='1.0' encoding='windows-1252'?> 2 <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" 3 xmlns:f="http://java.sun.com/jsf/core" 4 xmlns:af="http://xmlns.oracle.com/adf/faces/rich" 5 xmlns:c="http://java.sun.com/jsp/jstl/core"> 6 <c:set var="viewcontrollerBundle" 7 value="#{adfBundle['view.resources.ViewControllerBundle']}"/> 8 <jsp:directive.page contentType="text/html;charset=windows-1252"/> 9 <f:view> 10 <af:document id="d1" binding="#{backingBeanScope.backing_view1.d1}" 11 title="#{viewcontrollerBundle.ACCOUNT_CLAIM_VALIDATION}"> 12 <af:form id="f1" binding="#{backingBeanScope.backing_view1.f1}"> 13 <af:pageTemplate viewId="/oracle/templates/threeColumnTemplate.jspx" 14 id="pt1"> 15 <f:facet name="center"> 16 <af:panelFormLayout binding="#{backingBeanScope.backing_view1.pfl1}" 17 id="pfl1" rows="10"> 18 <af:panelLabelAndMessage label="#{viewcontrollerBundle.ACCOUNT_INFORMATION}" 19 binding="#{backingBeanScope.backing_view1.plam1}" 20 id="plam1"/> 21 <af:inputText label="#{viewcontrollerBundle.UID}" 22 binding="#{backingBeanScope.backing_view1.it1}" 23 id="it1" showRequired="true" required="true" 24 validator="#{backingBeanScope.backing_view1.it1_validator}"/> 25 <af:inputText label="#{viewcontrollerBundle.PIN}" 26 binding="#{backingBeanScope.backing_view1.it2}" 27 id="it2" secret="true" showRequired="true" 28 required="true" 29 validator="#{backingBeanScope.backing_view1.it2_validator}"/> 30 <af:inputText 31 binding="#{backingBeanScope.backing_view1.it3}" 32 id="it3" showRequired="true" required="true" 33 validator="#{backingBeanScope.backing_view1.it3_validator}" 34 label="#{viewcontrollerBundle.ZIP_CODE}"/> 35 <af:inputDate 36 binding="#{backingBeanScope.backing_view1.id2}" 37 id="id2" showRequired="true" required="true" 38 label="#{viewcontrollerBundle.DATE_OF_BIRTH}" 39 validator="#{backingBeanScope.backing_view1.id2_validator2}"/> 40 41 <af:panelGroupLayout binding="#{backingBeanScope.backing_view1.pgl1}" 42 id="pgl1"> 43 <af:commandButton text="#{viewcontrollerBundle.NEXT}" 44 binding="#{backingBeanScope.backing_view1.cb1}" 45 id="cb1" 46 action="#{backingBeanScope.backing_view1.cb1_action}"/> 47 <af:commandButton text="#{viewcontrollerBundle.CANCEL}" 48 binding="#{backingBeanScope.backing_view1.cb2}" 49 id="cb2" action="cancel"/> 50 </af:panelGroupLayout> 51 </af:panelFormLayout> 52 </f:facet> 53 <f:facet name="header"/> 54 <f:facet name="end"/> 55 <f:facet name="start"/> 56 <f:facet name="branding"/> 57 <f:facet name="copyright"/> 58 <f:facet name="status"/> 59 </af:pageTemplate> 60 </af:form> 61 </af:document> 62 </f:view> 63 <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_view1--> 64 </jsp:root> 65
Backing Bean of view1.jspx : View1.java
1 package view.resources.backing; 2 3 import java.text.SimpleDateFormat; 4 5 import javax.faces.application.FacesMessage; 6 7 import java.util.Date; 8 import java.util.List; 9 import java.util.Map; 10 import java.util.ResourceBundle; 11 12 import java.util.regex.Matcher; 13 import java.util.regex.Pattern; 14 15 import javax.faces.component.UIComponent; 16 import javax.faces.context.FacesContext; 17 18 import javax.faces.validator.ValidatorException; 19 20 import oracle.adf.share.ADFContext; 21 import oracle.adf.view.rich.component.rich.RichDocument; 22 import oracle.adf.view.rich.component.rich.RichForm; 23 import oracle.adf.view.rich.component.rich.input.RichInputDate; 24 import oracle.adf.view.rich.component.rich.input.RichInputText; 25 import oracle.adf.view.rich.component.rich.layout.RichPanelFormLayout; 26 import oracle.adf.view.rich.component.rich.layout.RichPanelGroupLayout; 27 import oracle.adf.view.rich.component.rich.layout.RichPanelHeader; 28 import oracle.adf.view.rich.component.rich.layout.RichPanelLabelAndMessage; 29 import oracle.adf.view.rich.component.rich.nav.RichCommandButton; 30 31 import oracle.iam.identity.exception.NoSuchUserException; 32 import oracle.iam.identity.exception.UserLookupException; 33 import oracle.iam.identity.exception.UserModifyException; 34 import oracle.iam.identity.exception.UserSearchException; 35 import oracle.iam.identity.exception.ValidationFailedException; 36 import oracle.iam.identity.usermgmt.api.UserManager; 37 import oracle.iam.identity.usermgmt.vo.User; 38 import oracle.iam.identity.usermgmt.vo.UserManagerResult; 39 import oracle.iam.platform.OIMClient; 40 import oracle.iam.platform.Role; 41 42 import oracle.iam.platform.authz.exception.AccessDeniedException; 43 44 import oracle.iam.platform.entitymgr.vo.SearchCriteria; 45 46 import org.apache.myfaces.trinidad.component.UIXGroup; 47 48 import static view.resources.backing.PropertyLoader.admin; 49 import static view.resources.backing.PropertyLoader.password; 50 import static view.resources.backing.PropertyLoader.GRACE_DAYS; 51 52 53 54 public class View1 { 55 private RichForm f1; 56 private RichDocument d1; 57 private RichCommandButton cb1; 58 private UIXGroup g1; 59 private RichInputText it1; 60 private RichInputText it2; 61 private RichInputText it3; 62 private RichCommandButton cb2; 63 private String className = this.getClass().getSimpleName(); 64 private RichPanelFormLayout pfl1; 65 private RichPanelGroupLayout pgl1; 66 private RichPanelLabelAndMessage plam1; 67 private RichPanelFormLayout pfl2; 68 private RichPanelGroupLayout pgl2; 69 70 private UIXGroup g2; 71 private RichInputDate id2; 72 private RichPanelHeader ph1; 73 74 75 public void setF1(RichForm f1) { 76 this.f1 = f1; 77 } 78 79 public RichForm getF1() { 80 return f1; 81 } 82 83 public void setD1(RichDocument d1) { 84 this.d1 = d1; 85 } 86 87 public RichDocument getD1() { 88 return d1; 89 } 90 91 public void setCb1(RichCommandButton cb1) { 92 this.cb1 = cb1; 93 } 94 95 public RichCommandButton getCb1() { 96 return cb1; 97 } 98 99 private String getResourceBundleName() { 100 String method = Thread.currentThread().getStackTrace()[1] 101 .getMethodName(); 102 enter(method); 103 String wpf = ""; 104 try { 105 wpf = ResourceBundle.getBundle("view.backing.whichpropfile") 106 .getString("whichpropfile"); 107 System.out.println("wpf ->" + wpf); 108 } catch (Exception e) { 109 e.printStackTrace(); 110 System.out.println("e.getMessage ->" + e.getMessage()); 111 } 112 exit(method); 113 return wpf; 114 } 115 116 private void enter(String method) { 117 System.out.println("Entering " + method + " of class " + className); 118 } 119 120 private void exit(String method) { 121 System.out.println("Exiting " + method + " of class " + className); 122 } 123 124 public String cb1_action() { 125 String response = "false"; 126 String method = Thread.currentThread().getStackTrace()[1] 127 .getMethodName(); 128 enter(method); 129 try { 130 131 String oimUserName = it1.getValue().toString(); 132 System.out.println("oimUserName ->" + oimUserName); 133 setInSession("username", oimUserName); 134 OIMOperator oim = new OIMOperator(admin, password); 135 UserManager usersvc = oim.getUserManager(); 136 User user = usersvc.getDetails(oimUserName, null, true); 137 // make all the checks 138 // boolean otherValuesMatch = otherValuesMatch(user); 139 boolean isUserDisabled = isUserDisabled(user); 140 boolean isPinExpired = isPinExpired(user); 141 if (isUserDisabled && (!isPinExpired)) { 142 oim.logout(); 143 System.out.println("all conditions satisfied"); 144 response = "true"; 145 } 146 } catch (Exception e) { 147 e.printStackTrace(); 148 System.out.println("e.toString() ->" + e.toString()); 149 System.out.println("e.getMessage() ->" + e.getMessage()); 150 } 151 exit(method); 152 return response; 153 } 154 155 private boolean isUserDisabled(User user) { 156 String method = Thread.currentThread().getStackTrace()[1] 157 .getMethodName(); 158 enter(method); 159 boolean isDisabled = false; 160 String isDis = ""; 161 try { 162 isDis = user.getUserDisabled(); 163 System.out.println("isDis ->" + isDis); 164 if (isDis.equalsIgnoreCase("1")) { 165 isDisabled = true; 166 } 167 } catch (Exception e) { 168 169 e.printStackTrace(); 170 } 171 exit(method); 172 return isDisabled; 173 } 174 175 private boolean isEndDateInFuture(User user) { 176 String method = Thread.currentThread().getStackTrace()[1] 177 .getMethodName(); 178 enter(method); 179 boolean isEndInFuture = false; 180 Date endDate; 181 try { 182 endDate = user.getEndDate(); 183 System.out.println("endDate ->" + endDate); 184 Date currentDate = new Date(); 185 System.out.println("currentDate ->" + currentDate); 186 int dateComp = currentDate.compareTo(endDate); 187 if ((dateComp == 0) || (dateComp < 0)) { 188 isEndInFuture = true; 189 } 190 } catch (Exception e) { 191 System.out.println("e.getMessage() ->" + e.getMessage()); 192 e.printStackTrace(); 193 } 194 exit(method); 195 return isEndInFuture; 196 } 197 198 private boolean isPinExpired(User user) { 199 String method = Thread.currentThread().getStackTrace()[1] 200 .getMethodName(); 201 enter(method); 202 boolean isPinExpired = false; 203 Date startDate; 204 try { 205 startDate = (Date) user.getAttribute("PIN Start Date"); 206 System.out.println("startDate ->" + startDate); 207 long startTime = startDate.getTime(); 208 System.out.println("startTime -> " + startTime); 209 long oneday = 24 * 60 * 60 * 1000; 210 long totalGraceTime = Integer.parseInt(GRACE_DAYS) * oneday; 211 System.out.println("totalGraceTime -> " + totalGraceTime); 212 Date currentDate = new Date(); 213 long currentTime = currentDate.getTime(); 214 System.out.println("currentTime -> " + currentTime); 215 if (currentTime - startTime <= totalGraceTime) { 216 System.out.println("Within the Grace Period"); 217 isPinExpired = false; 218 } else { 219 System.out.println("Grace Period Exceeded"); 220 isPinExpired = true; 221 } 222 } catch (Exception e) { 223 System.out.println("e.getMessage() ->" + e.getMessage()); 224 e.printStackTrace(); 225 } 226 exit(method); 227 return isPinExpired; 228 } 229 230 private void setInSession(String attr, String value) { 231 String method = Thread.currentThread().getStackTrace()[1] 232 .getMethodName(); 233 enter(method); 234 try { 235 ADFContext adfCtx = ADFContext.getCurrent(); 236 Map session = adfCtx.getSessionScope(); 237 session.put(attr, value); 238 System.out.println("Added in session -> " + attr); 239 } catch (Exception e) { 240 e.printStackTrace(); 241 } 242 } 243 244 private boolean pinMatch(String uid, String tempPIN) { 245 String method = Thread.currentThread().getStackTrace()[1] 246 .getMethodName(); 247 enter(method); 248 boolean flag = false; 249 250 try { 251 OIMOperator oim = new OIMOperator(admin, password); 252 UserManager usersvc = oim.getUserManager(); 253 User user = usersvc.getDetails(uid, null, true); 254 255 String tPin = ""; 256 tPin = (String) user.getAttribute("Temp PIN"); 257 System.out.println("tPin ->" + tPin); 258 boolean tPinMatches = tPin.equalsIgnoreCase(tempPIN); 259 System.out.println("tPinMatches ->" + tPinMatches); 260 if (tPinMatches) { 261 flag = true; 262 setInSession("pin", tPin); 263 } else { 264 System.out 265 .println("set the logic to set OIM UDF ACP Counter to three or more"); 266 } 267 oim.logout(); 268 } catch (Exception e) { 269 270 e.printStackTrace(); 271 } 272 exit(method); 273 return flag; 274 } 275 276 private boolean zipMatch(String uid, String zip) { 277 String method = Thread.currentThread().getStackTrace()[1] 278 .getMethodName(); 279 enter(method); 280 boolean flag = false; 281 282 try { 283 OIMOperator oim = new OIMOperator(admin, password); 284 UserManager usersvc = oim.getUserManager(); 285 User user = usersvc.getDetails(uid, null, true); 286 287 String zipCode = ""; 288 zipCode = (String) user.getAttribute("Zip Code"); 289 System.out.println("zipCode ->" + zipCode); 290 boolean zipMatches = zip.equalsIgnoreCase(zip); 291 System.out.println("zipMatches ->" + zipMatches); 292 if (zipMatches) { 293 flag = true; 294 setInSession("zip", zipCode); 295 } 296 oim.logout(); 297 } catch (Exception e) { 298 e.printStackTrace(); 299 } 300 exit(method); 301 return flag; 302 } 303 304 private boolean dobMatch(String uid, Date dob) { 305 String method = Thread.currentThread().getStackTrace()[1] 306 .getMethodName(); 307 enter(method); 308 boolean flag = false; 309 310 try { 311 OIMOperator oim = new OIMOperator(admin, password); 312 UserManager usersvc = oim.getUserManager(); 313 User user = usersvc.getDetails(uid, null, true); 314 315 Date dobOIM = null; 316 dobOIM = (Date) user.getAttribute("Date of Birth"); 317 System.out.println("dobOIM ->" + dobOIM); 318 boolean dobMatches = dob.equals(dobOIM); 319 System.out.println("dobMatches ->" + dobMatches); 320 if (dobMatches) { 321 flag = true; 322 } 323 oim.logout(); 324 } catch (Exception e) { 325 326 e.printStackTrace(); 327 } 328 exit(method); 329 return flag; 330 } 331 332 private boolean otherValuesMatch(User user) { 333 String method = Thread.currentThread().getStackTrace()[1] 334 .getMethodName(); 335 enter(method); 336 boolean flag = false; 337 338 try { 339 340 String zip = it3.getValue().toString(); 341 System.out.println("zip ->" + zip); 342 Date dob = (Date) id2.getValue(); 343 System.out.println("dob -> " + dob); 344 345 String z = ""; 346 z = (String) user.getAttribute("Zip Code"); 347 System.out.println("z ->" + z); 348 349 Date d = null; 350 d = (Date) user.getAttribute("Date of Birth"); 351 System.out.println("d ->" + d); 352 353 boolean zipMatches = zip.equalsIgnoreCase(z); 354 System.out.println("zipMatches ->" + zipMatches); 355 boolean dobMatches = dob.equals(d); 356 System.out.println("dobMatches ->" + dobMatches); 357 358 if (zipMatches && dobMatches) { 359 flag = true; 360 361 setInSession("zip", z); 362 // setInSession("dob", d); 363 364 } 365 } catch (Exception e) { 366 367 e.printStackTrace(); 368 } 369 exit(method); 370 return flag; 371 } 372 373 public void setG1(UIXGroup g1) { 374 this.g1 = g1; 375 } 376 377 public UIXGroup getG1() { 378 return g1; 379 } 380 381 public void setIt1(RichInputText it1) { 382 this.it1 = it1; 383 } 384 385 public RichInputText getIt1() { 386 return it1; 387 } 388 389 public void setIt2(RichInputText it2) { 390 this.it2 = it2; 391 } 392 393 public RichInputText getIt2() { 394 return it2; 395 } 396 397 public void setIt3(RichInputText it3) { 398 this.it3 = it3; 399 } 400 401 public RichInputText getIt3() { 402 return it3; 403 } 404 405 public void setCb2(RichCommandButton cb2) { 406 this.cb2 = cb2; 407 } 408 409 public RichCommandButton getCb2() { 410 return cb2; 411 } 412 413 public void setPfl1(RichPanelFormLayout pfl1) { 414 this.pfl1 = pfl1; 415 } 416 417 public RichPanelFormLayout getPfl1() { 418 return pfl1; 419 } 420 421 public void setPgl1(RichPanelGroupLayout pgl1) { 422 this.pgl1 = pgl1; 423 } 424 425 public RichPanelGroupLayout getPgl1() { 426 return pgl1; 427 } 428 429 public void setPlam1(RichPanelLabelAndMessage plam1) { 430 this.plam1 = plam1; 431 } 432 433 public RichPanelLabelAndMessage getPlam1() { 434 return plam1; 435 } 436 437 public void setPfl2(RichPanelFormLayout pfl2) { 438 this.pfl2 = pfl2; 439 } 440 441 public RichPanelFormLayout getPfl2() { 442 return pfl2; 443 } 444 445 public void setPgl2(RichPanelGroupLayout pgl2) { 446 this.pgl2 = pgl2; 447 } 448 449 public RichPanelGroupLayout getPgl2() { 450 return pgl2; 451 } 452 453 public void setG2(UIXGroup g2) { 454 this.g2 = g2; 455 } 456 457 public UIXGroup getG2() { 458 return g2; 459 } 460 461 public void it3_validator(FacesContext facesContext, 462 UIComponent uIComponent, Object object) { 463 464 FacesContext fc = FacesContext.getCurrentInstance(); 465 String zipCode = (String) object; 466 System.out.println("zipCode -> " + zipCode); 467 468 if (!isNumeric(zipCode)) { 469 throw new ValidatorException(new FacesMessage( 470 FacesMessage.SEVERITY_ERROR, 471 "Zip Code should be all numeric", null)); 472 } 473 474 if (!zipMatch((String) getIt1().getValue(), zipCode)) { 475 throw new ValidatorException(new FacesMessage( 476 FacesMessage.SEVERITY_ERROR, "Zip Code is not correct", 477 null)); 478 } 479 480 } 481 482 private boolean isNumeric(String str) { 483 String method = Thread.currentThread().getStackTrace()[1] 484 .getMethodName(); 485 enter(method); 486 boolean flag = true; 487 try { 488 489 int d = Integer.parseInt(str); 490 System.out.println("d -> " + d); 491 } catch (NumberFormatException nfe) { 492 nfe.printStackTrace(); 493 flag = false; 494 } 495 exit(method); 496 return flag; 497 } 498 499 public void setId2(RichInputDate id2) { 500 this.id2 = id2; 501 } 502 503 public RichInputDate getId2() { 504 return id2; 505 } 506 507 public void setPh1(RichPanelHeader ph1) { 508 this.ph1 = ph1; 509 } 510 511 public RichPanelHeader getPh1() { 512 return ph1; 513 } 514 515 private boolean checkAlphaNumeric(String s) { 516 Pattern ALPHA = Pattern.compile("[A-Za-z]+"); 517 Pattern NUMERIC = Pattern.compile("[0-9]+"); 518 if (s == null) { 519 return false; 520 } else { 521 Matcher m = ALPHA.matcher(s); 522 Matcher m2 = NUMERIC.matcher(s); 523 return (m.matches() || m2.matches()); 524 } 525 } 526 527 private boolean isUserExist(String userid) { 528 boolean flag = false; 529 String method = Thread.currentThread().getStackTrace()[1] 530 .getMethodName(); 531 enter(method); 532 try { 533 534 } catch (Exception e) { 535 e.printStackTrace(); 536 } 537 exit(method); 538 return flag; 539 } 540 541 public void it1_validator(FacesContext facesContext, 542 UIComponent uIComponent, Object object) { 543 String oimUserName = (String) object; 544 System.out.println("oimUserName -> " + oimUserName); 545 if (checkAlphaNumeric(oimUserName)) { 546 System.out.println("Alphanumeric"); 547 } else { 548 System.out.println("Not alphanumeric"); 549 throw new ValidatorException(new FacesMessage( 550 FacesMessage.SEVERITY_ERROR, "UID should be AlphaNumeric", 551 null)); 552 } 553 OIMOperator oim = new OIMOperator(admin, password); 554 UserManager usersvc = oim.getUserManager(); 555 SearchCriteria criteria = new SearchCriteria("User Login", oimUserName, 556 SearchCriteria.Operator.EQUAL); 557 List<User> result = null; 558 559 try { 560 result = usersvc.search(criteria, null, null); 561 } catch (AccessDeniedException e) { 562 e.printStackTrace(); 563 } catch (UserSearchException e) { 564 e.printStackTrace(); 565 } 566 oim.logout(); 567 if (result.size() == 0) { 568 System.out.println("UID does not exist"); 569 throw new ValidatorException(new FacesMessage( 570 FacesMessage.SEVERITY_ERROR, "UID does not exist", null)); 571 } 572 573 } 574 575 private int pinValidCount = 0; 576 577 private boolean fetchPinValidCount(User user) { 578 String method = Thread.currentThread().getStackTrace()[1] 579 .getMethodName(); 580 enter(method); 581 boolean pinValidCount = true; 582 try { 583 String pinAttempt = ""; 584 pinAttempt = (String) user.getAttribute("PINAttempt"); 585 System.out.println("pinAttempt ->" + pinAttempt); 586 int pinAttemptCount = Integer.parseInt(pinAttempt); 587 588 if (pinAttemptCount >= 3) { 589 System.out.println("pinAttempt limit exceeded"); 590 pinValidCount = false; 591 } 592 } catch (Exception e) { 593 e.printStackTrace(); 594 } 595 exit(method); 596 return pinValidCount; 597 } 598 599 private int getWrongPinAttempt(User user) { 600 String method = Thread.currentThread().getStackTrace()[1] 601 .getMethodName(); 602 enter(method); 603 int pinAttemptCount = 0; 604 try { 605 String pinAttempt = (String) user.getAttribute("PINAttempt"); 606 pinAttemptCount = Integer.parseInt(pinAttempt); 607 System.out.println("pinAttemptCount -> " + pinAttemptCount); 608 if (pinAttemptCount >= 3) { 609 System.out.println(" pinAttemptCount is 3 or more"); 610 // call pinInValidate 611 } else { 612 pinAttemptCount = pinAttemptCount + 1; 613 } 614 } catch (Exception e) { 615 e.printStackTrace(); 616 } 617 exit(method); 618 return pinAttemptCount; 619 } 620 621 public void it2_validator(FacesContext facesContext, 622 UIComponent uIComponent, Object object) { 623 String method = Thread.currentThread().getStackTrace()[1] 624 .getMethodName(); 625 enter(method); 626 627 String pin = (String) object; 628 System.out.println("pin -> " + pin); 629 String uid = (String) getIt1().getValue(); 630 System.out.println("uid ->" + uid); 631 OIMOperator oim = new OIMOperator(admin, password); 632 UserManager usersvc = oim.getUserManager(); 633 User user; 634 try { 635 user = usersvc.getDetails(uid, null, true); 636 } catch (AccessDeniedException e) { 637 e.printStackTrace(); 638 } catch (NoSuchUserException e) { 639 e.printStackTrace(); 640 } catch (UserLookupException e) { 641 e.printStackTrace(); 642 } 643 boolean fetchPinValidCount = fetchPinValidCount(user); 644 System.out.println("fetchPinValidCount -> " + fetchPinValidCount); 645 if (!fetchPinValidCount) { 646 Date pinVAlidityDate = (Date) user.getAttribute("PINVAlidityDate"); 647 648 throw new ValidatorException(new FacesMessage( 649 FacesMessage.SEVERITY_ERROR, 650 "PIN Attempt Limit is Reached", null)); 651 } 652 boolean isPinValid = pinMatch(uid, pin); 653 if (!isPinValid) { 654 System.out.println("PIN is not valid"); 655 int pinAttemptCount = getWrongPinAttempt(user); 656 String pinAttempt = String.valueOf(pinAttemptCount); 657 System.out.println("pinAttempt -> " + pinAttempt); 658 user.setAttribute("PINAttempt", pinAttempt); 659 try { 660 usersvc.modify(user); 661 } catch (ValidationFailedException e) { 662 e.printStackTrace(); 663 } catch (AccessDeniedException e) { 664 e.printStackTrace(); 665 } catch (UserModifyException e) { 666 e.printStackTrace(); 667 } catch (NoSuchUserException e) { 668 e.printStackTrace(); 669 } 670 throw new ValidatorException(new FacesMessage( 671 FacesMessage.SEVERITY_ERROR, "PIN is not valid", null)); 672 } 673 oim.logout(); 674 exit(method); 675 676 } 677 678 public void id2_validator2(FacesContext facesContext, 679 UIComponent uIComponent, Object object) { 680 Date dob = (Date) object; 681 System.out.println("dob -> " + dob); 682 if (!dobMatch((String) getIt1().getValue(), dob)) { 683 throw new ValidatorException(new FacesMessage( 684 FacesMessage.SEVERITY_ERROR, 685 "Date of Birth is not correct", null)); 686 } 687 } 688 } 689
Screen 2 : ChangePassword.jspx
Source
1 <?xml version='1.0' encoding='windows-1252'?> 2 <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1" 3 xmlns:f="http://java.sun.com/jsf/core" 4 xmlns:af="http://xmlns.oracle.com/adf/faces/rich" 5 xmlns:c="http://java.sun.com/jsp/jstl/core"> 6 <c:set var="viewcontrollerBundle" 7 value="#{adfBundle['view.resources.ViewControllerBundle']}"/> 8 <jsp:directive.page contentType="text/html;charset=windows-1252"/> 9 <f:view> 10 <af:document id="d1" title="Change Password Page" 11 binding="#{backingBeanScope.backing_ChangePassword.d1}"> 12 <af:form id="f1" binding="#{backingBeanScope.backing_ChangePassword.f1}"> 13 <af:pageTemplate viewId="/oracle/templates/threeColumnTemplate.jspx" 14 id="pt1"> 15 <f:facet name="center"> 16 17 <af:panelFormLayout binding="#{backingBeanScope.backing_ChangePassword.pfl1}" 18 id="pfl1" rows="99" maxColumns="1"> 19 20 <af:panelLabelAndMessage label="Password Information" 21 binding="#{backingBeanScope.backing_ChangePassword.plam1}" 22 id="plam1"/> 23 <af:inputText label="Password " 24 binding="#{backingBeanScope.backing_ChangePassword.it1}" 25 id="it1" showRequired="true" secret="true" 26 required="true"/> 27 <af:inputText label="New Password " 28 binding="#{backingBeanScope.backing_ChangePassword.it2}" 29 id="it2" secret="true" showRequired="true" 30 required="true"/> 31 <af:inputText label="Confirm New Password" 32 binding="#{backingBeanScope.backing_ChangePassword.it3}" 33 id="it3" secret="true" showRequired="true" 34 validator="#{backingBeanScope.backing_ChangePassword.it3_validator}" 35 required="true"/> 36 37 <af:panelLabelAndMessage label="Challenge Question and Answers" 38 binding="#{backingBeanScope.backing_ChangePassword.plam2}" 39 id="plam2"/> 40 41 <af:panelGroupLayout id="pgl1" layout="horizontal"> 42 <af:selectOneChoice label="Question 1 : " 43 binding="#{backingBeanScope.backing_ChangePassword.soc1}" 44 id="soc1" showRequired="true" 45 required="true"> 46 <f:selectItems value="#{challengeQnABean.selectItems}" 47 id="si1"/> 48 </af:selectOneChoice> 49 <af:inputText label="Answer 1 : " 50 binding="#{backingBeanScope.backing_ChangePassword.it5}" 51 id="it5" showRequired="true" required="true"/> 52 </af:panelGroupLayout> 53 <af:panelGroupLayout id="pgl2" layout="horizontal"> 54 <af:selectOneChoice label="Question 2 : " 55 binding="#{backingBeanScope.backing_ChangePassword.soc2}" 56 id="soc2" showRequired="true" 57 required="true"> 58 <f:selectItems value="#{challengeQnABean.selectItems}" 59 id="si2"/> 60 </af:selectOneChoice> 61 <af:inputText label="Answer 2 : " 62 binding="#{backingBeanScope.backing_ChangePassword.it6}" 63 id="it6" showRequired="true" required="true"/> 64 </af:panelGroupLayout> 65 <af:panelGroupLayout id="pgl3" layout="horizontal"> 66 <af:selectOneChoice label="Question 3 : " 67 binding="#{backingBeanScope.backing_ChangePassword.soc3}" 68 id="soc3" showRequired="true" 69 validator="#{backingBeanScope.backing_ChangePassword.soc3_validator}" 70 required="true"> 71 <f:selectItems value="#{challengeQnABean.selectItems}" 72 id="si3"/> 73 </af:selectOneChoice> 74 <af:inputText label="Answer 3 : " 75 binding="#{backingBeanScope.backing_ChangePassword.it7}" 76 id="it7" showRequired="true" 77 validator="#{backingBeanScope.backing_ChangePassword.it7_validator}" 78 required="true"/> 79 </af:panelGroupLayout> 80 81 <af:panelGroupLayout binding="#{backingBeanScope.backing_ChangePassword.pgl4}" 82 id="pgl4"> 83 <af:commandButton text="Submit" 84 binding="#{backingBeanScope.backing_ChangePassword.cb1}" 85 id="cb1" 86 action="#{backingBeanScope.backing_ChangePassword.cb1_action}"/> 87 <af:commandButton text="Cancel" 88 binding="#{backingBeanScope.backing_ChangePassword.cb2}" 89 id="cb2" 90 action="#{backingBeanScope.backing_ChangePassword.cb2_action}"/> 91 </af:panelGroupLayout> 92 93 </af:panelFormLayout> 94 </f:facet> 95 <f:facet name="header"/> 96 <f:facet name="end"/> 97 <f:facet name="start"/> 98 <f:facet name="branding"/> 99 <f:facet name="copyright"/> 100 <f:facet name="status"/> 101 </af:pageTemplate> 102 </af:form> 103 </af:document> 104 </f:view> 105 <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_ChangePassword--> 106 </jsp:root> 107
Backing Bean for ChangePassword.jspx : ChangePassword.java
1 package view.resources.backing; 2 3 import java.util.Date; 4 import java.util.HashMap; 5 import java.util.List; 6 import java.util.Map; 7 8 import javax.faces.application.FacesMessage; 9 import javax.faces.component.UIComponent; 10 import javax.faces.component.UISelectItems; 11 import javax.faces.context.ExternalContext; 12 import javax.faces.context.FacesContext; 13 import javax.faces.validator.ValidatorException; 14 15 import javax.servlet.http.HttpServletResponse; 16 17 import javax.servlet.http.HttpSession; 18 19 import model.UpdateDb; 20 21 import oracle.adf.share.ADFContext; 22 import oracle.adf.view.rich.component.rich.RichDocument; 23 import oracle.adf.view.rich.component.rich.RichForm; 24 import oracle.adf.view.rich.component.rich.input.RichInputListOfValues; 25 import oracle.adf.view.rich.component.rich.input.RichInputText; 26 import oracle.adf.view.rich.component.rich.input.RichSelectItem; 27 import oracle.adf.view.rich.component.rich.input.RichSelectOneChoice; 28 import oracle.adf.view.rich.component.rich.layout.RichPanelFormLayout; 29 import oracle.adf.view.rich.component.rich.layout.RichPanelGroupLayout; 30 import oracle.adf.view.rich.component.rich.layout.RichPanelHeader; 31 import oracle.adf.view.rich.component.rich.layout.RichPanelLabelAndMessage; 32 import oracle.adf.view.rich.component.rich.nav.RichCommandButton; 33 import oracle.adf.view.rich.component.rich.output.RichOutputLabel; 34 import oracle.adf.view.rich.component.rich.output.RichSeparator; 35 36 import oracle.iam.identity.usermgmt.api.UserManager; 37 import oracle.iam.identity.usermgmt.vo.User; 38 import oracle.iam.identity.usermgmt.vo.UserManagerResult; 39 40 import org.apache.myfaces.trinidad.component.UIXGroup; 41 42 import static view.resources.backing.PropertyLoader.admin; 43 import static view.resources.backing.PropertyLoader.password; 44 import static view.resources.backing.PropertyLoader.oimLogin; 45 46 public class ChangePassword { 47 private RichForm f1; 48 private RichDocument d1; 49 private RichInputText it1; 50 private UIXGroup g1; 51 private RichInputText it2; 52 private RichInputText it3; 53 private RichSeparator s1; 54 private RichOutputLabel ol1; 55 private RichInputListOfValues ilov1; 56 private RichSelectOneChoice soc1; 57 private RichSelectItem si1; 58 private List challengeQnA; 59 private RichSelectOneChoice soc2; 60 private UISelectItems si2; 61 private RichSelectOneChoice soc3; 62 private UISelectItems si3; 63 private RichCommandButton cb1; 64 private RichCommandButton cb2; 65 private RichInputText it5; 66 private RichInputText it6; 67 private RichInputText it7; 68 private String className = this.getClass().getSimpleName(); 69 private RichPanelFormLayout pfl1; 70 private RichPanelLabelAndMessage plam1; 71 private RichPanelFormLayout pfl2; 72 private UIXGroup g2; 73 74 private RichPanelLabelAndMessage plam2; 75 private UIXGroup g3; 76 77 private RichPanelGroupLayout pgl4; 78 // private UIXGroup g1; 79 private RichPanelHeader ph1; 80 private RichPanelLabelAndMessage plam3; 81 private RichInputText it4; 82 private RichInputText it8; 83 private RichInputText it9; 84 private UIXGroup g4; 85 private RichPanelLabelAndMessage plam4; 86 private RichPanelGroupLayout pgl1; 87 private RichSelectOneChoice soc4; 88 private UISelectItems si4; 89 private RichInputText it10; 90 private RichPanelGroupLayout pgl2; 91 private RichSelectOneChoice soc5; 92 private UISelectItems si5; 93 private RichInputText it11; 94 private RichPanelGroupLayout pgl3; 95 private RichSelectOneChoice soc6; 96 private UISelectItems si6; 97 private RichInputText it12; 98 private UIXGroup g5; 99 private RichPanelGroupLayout pgl5; 100 private RichCommandButton cb3; 101 private RichCommandButton cb4; 102 private RichPanelHeader ph2; 103 // private RichPanelFormLayout pfl2; 104 private RichPanelFormLayout pfl3; 105 106 // private RichGoImageLink gil1; 107 108 public void setF1(RichForm f1) { 109 this.f1 = f1; 110 } 111 112 public RichForm getF1() { 113 return f1; 114 } 115 116 public void setD1(RichDocument d1) { 117 this.d1 = d1; 118 } 119 120 public RichDocument getD1() { 121 return d1; 122 } 123 124 public void setIt1(RichInputText it1) { 125 this.it1 = it1; 126 } 127 128 public RichInputText getIt1() { 129 return it1; 130 } 131 132 public void setG1(UIXGroup g1) { 133 this.g1 = g1; 134 } 135 136 public UIXGroup getG1() { 137 return g1; 138 } 139 140 public void setIt2(RichInputText it2) { 141 this.it2 = it2; 142 } 143 144 public RichInputText getIt2() { 145 return it2; 146 } 147 148 public void setIt3(RichInputText it3) { 149 this.it3 = it3; 150 } 151 152 public RichInputText getIt3() { 153 return it3; 154 } 155 156 public void setS1(RichSeparator s1) { 157 this.s1 = s1; 158 } 159 160 public RichSeparator getS1() { 161 return s1; 162 } 163 164 public void setOl1(RichOutputLabel ol1) { 165 this.ol1 = ol1; 166 } 167 168 public RichOutputLabel getOl1() { 169 return ol1; 170 } 171 172 public void setIlov1(RichInputListOfValues ilov1) { 173 this.ilov1 = ilov1; 174 } 175 176 public RichInputListOfValues getIlov1() { 177 return ilov1; 178 } 179 180 public void setSoc1(RichSelectOneChoice soc1) { 181 this.soc1 = soc1; 182 } 183 184 public RichSelectOneChoice getSoc1() { 185 return soc1; 186 } 187 188 public void setSi1(RichSelectItem si1) { 189 this.si1 = si1; 190 } 191 192 public RichSelectItem getSi1() { 193 return si1; 194 } 195 196 public void setChallengeQnA(List challengeQnA) { 197 this.challengeQnA = challengeQnA; 198 } 199 200 public List getChallengeQnA() { 201 OIMOperator oim = new OIMOperator(admin, password); 202 return oim.getChallengeAnswersAsList(); 203 // return challengeQnA; 204 } 205 206 public void setSoc2(RichSelectOneChoice soc2) { 207 this.soc2 = soc2; 208 } 209 210 public RichSelectOneChoice getSoc2() { 211 return soc2; 212 } 213 214 public void setSi2(UISelectItems si2) { 215 this.si2 = si2; 216 } 217 218 public UISelectItems getSi2() { 219 return si2; 220 } 221 222 public void setSoc3(RichSelectOneChoice soc3) { 223 this.soc3 = soc3; 224 } 225 226 public RichSelectOneChoice getSoc3() { 227 return soc3; 228 } 229 230 public void setSi3(UISelectItems si3) { 231 this.si3 = si3; 232 } 233 234 public UISelectItems getSi3() { 235 return si3; 236 } 237 238 public void setCb1(RichCommandButton cb1) { 239 this.cb1 = cb1; 240 } 241 242 public RichCommandButton getCb1() { 243 return cb1; 244 } 245 246 public void setCb2(RichCommandButton cb2) { 247 this.cb2 = cb2; 248 } 249 250 public RichCommandButton getCb2() { 251 return cb2; 252 } 253 254 private void enter(String method) { 255 System.out.println("Entering " + method + " of class " + className); 256 } 257 258 private void exit(String method) { 259 System.out.println("Exiting " + method + " of class " + className); 260 } 261 262 private String getFromSession(String attr) { 263 String method = Thread.currentThread().getStackTrace()[1] 264 .getMethodName(); 265 enter(method); 266 String value = ""; 267 try { 268 ADFContext adfCtx = ADFContext.getCurrent(); 269 Map session = adfCtx.getSessionScope(); 270 value = (String) session.get(attr); 271 System.out.println("retrived from session -> " + value); 272 } catch (Exception e) { 273 e.printStackTrace(); 274 } 275 exit(method); 276 return value; 277 } 278 279 public String cb1_action() { 280 String response = "false"; 281 String method = Thread.currentThread().getStackTrace()[1] 282 .getMethodName(); 283 enter(method); 284 try { 285 String oimUserName = getFromSession("username"); 286 System.out.println("oimUserName ->" + oimUserName); 287 String mail = getFromSession("email"); 288 System.out.println("mail ->" + mail); 289 String oldPassword = it1.getValue().toString(); 290 System.out.println("oldPassword ->" + oldPassword); 291 String newPassword = it2.getValue().toString(); 292 System.out.println("newPassword ->" + newPassword); 293 294 // Update the user in DB first and then proceed 295 UpdateDb updateDB = new UpdateDb(); 296 297 String dbResult = updateDB.updateClaimTable(oimUserName, mail); 298 System.out.println("dbResult -> " + dbResult); 299 300 if (dbResult.equalsIgnoreCase("CLAIMED")) { 301 String q1 = soc1.getValue().toString(); 302 System.out.println("q1 ->" + q1); 303 String q2 = soc2.getValue().toString(); 304 System.out.println("q2 ->" + q2); 305 String q3 = soc3.getValue().toString(); 306 System.out.println("q3 ->" + q3); 307 308 Object a1 = it5.getValue(); 309 System.out.println("a1 ->" + a1); 310 Object a2 = it6.getValue(); 311 System.out.println("a2 ->" + a2); 312 Object a3 = it7.getValue(); 313 System.out.println("a3 ->" + a3); 314 System.out 315 .println("enable the user first so that he can login"); 316 boolean isEnabledNow = enableUser(oimUserName); // Enable the 317 // user first 318 System.out.println(" isEnabledNow-> Modifed the flow -> " 319 + isEnabledNow); 320 321 OIMOperator useroim = new OIMOperator(oimUserName, oldPassword); 322 Map<String, Object> quesAnsMap = new HashMap<String, Object>(); 323 quesAnsMap.put(q1, a1); 324 quesAnsMap.put(q2, a2); 325 quesAnsMap.put(q3, a3); 326 327 if (isEnabledNow) { 328 boolean chgPass, chgQnA = false; 329 chgPass = useroim.changePassword(oldPassword, newPassword, 330 newPassword); 331 System.out.println("chgPass -> " + chgPass); 332 if (chgPass) { 333 chgQnA = useroim.setChallengeValues(quesAnsMap); 334 System.out.println("chgQnA -> " + chgQnA); 335 boolean isErrorInOIM = useroim.isError(); 336 System.out.println(" isErrorInOIM -> " + isErrorInOIM); 337 } 338 if (chgPass && chgQnA) { 339 System.out 340 .println(" Both Password Changed as well as Challenge QnA set-> "); 341 response = "true"; 342 } 343 } 344 boolean isUserOimError = useroim.isError(); 345 if (isUserOimError) { 346 disableUser(oimUserName); 347 } 348 useroim.logout(); 349 350 FacesContext ctx = FacesContext.getCurrentInstance(); 351 System.out.println("ctx ->" + ctx); 352 ExternalContext ectx = ctx.getExternalContext(); 353 System.out.println("ectx ->" + ectx); 354 355 HttpServletResponse hresponse; 356 hresponse = (HttpServletResponse) ectx.getResponse(); 357 HttpSession session = (HttpSession) ectx.getSession(false); 358 session.invalidate(); 359 hresponse.sendRedirect(oimLogin); 360 ctx.responseComplete(); 361 System.out.println("Exiting cb1_action () Aug 08->"); 362 } else { 363 response = dbResult; 364 } 365 System.out.println("Exiting cb1_action () Aug 08->"); 366 367 } catch (Exception e) { 368 e.printStackTrace(); 369 } 370 exit(method); 371 return response; 372 } 373 374 private boolean setEndDate(String oimUserName) { 375 String method = Thread.currentThread().getStackTrace()[1] 376 .getMethodName(); 377 enter(method); 378 boolean isEndSet = false; 379 380 try { 381 OIMOperator systemoim = new OIMOperator(admin, password); 382 UserManager usersvc = systemoim.getUserManager(); 383 User user = usersvc.getDetails(oimUserName, null, true); 384 user.setEndDate(null); 385 UserManagerResult umr = usersvc.modify(user); 386 String status = umr.getStatus(); 387 if (status.equalsIgnoreCase("COMPLETED")) { 388 System.out.println("endDate set successfully"); 389 isEndSet = true; 390 } else { 391 System.out.println("endDate not set -> "); 392 } 393 394 systemoim.logout(); 395 } catch (Exception e) { 396 System.out.println("e.getMessage() ->" + e.getMessage()); 397 e.printStackTrace(); 398 } 399 exit(method); 400 return isEndSet; 401 } 402 403 private boolean disableUser(String uid) { 404 String method = Thread.currentThread().getStackTrace()[1] 405 .getMethodName(); 406 enter(method); 407 boolean flag = false; 408 try { 409 OIMOperator oim = new OIMOperator(admin, password); 410 UserManagerResult umr = null; 411 UserManager usersvc = oim.getUserManager(); 412 User user = usersvc.getDetails(uid, null, true); 413 if (user.getUserDisabled().equalsIgnoreCase("0")) { 414 umr = usersvc.disable(uid, true); 415 } 416 String status = ""; 417 if (umr != null) 418 status = umr.getStatus(); 419 System.out.println("status ->" + status); 420 if (status.equalsIgnoreCase("COMPLETED")) { 421 flag = true; 422 } 423 oim.logout(); 424 } catch (Exception e) { 425 e.printStackTrace(); 426 System.out.println("e.toString() ->" + e.toString()); 427 System.out.println("e.getMessage() ->" + e.getMessage()); 428 } 429 exit(method); 430 return flag; 431 } 432 433 private boolean enableUser(String uid) { 434 String method = Thread.currentThread().getStackTrace()[1] 435 .getMethodName(); 436 enter(method); 437 boolean flag = false; 438 try { 439 OIMOperator oim = new OIMOperator(admin, password); 440 UserManagerResult umr = null; 441 UserManager usersvc = oim.getUserManager(); 442 User user = usersvc.getDetails(uid, null, true); 443 if (user.getUserDisabled().equalsIgnoreCase("1")) { 444 umr = usersvc.enable(uid, true); 445 } 446 String status = ""; 447 if (umr != null) 448 status = umr.getStatus(); 449 System.out.println("status ->" + status); 450 if (status.equalsIgnoreCase("COMPLETED")) { 451 flag = true; 452 } 453 oim.logout(); 454 } catch (Exception e) { 455 e.printStackTrace(); 456 System.out.println("e.toString() ->" + e.toString()); 457 System.out.println("e.getMessage() ->" + e.getMessage()); 458 } 459 exit(method); 460 return flag; 461 } 462 463 public String cb2_action() { 464 // Add event code here... 465 return null; 466 } 467 468 public void setIt5(RichInputText it5) { 469 this.it5 = it5; 470 } 471 472 public RichInputText getIt5() { 473 return it5; 474 } 475 476 public void setIt6(RichInputText it6) { 477 this.it6 = it6; 478 } 479 480 public RichInputText getIt6() { 481 return it6; 482 } 483 484 public void setIt7(RichInputText it7) { 485 this.it7 = it7; 486 } 487 488 public RichInputText getIt7() { 489 return it7; 490 } 491 492 public void it3_validator(FacesContext facesContext, 493 UIComponent uIComponent, Object object) { 494 495 String rit3 = (String) object; 496 System.out.println("rit3 ->" + rit3); 497 RichInputText rit2 = getIt2(); 498 String rit2_s = (String) rit2.getValue(); 499 System.out.println(" rit2_s ->" + rit2_s); 500 if (!(rit3.equalsIgnoreCase(rit2_s))) { 501 throw new ValidatorException( 502 new FacesMessage( 503 FacesMessage.SEVERITY_ERROR, 504 "New Password and Confirm New Password do not match.", 505 null)); 506 } 507 } 508 509 public void it7_validator(FacesContext facesContext, 510 UIComponent uIComponent, Object object) { 511 String rit7 = (String) object; 512 System.out.println("rit7 ->" + rit7); 513 514 RichInputText rit5 = getIt5(); 515 String rit5_s = (String) rit5.getValue(); 516 System.out.println(" rit5_s ->" + rit5_s); 517 518 RichInputText rit6 = getIt6(); 519 String rit6_s = (String) rit6.getValue(); 520 System.out.println(" rit6_s ->" + rit6_s); 521 522 boolean a = rit7.equalsIgnoreCase(rit5_s); 523 boolean b = rit7.equalsIgnoreCase(rit6_s); 524 boolean c = rit5_s.equalsIgnoreCase(rit6_s); 525 if (a || b || c) { 526 throw new ValidatorException(new FacesMessage( 527 FacesMessage.SEVERITY_ERROR, 528 "All Answers should be uniquely set.", null)); 529 } 530 } 531 532 public void setPfl1(RichPanelFormLayout pfl1) { 533 this.pfl1 = pfl1; 534 } 535 536 public RichPanelFormLayout getPfl1() { 537 return pfl1; 538 } 539 540 public void setPlam1(RichPanelLabelAndMessage plam1) { 541 this.plam1 = plam1; 542 } 543 544 public RichPanelLabelAndMessage getPlam1() { 545 return plam1; 546 } 547 548 public void setPfl2(RichPanelFormLayout pfl2) { 549 this.pfl2 = pfl2; 550 } 551 552 public RichPanelFormLayout getPfl2() { 553 return pfl2; 554 } 555 556 public void setG2(UIXGroup g2) { 557 this.g2 = g2; 558 } 559 560 public UIXGroup getG2() { 561 return g2; 562 } 563 564 public void setPlam2(RichPanelLabelAndMessage plam2) { 565 this.plam2 = plam2; 566 } 567 568 public RichPanelLabelAndMessage getPlam2() { 569 return plam2; 570 } 571 572 public void setG3(UIXGroup g3) { 573 this.g3 = g3; 574 } 575 576 public UIXGroup getG3() { 577 return g3; 578 } 579 580 public void setPgl4(RichPanelGroupLayout pgl4) { 581 this.pgl4 = pgl4; 582 } 583 584 public RichPanelGroupLayout getPgl4() { 585 return pgl4; 586 } 587 588 public void soc3_validator(FacesContext facesContext, 589 UIComponent uIComponent, Object object) { 590 591 String soc3 = (String) object; 592 System.out.println(" soc3 -> " + soc3); 593 594 RichSelectOneChoice soc1 = getSoc1(); 595 String soc1_s = (String) soc1.getValue(); 596 System.out.println(" soc1_s ->" + soc1_s); 597 598 RichSelectOneChoice soc2 = getSoc2(); 599 String soc2_s = (String) soc2.getValue(); 600 System.out.println(" soc2_s ->" + soc2_s); 601 602 boolean a = soc3.equalsIgnoreCase(soc1_s); 603 boolean b = soc3.equalsIgnoreCase(soc2_s); 604 boolean c = soc1_s.equalsIgnoreCase(soc2_s); 605 if (a || b || c) { 606 throw new ValidatorException(new FacesMessage( 607 FacesMessage.SEVERITY_ERROR, 608 "All Questions should be uniquely set.", null)); 609 } 610 611 } 612 613 public void setPh1(RichPanelHeader ph1) { 614 this.ph1 = ph1; 615 } 616 617 public RichPanelHeader getPh1() { 618 return ph1; 619 } 620 621 public void setPlam3(RichPanelLabelAndMessage plam3) { 622 this.plam3 = plam3; 623 } 624 625 public RichPanelLabelAndMessage getPlam3() { 626 return plam3; 627 } 628 629 public void setIt4(RichInputText it4) { 630 this.it4 = it4; 631 } 632 633 public RichInputText getIt4() { 634 return it4; 635 } 636 637 public void setIt8(RichInputText it8) { 638 this.it8 = it8; 639 } 640 641 public RichInputText getIt8() { 642 return it8; 643 } 644 645 public void setIt9(RichInputText it9) { 646 this.it9 = it9; 647 } 648 649 public RichInputText getIt9() { 650 return it9; 651 } 652 653 public void setG4(UIXGroup g4) { 654 this.g4 = g4; 655 } 656 657 public UIXGroup getG4() { 658 return g4; 659 } 660 661 public void setPlam4(RichPanelLabelAndMessage plam4) { 662 this.plam4 = plam4; 663 } 664 665 public RichPanelLabelAndMessage getPlam4() { 666 return plam4; 667 } 668 669 public void setPgl1(RichPanelGroupLayout pgl1) { 670 this.pgl1 = pgl1; 671 } 672 673 public RichPanelGroupLayout getPgl1() { 674 return pgl1; 675 } 676 677 public void setSoc4(RichSelectOneChoice soc4) { 678 this.soc4 = soc4; 679 } 680 681 public RichSelectOneChoice getSoc4() { 682 return soc4; 683 } 684 685 public void setSi4(UISelectItems si4) { 686 this.si4 = si4; 687 } 688 689 public UISelectItems getSi4() { 690 return si4; 691 } 692 693 public void setIt10(RichInputText it10) { 694 this.it10 = it10; 695 } 696 697 public RichInputText getIt10() { 698 return it10; 699 } 700 701 public void setPgl2(RichPanelGroupLayout pgl2) { 702 this.pgl2 = pgl2; 703 } 704 705 public RichPanelGroupLayout getPgl2() { 706 return pgl2; 707 } 708 709 public void setSoc5(RichSelectOneChoice soc5) { 710 this.soc5 = soc5; 711 } 712 713 public RichSelectOneChoice getSoc5() { 714 return soc5; 715 } 716 717 public void setSi5(UISelectItems si5) { 718 this.si5 = si5; 719 } 720 721 public UISelectItems getSi5() { 722 return si5; 723 } 724 725 public void setIt11(RichInputText it11) { 726 this.it11 = it11; 727 } 728 729 public RichInputText getIt11() { 730 return it11; 731 } 732 733 public void setPgl3(RichPanelGroupLayout pgl3) { 734 this.pgl3 = pgl3; 735 } 736 737 public RichPanelGroupLayout getPgl3() { 738 return pgl3; 739 } 740 741 public void setSoc6(RichSelectOneChoice soc6) { 742 this.soc6 = soc6; 743 } 744 745 public RichSelectOneChoice getSoc6() { 746 return soc6; 747 } 748 749 public void setSi6(UISelectItems si6) { 750 this.si6 = si6; 751 } 752 753 public UISelectItems getSi6() { 754 return si6; 755 } 756 757 public void setIt12(RichInputText it12) { 758 this.it12 = it12; 759 } 760 761 public RichInputText getIt12() { 762 return it12; 763 } 764 765 public void setG5(UIXGroup g5) { 766 this.g5 = g5; 767 } 768 769 public UIXGroup getG5() { 770 return g5; 771 } 772 773 public void setPgl5(RichPanelGroupLayout pgl5) { 774 this.pgl5 = pgl5; 775 } 776 777 public RichPanelGroupLayout getPgl5() { 778 return pgl5; 779 } 780 781 public void setCb3(RichCommandButton cb3) { 782 this.cb3 = cb3; 783 } 784 785 public RichCommandButton getCb3() { 786 return cb3; 787 } 788 789 public void setCb4(RichCommandButton cb4) { 790 this.cb4 = cb4; 791 } 792 793 public RichCommandButton getCb4() { 794 return cb4; 795 } 796 797 public void setPh2(RichPanelHeader ph2) { 798 this.ph2 = ph2; 799 } 800 801 public RichPanelHeader getPh2() { 802 return ph2; 803 } 804 805 public void setPfl3(RichPanelFormLayout pfl3) { 806 this.pfl3 = pfl3; 807 } 808 809 public RichPanelFormLayout getPfl3() { 810 return pfl3; 811 } 812 } 813
Other Screen Pages just display the final result
ChallengeQnABean.java loads the questions from the OIM and saves it for the user session page ChangePassword.jspx
1 package view.resources.backing; 2 3 import javax.faces.model.SelectItem; 4 5 import static view.resources.backing.PropertyLoader.admin; 6 import static view.resources.backing.PropertyLoader.password; 7 8 public class ChallengeQnABean { 9 public ChallengeQnABean() { 10 super(); 11 } 12 13 private SelectItem[] selectItems; 14 15 private String className = this.getClass().getSimpleName(); 16 17 private void enter(String method) { 18 System.out.println("Entering " + method + " of class " + className); 19 } 20 21 private void exit(String method) { 22 System.out.println("Exiting " + method + " of class " + className); 23 } 24 25 private String[] loadQnA() { 26 String method = Thread.currentThread().getStackTrace()[1] 27 .getMethodName(); 28 enter(method); 29 boolean flag = false; 30 String[] cNa = null; 31 try { 32 OIMOperator oim = new OIMOperator(admin, password); 33 cNa = oim.getChallengeQnA(); 34 oim.logout(); 35 } catch (Exception e) { 36 e.printStackTrace(); 37 System.out.println("e.toString() ->" + e.toString()); 38 System.out.println("e.getMessage() ->" + e.getMessage()); 39 } 40 exit(method); 41 return cNa; 42 } 43 44 public SelectItem[] getSelectItems() { 45 String[] cNa = loadQnA(); 46 if (selectItems == null) { 47 selectItems = new SelectItem[cNa.length]; 48 for (int i = 0; i < cNa.length; i++) { 49 selectItems[i] = new SelectItem(cNa[i], cNa[i], null, false); 50 } 51 } 52 53 return selectItems; 54 } 55 56 } 57
OIMOperator.java : it uses the OIM 11g api to perform all oim operations like reads global questions, update user, set QnA etc.
1 package view.resources.backing; 2 3 import java.util.ArrayList; 4 import java.util.Arrays; 5 6 import oracle.iam.platform.OIMClient; 7 8 import java.util.Hashtable; 9 import java.util.List; 10 11 import java.util.Map; 12 13 import javax.security.auth.login.LoginException; 14 15 import oracle.iam.identity.usermgmt.api.UserManager; 16 import oracle.iam.selfservice.self.selfmgmt.api.AuthenticatedSelfService; 17 import oracle.iam.identity.usermgmt.api.UserManager; 18 import oracle.iam.identity.usermgmt.vo.User; 19 import oracle.iam.identity.usermgmt.vo.UserManagerResult; 20 import oracle.iam.platform.OIMClient; 21 import oracle.iam.platform.Role; 22 import oracle.iam.selfservice.exception.AuthSelfServiceException; 23 24 import oracle.iam.selfservice.uself.uselfmgmt.api.UnauthenticatedSelfService; 25 26 import static view.resources.backing.PropertyLoader.oimURL; 27 28 public class OIMOperator { 29 30 private OIMClient client = null; 31 private String className = this.getClass().getSimpleName(); 32 private boolean error = false; 33 34 OIMOperator(String user, String password) { 35 setOIMClient(oimURL); 36 login(user, password); 37 } 38 39 private void enter(String method) { 40 System.out.println("Entering " + method + " of class " + className); 41 } 42 43 private void exit(String method) { 44 System.out.println("Exiting " + method + " of class " + className); 45 } 46 47 AuthenticatedSelfService getAuthenticatedSelfService() { 48 String method = Thread.currentThread().getStackTrace()[1] 49 .getMethodName(); 50 enter(method); 51 AuthenticatedSelfService service = null; 52 try { 53 service = client.getService(AuthenticatedSelfService.class); 54 } catch (Exception e) { 55 e.printStackTrace(); 56 System.out.println("e.toString() ->" + e.toString()); 57 System.out.println("e.getMessage() ->" + e.getMessage()); 58 setError(true); 59 } 60 exit(method); 61 return service; 62 } 63 64 UnauthenticatedSelfService getUnauthenticatedSelfService() { 65 String method = Thread.currentThread().getStackTrace()[1] 66 .getMethodName(); 67 enter(method); 68 UnauthenticatedSelfService service = null; 69 try { 70 service = client.getService(UnauthenticatedSelfService.class); 71 } catch (Exception e) { 72 73 e.printStackTrace(); 74 System.out.println("e.toString() ->" + e.toString()); 75 System.out.println("e.getMessage() ->" + e.getMessage()); 76 setError(true); 77 } 78 exit(method); 79 return service; 80 } 81 82 UserManager getUserManager() { 83 String method = Thread.currentThread().getStackTrace()[1] 84 .getMethodName(); 85 enter(method); 86 UserManager service = null; 87 try { 88 service = client.getService(UserManager.class); 89 } catch (Exception e) { 90 e.printStackTrace(); 91 System.out.println("e.toString() ->" + e.toString()); 92 System.out.println("e.getMessage() ->" + e.getMessage()); 93 setError(true); 94 } 95 exit(method); 96 return service; 97 } 98 99 public List<String> getChallengeAnswersAsList() { 100 return getChallengeQnAasList(); 101 } 102 103 private List<String> getSArrayToList(String[] s_arr) { 104 List<String> list = new ArrayList<String>(Arrays.asList(s_arr)); 105 return list; 106 } 107 108 String[] getChallengeQnA() { 109 110 String method = Thread.currentThread().getStackTrace()[1] 111 .getMethodName(); 112 enter(method); 113 String[] CnA = null; 114 try { 115 AuthenticatedSelfService service = getAuthenticatedSelfService(); 116 CnA = service.getSystemChallengeQuestions(); 117 } catch (Exception e) { 118 e.printStackTrace(); 119 System.out.println("e.toString() ->" + e.toString()); 120 System.out.println("e.getMessage() ->" + e.getMessage()); 121 setError(true); 122 } 123 exit(method); 124 return CnA; 125 } 126 127 private List<String> getChallengeQnAasList() { 128 List<String> CnAList = null; 129 String method = ""; 130 try { 131 method = Thread.currentThread().getStackTrace()[1].getMethodName(); 132 enter(method); 133 AuthenticatedSelfService service = getAuthenticatedSelfService(); 134 String[] CnA; 135 CnA = service.getSystemChallengeQuestions(); 136 CnAList = getSArrayToList(CnA); 137 138 } catch (Exception e) { 139 e.printStackTrace(); 140 System.out.println("e.toString() ->" + e.toString()); 141 System.out.println("e.getMessage() ->" + e.getMessage()); 142 setError(true); 143 } 144 exit(method); 145 return CnAList; 146 } 147 148 private void setOIMClient(String oimURL) { 149 String method = Thread.currentThread().getStackTrace()[1] 150 .getMethodName(); 151 enter(method); 152 try { 153 Hashtable env = new Hashtable(); 154 env.put(OIMClient.JAVA_NAMING_FACTORY_INITIAL, 155 OIMClient.WLS_CONTEXT_FACTORY); 156 env.put(OIMClient.JAVA_NAMING_PROVIDER_URL, oimURL); 157 client = new OIMClient(env); 158 } catch (Exception e) { 159 e.printStackTrace(); 160 System.out.println("e.toString() ->" + e.toString()); 161 System.out.println("e.getMessage() ->" + e.getMessage()); 162 setError(true); 163 } 164 exit(method); 165 166 } 167 168 private void login(String user, String password) { 169 String method = Thread.currentThread().getStackTrace()[1] 170 .getMethodName(); 171 enter(method); 172 try { 173 System.out.println("Before Login"); 174 client.login(user, password.toCharArray()); 175 System.out.println("After Login"); 176 } catch (Exception e) { 177 e.printStackTrace(); 178 System.out.println("e.toString() ->" + e.toString()); 179 System.out.println("e.getMessage() ->" + e.getMessage()); 180 setError(true); 181 } 182 exit(method); 183 } 184 185 void logout() { 186 String method = Thread.currentThread().getStackTrace()[1] 187 .getMethodName(); 188 enter(method); 189 try { 190 if (client != null) 191 client.logout(); 192 } catch (Exception e) { 193 e.printStackTrace(); 194 System.out.println("e.toString() ->" + e.toString()); 195 System.out.println("e.getMessage() ->" + e.getMessage()); 196 } 197 exit(method); 198 } 199 200 boolean resetPassword(String username, Map<String, Object> quesAnsMap, 201 String password) { 202 String method = Thread.currentThread().getStackTrace()[1] 203 .getMethodName(); 204 enter(method); 205 boolean flag = false; 206 try { 207 flag = getUnauthenticatedSelfService().resetPassword(username, 208 quesAnsMap, password.toCharArray()); 209 } catch (Exception e) { 210 e.printStackTrace(); 211 System.out.println("e.toString() ->" + e.toString()); 212 System.out.println("e.getMessage() ->" + e.getMessage()); 213 setError(true); 214 } 215 exit(method); 216 217 return flag; 218 219 } 220 221 boolean setChallengeQnAValues(Map<String, Object> quesAnsMap) { 222 String method = Thread.currentThread().getStackTrace()[1] 223 .getMethodName(); 224 enter(method); 225 boolean flag = false; 226 try { 227 getAuthenticatedSelfService().setChallengeValues(quesAnsMap); 228 flag = true; 229 } catch (Exception e) { 230 e.printStackTrace(); 231 System.out.println("e.toString() ->" + e.toString()); 232 System.out.println("e.getMessage() ->" + e.getMessage()); 233 setError(true); 234 } 235 exit(method); 236 237 return flag; 238 239 } 240 241 boolean changePassword(String oldPwd, String newPwd, String confirmPwd) { 242 String method = Thread.currentThread().getStackTrace()[1] 243 .getMethodName(); 244 enter(method); 245 boolean flag = false; 246 try { 247 getAuthenticatedSelfService().changePassword(oldPwd.toCharArray(), 248 newPwd.toCharArray(), confirmPwd.toCharArray()); 249 flag = true; 250 } catch (Exception e) { 251 e.printStackTrace(); 252 System.out.println("e.toString() ->" + e.toString()); 253 System.out.println("e.getMessage() ->" + e.getMessage()); 254 setError(true); 255 } 256 exit(method); 257 return flag; 258 } 259 260 boolean setChallengeValues(Map<String, Object> quesAnsMap) { 261 String method = Thread.currentThread().getStackTrace()[1] 262 .getMethodName(); 263 enter(method); 264 boolean flag = false; 265 try { 266 getAuthenticatedSelfService().setChallengeValues(quesAnsMap); 267 flag = true; 268 } catch (Exception e) { 269 e.printStackTrace(); 270 System.out.println("e.toString() ->" + e.toString()); 271 System.out.println("e.getMessage() ->" + e.getMessage()); 272 setError(true); 273 } 274 exit(method); 275 return flag; 276 } 277 278 public void setError(boolean error) { 279 this.error = error; 280 } 281 282 public boolean isError() { 283 return error; 284 } 285 } 286
PropertyLoader.java : reads the configuratiosn and UI labels and anything else that should not be hard coded
1 package view.resources.backing; 2 3 import java.util.ResourceBundle; 4 5 public class PropertyLoader { 6 static String admin = null; 7 static String password = null; 8 static String oimURL = null; 9 static String oimLogin = null; 10 static String GRACE_DAYS = null; 11 12 static { 13 try { 14 ResourceBundle rbe = ResourceBundle.getBundle("view.backing." 15 + getResourceBundleName()); 16 admin = rbe.getString("admin"); 17 password = rbe.getString("password"); 18 oimURL = rbe.getString("oimURL"); 19 oimLogin = rbe.getString("oimLogin"); 20 GRACE_DAYS = rbe.getString("GRACE_DAYS"); 21 System.out.println(" admin->" + admin); 22 System.out.println(" oimURL->" + oimURL); 23 System.out.println(" oimLogin->" + oimLogin); 24 System.out.println(" GRACE_DAYS->" + GRACE_DAYS); 25 26 } catch (Exception e) { 27 e.printStackTrace(); 28 System.out.println("e.getMessage ->" + e.getMessage()); 29 } 30 31 } 32 33 public static void main(String[] args) { 34 35 } 36 37 private static String getResourceBundleName() { 38 String wpf = ""; 39 try { 40 wpf = ResourceBundle.getBundle("view.backing.whichpropfile") 41 .getString("whichpropfile"); 42 System.out.println("wpf ->" + wpf); 43 } catch (Exception e) { 44 e.printStackTrace(); 45 System.out.println("e.getMessage ->" + e.getMessage()); 46 } 47 return wpf; 48 } 49 50 static void load() { 51 try { 52 ResourceBundle rbe = ResourceBundle.getBundle("view.backing." 53 + getResourceBundleName()); 54 admin = rbe.getString("admin"); 55 password = rbe.getString("password"); 56 oimURL = rbe.getString("oimURL"); 57 oimLogin = rbe.getString("oimLogin"); 58 59 System.out.println(" admin->" + admin); 60 System.out.println(" oimURL->" + oimURL); 61 System.out.println(" oimLogin->" + oimLogin); 62 63 } catch (Exception e) { 64 e.printStackTrace(); 65 System.out.println("e.getMessage ->" + e.getMessage()); 66 } 67 68 } 69 } 70
UpdateDb.java : it tracks the account claim process in its internal schema table like whether the account is already claimed or not and few more tables which can be used by external applications
1 package model; 2 3 import java.util.ResourceBundle; 4 5 import java.sql.Connection; 6 import java.sql.DatabaseMetaData; 7 import java.sql.Date; 8 import java.sql.DriverManager; 9 import java.sql.PreparedStatement; 10 import java.sql.ResultSet; 11 import java.sql.SQLException; 12 13 import javax.naming.InitialContext; 14 15 import javax.sql.DataSource; 16 17 public class UpdateDb { 18 private String className = this.getClass().getSimpleName(); 19 private static String usedatasource = null; 20 private static String datasource = null; 21 private static String username = null; 22 private static String dbpassword = null; 23 private static String table = null; 24 private static String colum = null; 25 private static String claimcolum = null; 26 // private Connection con = null; 27 private static String url = null; 28 private static String claimSetCheck = null; 29 private static String updateClaim = null; 30 private static String selectGobtPac; 31 private static String updateGobtPac; 32 33 static { 34 System.out.println("Entering static block of UpdateDB"); 35 String wpf = ResourceBundle.getBundle("view.backing.whichpropfile") 36 .getString("whichpropfile"); 37 System.out.println("wpf ->" + wpf); 38 ResourceBundle rbe = ResourceBundle.getBundle("view.backing." + wpf); 39 usedatasource = rbe.getString("usedatasource"); 40 System.out.println("usedatasource -> " + usedatasource); 41 if (usedatasource.equalsIgnoreCase("true")) { 42 datasource = rbe.getString("datasource"); 43 System.out.println(" datasource->" + datasource); 44 } else { 45 username = rbe.getString("username"); 46 System.out.println(" username->" + username); 47 dbpassword = rbe.getString("dbpassword"); 48 url = rbe.getString("url"); 49 System.out.println(" url->" + url); 50 } 51 table = rbe.getString("table"); 52 System.out.println(" table->" + table); 53 colum = rbe.getString("colum"); 54 System.out.println(" colum->" + colum); 55 claimcolum = rbe.getString("claimcolum"); 56 System.out.println(" claimcolum->" + claimcolum); 57 claimSetCheck = "select " + colum + ", " + claimcolum + " from " 58 + table + " where " + colum + " = ?"; 59 System.out.println(" claimSetCheck->" + claimSetCheck); 60 updateClaim = "update " + table + " set " + claimcolum + "= ? where " 61 + colum + " = ?"; 62 System.out.println(" updateClaim->" + updateClaim); 63 64 selectGobtPac = "select GOBTPAC_USER,GOBTPAC_PIN from GOBTPAC where GOBTPAC_USER = ?"; 65 System.out.println(" gobtPacSet->" + selectGobtPac); 66 updateGobtPac = "update GOBTPAC set GOBTPAC_PIN = ?,GOBTPAC_PIN_EXP_DATE = ? where GOBTPAC_USER = ?"; 67 System.out.println(" updateGobtPac->" + updateGobtPac); 68 69 } 70 71 private void enter(String method) { 72 System.out.println("Entering " + method + " of class " + className); 73 } 74 75 private void exit(String method) { 76 System.out.println("Exiting " + method + " of class " + className); 77 } 78 79 private Connection getConnection() { 80 String method = Thread.currentThread().getStackTrace()[1] 81 .getMethodName(); 82 enter(method); 83 Connection con = null; 84 try { 85 if (usedatasource.equalsIgnoreCase("true")) { 86 InitialContext ctx = null; 87 ctx = new InitialContext(); 88 DataSource ds = (DataSource) ctx.lookup(datasource); 89 con = (Connection) ds.getConnection(); 90 } else { 91 92 if ((con == null) || (con.isClosed())) { 93 Class.forName("oracle.jdbc.driver.OracleDriver"); 94 con = DriverManager 95 .getConnection(url, username, dbpassword); 96 } 97 } 98 System.out.println("Got the Connection"); 99 } catch (Exception e) { 100 e.printStackTrace(); 101 System.out.println("e.toString() ->" + e.toString()); 102 System.out.println("e.getMessage() ->" + e.getMessage()); 103 104 } 105 106 exit(method); 107 return con; 108 } 109 110 public String updateClaimTable(String userid, String mail) { 111 String method = Thread.currentThread().getStackTrace()[1] 112 .getMethodName(); 113 enter(method); 114 String response = "false"; 115 Connection con = null; 116 try { 117 boolean isGoremailUpdated = updateGoremalTable(userid, mail); 118 System.out.println("isGoremailUpdated -> " + isGoremailUpdated); 119 // if (isGoremailUpdated == false) 120 // return response; 121 con = getConnection(); 122 if (con != null) { 123 con.setAutoCommit(true); 124 PreparedStatement isClaimSet = null; 125 System.out.println("claimSetCheck -> " + claimSetCheck); 126 isClaimSet = con.prepareStatement(claimSetCheck); 127 System.out.println("isClaimSet ->" + isClaimSet); 128 isClaimSet.setString(1, userid); 129 ResultSet rs; 130 rs = isClaimSet.executeQuery(); 131 System.out.println("Query Executed ->"); 132 Date dt = null; 133 int rowCount = 0; 134 while (rs.next()) { 135 dt = rs.getDate(claimcolum); 136 System.out.println(" dt->" + dt); 137 rowCount = rowCount + 1; 138 } 139 System.out.println("Number of Rows=" + rowCount); 140 if (rowCount == 1) { 141 if (dt == null) { 142 java.util.Date utilDate = new java.util.Date(); 143 java.sql.Date sqlDate = new java.sql.Date( 144 utilDate.getTime()); 145 System.out.println("utilDate:" + utilDate); 146 System.out.println("sqlDate:" + sqlDate); 147 148 PreparedStatement updateClaimSet = null; 149 System.out.println("updateClaim -> " + updateClaim); 150 updateClaimSet = con.prepareStatement(updateClaim); 151 System.out.println(" Before updating date-> "); 152 updateClaimSet.setDate(1, sqlDate); 153 System.out.println(" Before updating userid-> "); 154 updateClaimSet.setString(2, userid); 155 System.out.println(" After updating both -> "); 156 int rs2; 157 rs2 = updateClaimSet.executeUpdate(); 158 System.out.println("rs2 ->" + rs2); 159 response = "CLAIMED"; 160 161 } else { 162 response = "CLAIMED_EARLIER"; 163 } 164 } else if (rowCount == 0) { 165 response = "NO_USER_FOUND"; 166 } else { 167 response = "MULTIPLE_USER_FOUND"; 168 } 169 } 170 171 } catch (Exception e) { 172 e.printStackTrace(); 173 System.out.println("e.toString() ->" + e.toString()); 174 System.out.println("e.getMessage() ->" + e.getMessage()); 175 176 } finally { 177 if (con != null) { 178 try { 179 con.close(); 180 } catch (Exception e) { 181 e.printStackTrace(); 182 System.out.println("e.toString() ->" + e.toString()); 183 System.out.println("e.getMessage() ->" + e.getMessage()); 184 185 } 186 } 187 } 188 System.out.println("response ->" + response); 189 exit(method); 190 return response; 191 } 192 193 public String updateGobtpacTable(String userid, String pin, 194 java.util.Date pin_exp) { 195 String method = Thread.currentThread().getStackTrace()[1] 196 .getMethodName(); 197 enter(method); 198 String response = "false"; 199 Connection con = null; 200 try { 201 con = getConnection(); 202 if (con != null) { 203 con.setAutoCommit(true); 204 PreparedStatement isClaimSet = null; 205 System.out.println("selectGobtPac -> " + selectGobtPac); 206 isClaimSet = con.prepareStatement(selectGobtPac); 207 System.out.println("isClaimSet ->" + isClaimSet); 208 isClaimSet.setString(1, userid); 209 ResultSet rs; 210 rs = isClaimSet.executeQuery(); 211 System.out.println("Query Executed ->"); 212 String dt = null; 213 int rowCount = 0; 214 while (rs.next()) { 215 dt = rs.getString("GOBTPAC_PIN"); 216 System.out.println(" dt->" + dt); 217 rowCount = rowCount + 1; 218 } 219 System.out.println("Number of Rows=" + rowCount); 220 if (rowCount == 1) { 221 if (dt == null) { 222 223 PreparedStatement updateClaimSet = null; 224 System.out 225 .println(" updateGobtPac -> " + updateGobtPac); 226 updateClaimSet = con.prepareStatement(updateGobtPac); 227 System.out.println(" Before updating pin-> "); 228 updateClaimSet.setString(1, pin); 229 System.out.println(" Before updating pin expiry -> "); 230 java.sql.Date sqlDate = new java.sql.Date( 231 pin_exp.getTime()); 232 System.out.println("utilDate:" + pin_exp); 233 System.out.println("sqlDate:" + sqlDate); 234 updateClaimSet.setDate(2, sqlDate); 235 updateClaimSet.setString(3, userid); 236 System.out.println(" After updating all -> "); 237 int rs2; 238 rs2 = updateClaimSet.executeUpdate(); 239 System.out.println("rs2 ->" + rs2); 240 response = "CLAIMED"; 241 242 } else { 243 response = "CLAIMED_EARLIER"; 244 } 245 } else if (rowCount == 0) { 246 response = "NO_USER_FOUND"; 247 } else { 248 response = "MULTIPLE_USER_FOUND"; 249 } 250 } 251 252 } catch (Exception e) { 253 e.printStackTrace(); 254 System.out.println("e.toString() ->" + e.toString()); 255 System.out.println("e.getMessage() ->" + e.getMessage()); 256 257 } finally { 258 if (con != null) { 259 try { 260 con.close(); 261 } catch (Exception e) { 262 e.printStackTrace(); 263 System.out.println("e.toString() ->" + e.toString()); 264 System.out.println("e.getMessage() ->" + e.getMessage()); 265 266 } 267 } 268 } 269 System.out.println("response ->" + response); 270 exit(method); 271 return response; 272 } 273 274 private boolean updateGoremalTable(String userid, String mail) { 275 String method = Thread.currentThread().getStackTrace()[1] 276 .getMethodName(); 277 enter(method); 278 boolean response = false; 279 Connection con = null; 280 try { 281 con = getConnection(); 282 if (con != null) { 283 con.setAutoCommit(true); 284 PreparedStatement updateGoremalState = null; 285 String updateSt = "UPDATE GOREMAL set GOREMAL_EMAIL_ADDRESS = ? WHERE GOREMAL_USER_ID = ?"; 286 System.out.println(" updateSt-> " + updateSt); 287 updateGoremalState = con.prepareStatement(updateSt); 288 System.out.println(" Before updating mail address-> "); 289 updateGoremalState.setString(1, mail); 290 System.out.println(" Before updating userid-> "); 291 updateGoremalState.setString(2, userid); 292 System.out.println(" After updating both -> "); 293 int rs2; 294 rs2 = updateGoremalState.executeUpdate(); 295 System.out.println("rs2 ->" + rs2); 296 response = true; 297 } 298 } catch (Exception e) { 299 e.printStackTrace(); 300 System.out.println("e.toString() ->" + e.toString()); 301 System.out.println("e.getMessage() ->" + e.getMessage()); 302 303 } finally { 304 if (con != null) { 305 try { 306 con.close(); 307 } catch (Exception e) { 308 e.printStackTrace(); 309 System.out.println("e.toString() ->" + e.toString()); 310 System.out.println("e.getMessage() ->" + e.getMessage()); 311 312 } 313 } 314 } 315 System.out.println("response ->" + response); 316 exit(method); 317 return response; 318 } 319 320 } 321
Properties Files
ViewControllerBundle.properties: Automtically used for UI labels in adf pages
#
ACCOUNT_INFORMATION=Account Information
#UID
UID=UID
#PIN
PIN=PIN
#Zip Code
ZIP_CODE=Zip Code
#Date of Birth
DATE_OF_BIRTH=Date of Birth
#Next
NEXT=Next
#Cancel
CANCEL=Cancel
#Account Claim Validation
ACCOUNT_CLAIM_VALIDATION=Account Claim Validation
myApp.properties: Application Specific properties file
admin=xelsysadm
password=password
oimURL=t3://host:14010/oim
oimLogin=http://host:14010/oim/faces/pages/Self.jspx
GRACE_DAYS=3
# DB Properties
#hostname=hostname
#DBservicename=servicename
#DBSIDname=sidname
#DBport=1521
dbuser=dbuser
dbpassword=dbpassword
table=table
colum=colum
claimcolum=claimcolum-date
url=jdbc:oracle:thin:@hostname:1521:sid
#DateSource
usedatasource=true
datasource=jdbc/iamdatasource