0

I am creating a event handler to modify user password using OIM UserManager API. But now I need to consider password policy and then generate new password that is compatible with the password policy defined in OIM.

Can you please point to some APIs and Methods which can help here?

Chaitanya K
  • 1,827
  • 4
  • 32
  • 67

3 Answers3

1
import oracle.idm.common.ipf.api.password.RandomPasswordGenerator;
import oracle.idm.common.ipf.api.password.RandomPasswordGeneratorImpl;

The classes above actually gives handle on the randomly generated password that I was looking for. The code below shows the implementation for the same.

PasswordPolicyInfo passwordPolicyInfo = ((PasswordMgmtService)Platform.getService(PasswordMgmtService.class)).getApplicablePasswordPolicy(entityId, Boolean.valueOf(false));

  RandomPasswordGenerator randomPasswordGenerator = new RandomPasswordGeneratorImpl();

  OimPasswordPolicy policy = new OimPasswordPolicy(Utils.getIpfPasswordPolicyInfoVO(passwordPolicyInfo));
  policy.setId(passwordPolicyInfo.getId());
  policy.setName(passwordPolicyInfo.getName());

  char[] generatedPassword = randomPasswordGenerator.generatePassword(policy, null);
Chaitanya K
  • 1,827
  • 4
  • 32
  • 67
1

Alternatively by using below OIM API's,you can generate password and also validate it against any policy in OIM:

import oracle.iam.passwordmgmt.api.PasswordMgmtService;
import oracle.iam.passwordmgmt.domain.generator.RandomPasswordGeneratorImpl;

Here is the snippet:

RandomPasswordGeneratorImpl randomPasswordGenerator = new RandomPasswordGeneratorImpl();
UserRepository userRepository = new DBUserRepository();
UserInfo usrInfo = userRepository.getUserAndManagerInfo(usrLogin);
String generatedPassword = new String(randomPasswordGenerator.generatePassword(Utils.getUser(usrInfo)));
PasswordMgmtService passMgmt = Platform.getService(PasswordMgmtService.class);
ValidationResult result = passMgmt.validatePasswordAgainstPolicy(generatedPassword.toCharArray(), Utils.getUser(usrInfo), Locale.getDefault());
ps2090
  • 223
  • 2
  • 15
0

You can use PasswordMgmtService api provided by OIM. You can use below method in you password generation logic in your event handler code.

PasswordPolicyDescription getApplicablePasswordPolicyDescription(java.lang.String userID) 

In the PasswordPolicyDescription object you have all properties which were configured while creating Password Policy.

Kunal Varpe
  • 419
  • 1
  • 5
  • 28
  • 1
    It is not completely resolving the problem, as I need to get the randomly generated password and not the rules associated with password policy. With these rules I can build my logic to generate the password but the default password handler does the same, So I think there will be some API which would be allowing it to do so. So still looking for it – Chaitanya K Sep 19 '16 at 05:10