OIM API for Authenticated SelfService Reset Password


  1. package com.oimacademy.password;
  2. import java.util.HashMap;
  3. import oracle.iam.identity.usermgmt.api.UserManagerConstants;
  4. import oracle.iam.platform.context.ContextManager;
  5. import oracle.iam.selfservice.self.selfmgmt.api.AuthenticatedSelfService;
  6. import com.oimacademy.connection.Platform;
  7. public class AuthenticatedSelfServiceResetPassword {  
  8.   private AuthenticatedSelfService m_authselfservice = Platform.getService(AuthenticatedSelfService.class);
  9.  public static void main(String[] args) {
  10.   try {
  11.    new AuthenticatedSelfServiceResetPassword().changePassword();
  12.   } catch (Exception e) {
  13.    // TODO Auto-generated catch block
  14.    e.printStackTrace();
  15.   }
  16.  }
  17. public void changePassword() throws Exception { 
  18.         String oldpwd ="Welcome1";
  19.         String newpwd = "Welcome2";
  20.         String confirmpwd = "Welcome2";
  21.   
  22. /*        UserManager userManager = platform.getService(UserManager.class);
  23.         HashMap<String, Object> createAttrsMap = new HashMap<String, Object>();
  24.        // createAttrsMap = utility.getAttributesInMap(m_authUserProps, "CREATE.createAttributes");
  25.         createAttrsMap.put("User Login", "TUSER10");
  26.         createAttrsMap.put("First Name", "TEST10");
  27.         createAttrsMap.put("Last Name", "USER10");
  28.         createAttrsMap.put("act_key", "1");
  29.         createAttrsMap.put("usr_password", "Welcome1");
  30.         createAttrsMap.put("Xellerate Type", "End-User");
  31.         createAttrsMap.put("Role","Full-Time");
  32.         long actkey = Long.parseLong(createAttrsMap.get("act_key").toString());     
  33.         createAttrsMap.put("act_key", actkey);
  34.         createAttrsMap.put(UserManagerConstants.AttributeName.PASSWORD.getId(), oldpwd.toCharArray());
  35.         createAttrsMap.put("Start Date", new java.util.Date());  
  36.         createAttrsMap.put("Email", "TEST.USER10@oracle.com");
  37.         UserManagerResult result = userManager.create(new User(null,createAttrsMap));
  38.         System.out.println("ENTITYID = " + result.getEntityId());        
  39.         String usrKey = result.getEntityId();*/
  40.        // setUserInContext("TUSER2", "6");
  41.         System.out.println("###################"+ContextManager.getOIMUser());       
  42.         try {           
  43.             //Attempt to change password 
  44.             m_authselfservice.changePassword(oldpwd.toCharArray(),newpwd.toCharArray(),confirmpwd.toCharArray());
  45.             //m_authselfservice.changePassword("10981", "Pass_12345".toCharArray(),false);  
  46.             ContextManager.clearContext();
  47.             System.out.println("###### PASSWORD UPDATED #############");             
  48.         } catch (Exception e) {
  49.             e.printStackTrace();            
  50.          } finally {
  51.            
  52.              ContextManager.clearContext();
  53.             }
  54.     }
  55.   public void setUserInContext(String userName, String userKey){
  56.       if(ContextManager.getContext() != null) {
  57.       ContextManager.popContext();
  58.     }
  59.     ContextManager.pushContext(null, null, null);
  60.     HashMap<String,String> map = new HashMap<String,String>();
  61.     map.put(UserManagerConstants.AttributeName.USER_KEY.getId(), userKey);
  62.     ContextManager.setOIMUser(userName);
  63.     ContextManager.setUserDetails(map);    
  64.   }
  65. }

No comments:

Post a Comment