Pages

Monday, December 17, 2012

UserManager : Create User Code

Lets start into more mainstream stuff.

We will look at the UserManager class which is used for the User operations. This is similar in operation with the tcUserOperationsIntf class, which is still present in 11G.

1) Creating a new Class for UserOperations



2) Writing code

package com.oim;
import oracle.iam.identity.exception.UserAlreadyExistsException;
import oracle.iam.identity.exception.UserCreateException;
import oracle.iam.identity.exception.ValidationFailedException;
import oracle.iam.identity.usermgmt.api.UserManager;
import oracle.iam.identity.usermgmt.vo.User;
import oracle.iam.platform.OIMClient;
import oracle.iam.platform.authz.exception.AccessDeniedException;

public class UserOperations {
public void createUser(OIMClient oimclient){
UserManager usrMgr = oimclient.getService(UserManager.class);
/*
* Mandatory fields are LastName, act_key, Role, Xellerate Type
*/
User user = new User(null); //Pass null while creating
user.setAttribute("First Name", "APIUser");
user.setAttribute("Last Name", "APIUser");
user.setAttribute("Email", "APIUser@mail.com");
user.setAttribute("act_key",1L); // Replace 1L with the organization key long value
user.setAttribute("Role","Full-Time");
user.setAttribute("Xellerate Type","End-User");
try {
usrMgr.create(user);
} catch (ValidationFailedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UserAlreadyExistsException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UserCreateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (AccessDeniedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void main(String[] args) {
OIMConnect conn = new OIMConnect();
conn.connect();
UserOperations userOps = new UserOperations();
userOps.createUser(conn.client);
conn.disconnect();
}
}
 3) Output

User is created in OIM.



4) Possible errors


  • oracle.iam.identity.exception.ValidationFailedException: IAM-3050028:The mandatory attributes act_key were not provided.:act_key
    • act_key has net been set as attribute in the User object
  • oracle.iam.identity.exception.ValidationFailedException: IAM-3050028:The mandatory attributes [Role, Last Name, Xellerate Type] were not provided.:[Role, Last Name, Xellerate Type]
    • Mandatory attributes have not be given values


4 comments:

  1. Thank you.. This code helped me a lot :-)

    ReplyDelete
  2. Thanks! This code snippet helped me in finding Xellerate type is also mandatory.

    ReplyDelete
  3. Hi,

    I have a question. Can we use OIM Client APIs directly on OIM production environment. I have a use case where we need to create users in OIM production system. Can I use OIM APIs. Any issue or impact i.e. repository corruption or do we need to restart OIM server when we use OIM APIs for user creation?

    Thanks
    Shant

    ReplyDelete
  4. Hi Shant,

    There is no technical impact in creating users in OIM Production using APIs.

    But its better to check with client about this approach, if they have any specific audit objectives that might not be met by using APIs.

    Other approach that you can use, is by create a GTC with flat file, which would load the users into OIM with reconciliation events.

    Thanks,
    Aravind

    ReplyDelete