- package com.oimacademy.users;
- import java.util.Calendar;
- import java.util.HashMap;
- import java.util.Map;
- import oracle.iam.identity.usermgmt.api.UserManagerConstants.AttributeName;
- import oracle.iam.platform.context.ContextManager;
- import oracle.iam.selfservice.uself.uselfmgmt.api.UnauthenticatedSelfService;
- import com.oimacademy.connection.Platform;
- public class CreateSelfRegistartionRequest {
- public static void main(String[] args) {
- CreateSelfRegistartionRequest selfRequest = new CreateSelfRegistartionRequest();
- System.out.println("Calling registerUser Method..!");
- selfRequest.registerUser();
- System.out.println("End Of registerUser Method..!");
- }
- public String registerUser() {
- System.out.println("Inside registerUser Method..!");
- System.out.println("Connection Established Without Credentials ..!");
- String requestId = null;
- if (ContextManager.getOIMUser() != null &&
- !ContextManager.getOIMUser().toString().equalsIgnoreCase("anonymous")) {
- System.out.println ("Before pop context testSubmitRegistrationPasswordAutoGeneratedRequest loggedInUser : " + ContextManager.getOIMUser());
- ContextManager.popContext();
- ContextManager.clearContext();
- }
- UnauthenticatedSelfService unauth = Platform
- .getService(UnauthenticatedSelfService.class);
- Map<String, String> mapAttrRef = new HashMap<String, String>();
- mapAttrRef.put("Last Name", "Last Name");
- mapAttrRef.put("First Name", "First Name");
- mapAttrRef.put("Email", "Email");
- mapAttrRef.put("User Login", "User Login");
- mapAttrRef.put("Password", "Password");
- mapAttrRef.put("act_key", "Organization");
- mapAttrRef.put("Start Date", "Start Date");
- Calendar cal = Calendar.getInstance();
- cal.add(Calendar.MONTH, 1);
- Map<String, Object> mapRequest = new HashMap<String, Object>();
- mapRequest.put("act_key", new Long("1"));
- mapRequest.put("Last Name", "USER");
- mapRequest.put("First Name", "TEST");
- mapRequest.put("Email", "TEST.USER@acme.com");
- mapRequest.put("User Login", "TUSER");
- mapRequest.put("Password", "Welcome1");
- mapRequest.put("Start Date", cal.getTime());
- Map<String, Object> mapQnA = new HashMap<String, Object>();
- mapQnA.put("What is your favorite color?", "1");
- mapQnA.put("What is your mother's maiden name?", "2");
- mapQnA.put("What is the city of your birth?", "3");
- mapRequest=addSuffixToAttribute(mapRequest);
- try {
- requestId = unauth.submitRegistrationRequest(mapRequest, mapQnA,
- "Self-Register User", mapAttrRef);
- System.out.println("requestId ->" + requestId);
- } catch (Exception e) {
- e.printStackTrace();
- }
- return requestId;
- }
- public static Map<String, Object> addSuffixToAttribute(Map<String, Object> attrMap) {
- StringBuffer strBuf = new StringBuffer();
- int suffix = getRandomNumber();
- if (attrMap.get(AttributeName.USER_LOGIN.getId()) != null) {
- String login = attrMap.get(AttributeName.USER_LOGIN.getId())
- .toString();
- System.out.println("Before User Login :" + login);
- strBuf.append(login);
- strBuf.append(suffix);
- attrMap.put("User Login", strBuf.toString());
- System.out.println("After User Login :" + strBuf.toString());
- strBuf.setLength(0);
- }
- if (attrMap.get(AttributeName.FIRSTNAME.getId()) != null) {
- String firstName = attrMap.get(AttributeName.FIRSTNAME.getId())
- .toString();
- System.out.println("Before firstName :" + firstName);
- strBuf.append(firstName);
- strBuf.append(suffix);
- attrMap.put(AttributeName.FIRSTNAME.getId(), strBuf.toString());
- System.out.println("After firstName :" + strBuf.toString());
- strBuf.setLength(0);
- }
- if (attrMap.get(AttributeName.LASTNAME.getId()) != null) {
- String lastName = attrMap.get(AttributeName.LASTNAME.getId())
- .toString();
- System.out.println("Before Last Name :" + lastName);
- strBuf.append(lastName);
- strBuf.append(suffix);
- attrMap.put(AttributeName.LASTNAME.getId(), strBuf.toString());
- System.out.println("After Last Name :" + strBuf.toString());
- strBuf.setLength(0);
- }
- if (attrMap.get(AttributeName.EMAIL.getId()) != null) {
- String email = attrMap.get(AttributeName.EMAIL.getId()).toString();
- System.out.println(" EMAIL Before Modify :" + email);
- strBuf.append(email.replace(".com", suffix + ".com"));
- attrMap.put(AttributeName.EMAIL.getId(), strBuf.toString());
- System.out.println("EMAIL After Modify:" + strBuf.toString());
- strBuf.setLength(0);
- }
- return attrMap;
- }
- public static int getRandomNumber() {
- java.util.Random r = new java.util.Random(Calendar.getInstance()
- .getTimeInMillis());
- int randint = Math.abs(r.nextInt()) % 1000;
- return randint;
- }
- }
Oracle Identity Manager(OIM) is the Provisioning Solution from oracle. This page contains an index with references to all OIM related posts in the oracle identity manager Academy blog. The posts included herein are intended to provide oracle identity management customers and developers with technical information about best practices for implementing OIM based solutions.
OIM API to Create SelfRegistartion Request
Subscribe to:
Post Comments (Atom)
-
Connection Related API's : OIM DB Connection/ Data Source connection OIMClient API / OIMConnection API OIM Platform API to getSer...
-
Error : Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory at org.springframewor...
-
In this post, we set the middle name as “MiddleName” if user does not provide middle name during user create operation. Below are high...
No comments:
Post a Comment