OIM UnAuthenticated SelfService Reset Password API


  1. package com.oimacademy.password;
  2. import java.sql.Connection;
  3. import java.sql.PreparedStatement;
  4. import java.sql.ResultSet;
  5. import java.util.HashMap;
  6. import java.util.Map;
  7. import oracle.iam.selfservice.uself.uselfmgmt.api.UnauthenticatedSelfService;
  8. import com.oimacademy.connection.DataSource;
  9. import com.oimacademy.connection.Platform;
  10. public class UnAuthenticatedSelfServiceResetPassword { 
  11.      private UnauthenticatedSelfService m_unAuthselfservice =  Platform.getService(UnauthenticatedSelfService.class);
  12.      static private Map<String, String> cachedUserKeys = new HashMap<String, String>();     
  13.      public static void main(String[] args) {
  14.   // TODO Auto-generated method stub
  15.       try {
  16.     new UnAuthenticatedSelfServiceResetPassword().setResetPassword("5", "TUSER0");
  17.    } catch (Exception e) {
  18.     // TODO Auto-generated catch block
  19.     e.printStackTrace();
  20.    }
  21.  } 
  22.   private  void setResetPassword(String usrKey, String loggedInUser) throws Exception {
  23.          String password = "Welcome1";
  24.          System.out.println("password : " + password);
  25.          Connection con = DataSource.getConnection();
  26.          String query = "SELECT USR_LOGIN," + " USR_PASSWORD FROM USR WHERE USR_KEY=?";
  27.          System.out.println(query);
  28.          PreparedStatement preparedStatement = con.prepareStatement(query);
  29.          preparedStatement.setLong(1, Long.parseLong(usrKey));
  30.          ResultSet resultSet = preparedStatement.executeQuery();
  31.          resultSet.next();
  32.          String oldPass = resultSet.getString("USR_PASSWORD");           
  33.          System.out.println("-----------oldPass oldPass--------------------- " + oldPass);
  34.         // removeChallengeQuestiones(usrKey);
  35.          Map<String, Object> quesAnsMap = setChallengeQuestiones();
  36.          m_unAuthselfservice = Platform.getService(UnauthenticatedSelfService.class);
  37.          m_unAuthselfservice.resetPassword(loggedInUser, quesAnsMap, password.toCharArray());
  38.          resultSet = preparedStatement.executeQuery();
  39.          resultSet.next();
  40.          String newPass = resultSet.getString("USR_PASSWORD");   
  41.          System.out.println("-------------newPass newPass------------------- " + newPass);
  42.          System.out.println("Change password successful!!!");
  43.          DataSource.closeConnection();
  44.      }    
  45.   private void removeChallengeQuestiones(String usrKey) throws Exception {
  46.    System.out.println("Removing Challenge Questions ....");
  47.          Connection con = DataSource.getConnection();
  48.          String query = "DELETE FROM PCQ WHERE USR_KEY=?";
  49.          System.out.println(query);
  50.          PreparedStatement preparedStatement = con.prepareStatement(query);
  51.          preparedStatement.setLong(1, Long.parseLong(usrKey));
  52.          preparedStatement.executeUpdate();        
  53.          System.out.println("Removed Challenge Questions ....");
  54.      }  
  55.      private  Map<String, Object> setChallengeQuestiones() throws Exception {
  56.        System.out.println("Setting  Challenge Questions ....");
  57.          Map<String, Object> mapQnA = new HashMap<String, Object>();   
  58.    mapQnA.put("What is your mother's maiden name?", "1");
  59.    //mapQnA.put("What is your favorite color?", "5");
  60.    mapQnA.put("What is the city of your birth?", "3");
  61.    mapQnA.put("What is the name of your pet?", "2");
  62.          return mapQnA;
  63.      }
  64. }


No comments:

Post a Comment