Create Password policy,organization to new User and Reset Password and verify update value in target OID/OUD/OVD

1. Create Password Policy
2. Create Organization
3. Attach Password policy to organization
4. Create user under organization
5. Update Password Policy
6. Reset Password for user
7. verify update value in target for changed value.


  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
package com.massiveGaze.ldap;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Set;

import javax.naming.NamingEnumeration;
import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.SearchControls;
import javax.naming.directory.SearchResult;

import com.massiveGaze.connection.Platform;
import com.massiveGaze.ldap.LDAPConnection;

import oracle.iam.identity.orgmgmt.api.OrganizationManager;
import oracle.iam.identity.orgmgmt.api.OrganizationManagerConstants;
import oracle.iam.identity.orgmgmt.vo.Organization;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.identity.usermgmt.vo.UserManagerResult;
import oracle.iam.identity.utils.Constants;
import oracle.iam.passwordmgmt.api.PasswordMgmtService;
import oracle.iam.passwordmgmt.vo.PasswordPolicyInfo;



public class TestLDAP {
 static PasswordMgmtService passwordmgmtService=Platform.getService(PasswordMgmtService.class);
 static OrganizationManager m_orgManagerService =Platform.getService(OrganizationManager.class);
 static UserManager usrMgmnt = Platform.getService(UserManager.class);
 static DirContext ctx=null;
 public static void main(String[] args) {
  
  try {
   new TestLDAP().pwdNeverExpireForPwdPolicyAsExpireDaysAfterIsNull();
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 public void pwdNeverExpireForPwdPolicyAsExpireDaysAfterIsNull() throws Exception {
  //CreatePasswordPolicy
  int i=5;
  ctx = (DirContext) LDAPConnection.getLDAPConnection();
  String policyName = "PasswordPolicy9"+i ; 
        PasswordPolicyInfo passPolicyInfo = new PasswordPolicyInfo();
        passPolicyInfo.setName(policyName);
        passPolicyInfo.setShortDesc(policyName + " description");
        passPolicyInfo.setPasswordExpiresAfterInDays(90);
        passPolicyInfo.setPriority(10000);            
        PasswordPolicyInfo searchPassPolicyInfo = new PasswordPolicyInfo();
        passPolicyInfo = passwordmgmtService.create(passPolicyInfo);        
        searchPassPolicyInfo = passwordmgmtService.getDetails(passPolicyInfo.getName());  
        System.out.println("Password Policy Created with id "+passPolicyInfo.getId());
       
        System.out.println(" Search Password Policy Created with id "+searchPassPolicyInfo.getId());
      
        //Create Organization
  Organization org = new Organization();
  org.setAttribute("Organization Name", "myorg"+i);
  org.setAttribute("Organization Customer Type", "Department");
  org.setAttribute("Organization Status", "Active");  
  String orgKey = m_orgManagerService.create(org); 
  System.out.println("Organization Created with ID "+orgKey);
        //Update Organization With PasswordPolicy Key
     HashMap<String, Object> updateAttributes = new HashMap<String, Object>();
     updateAttributes.put(OrganizationManagerConstants.AttributeName.ORG_PASSWORD_POLICY_KEY.getId(),passPolicyInfo.getId());
     orgKey= m_orgManagerService.modify(new Organization(orgKey,updateAttributes)); 
     System.out.println(" Modified Organization Adding Password Policy for Org ID "+orgKey);
        //CreateUser with Above Created Organization
     HashMap<String, Object> createAttributes = new HashMap<String, Object>();
  String userId =""+i;
     createAttributes.put(Constants.USERID, "TUSER" + userId);
  createAttributes.put(Constants.FIRSTNAME, "TEST" + userId);
  createAttributes.put(Constants.LASTNAME, "USER" + userId);
  createAttributes.put(Constants.ORGKEY, Long.parseLong(orgKey));
  createAttributes.put(Constants.PASSWORD, "Welcome1");
  createAttributes.put(Constants.EMAIL, "TUSER" + userId+ "@oracle.com");
  createAttributes.put(Constants.EMPTYPE, "Full-Time");
  createAttributes.put(Constants.USERTYPE,"End-User Administrator");    
  UserManagerResult result = usrMgmnt.create(new User(null,createAttributes));
     //Update setPasswordExpiresAfterInDays to Null for Password Never Expire
  System.out.println(" User Created with ID "+   result.getEntityId());
  PasswordPolicyInfo passPolicyObjAsNull = new PasswordPolicyInfo();
  passPolicyObjAsNull.setPasswordExpiresAfterInDays(null);
  passPolicyObjAsNull.setName("PasswordPolicy9"+i);
  passwordmgmtService.update(passPolicyObjAsNull);
  System.out.println(" Updated Password Policy to Null  ");
   //Change Password to Update USR_PWD_EXPIRE_DATE Column  
  usrMgmnt.changePassword(result.getEntityId(),"Pass_12345".toCharArray() , false);
  System.out.println(" Chnaged User Password for User +  "+result.getEntityId());
  //get USR_PWD_EXPIRE_DATE value
  Set<String> searchAttrs = new HashSet<String>();  
  searchAttrs.add("First Name");
  searchAttrs.add("Last Name");  
  searchAttrs.add("usr_pwd_expire_date");
  User userLookup = usrMgmnt.getDetails(result.getEntityId(), searchAttrs, false);
  String usr_pwd_expire_date=(String)userLookup.getAttributes().get("usr_pwd_expire_date");
  System.out.println(" usr_pwd_expire_date  From DB ->  "+usr_pwd_expire_date);
  //Get LDAP Attributes for the created User.
  String SearchCtrlString = "(&(objectclass=inetOrgPerson)(uid="+"TUSER" + userId + "))";
  SearchControls controls = new SearchControls();
  controls.setSearchScope(SearchControls.SUBTREE_SCOPE);
  NamingEnumeration results = ctx.search(LDAPConnection.getUserContainer(), SearchCtrlString, controls);
  String obPasswordExpiryDate=null;
  while (results.hasMore()) {
   SearchResult searchResult = (SearchResult) results.next();
   Attributes attributes = searchResult.getAttributes();
   Attribute attrObPWDExpiry = attributes.get("obpasswordexpirydate");
   if(attrObPWDExpiry==null){
    System.out.println(" attrObPWDExpiry is NUll   ");
     attrObPWDExpiry=attributes.get("orclpwdexpirationdate");
   }
   if(attrObPWDExpiry!=null)
            obPasswordExpiryDate = (String) attrObPWDExpiry.get();                 
  
   System.out.println(" obPasswordExpiryDate is    "+obPasswordExpiryDate);
   System.out.println(" usr_pwd_expire_date is "+usr_pwd_expire_date);
  }
  /*usrMgmnt.delete(result.getEntityId(), false);
     m_orgManagerService.delete(orgKey, false);
        passwordmgmtService.delete(policyName);*/
 }
}

No comments:

Post a Comment

About OIM

Oracle Identity Management enables organizations to effectively manage the end - to - end life - cycle of user ide...

Popular Posts