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
User is created in OIM.
4) Possible errors
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
3) Outputpackage 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 creatinguser.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 valueuser.setAttribute("Role","Full-Time");user.setAttribute("Xellerate Type","End-User");try {usrMgr.create(user);} catch (ValidationFailedException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (UserAlreadyExistsException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (UserCreateException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (AccessDeniedException e) {// TODO Auto-generated catch blocke.printStackTrace();}}public static void main(String[] args) {OIMConnect conn = new OIMConnect();conn.connect();UserOperations userOps = new UserOperations();userOps.createUser(conn.client);conn.disconnect();}}
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
Thank you.. This code helped me a lot :-)
ReplyDeleteThanks! This code snippet helped me in finding Xellerate type is also mandatory.
ReplyDeleteHi,
ReplyDeleteI 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
Hi Shant,
ReplyDeleteThere 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