//Create user in OIM
public void createUser(){
String userLogin = "A12345";
String fName = "Anand";
String lName = "Badal";
long actKey = 1;
String password = "Test123";
String empType = "EMP";
try{
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
//create user attributes map
HashMap<String, Object> usrAttributes = new HashMap<String, Object>();
usrAttributes.put("User Login", userLogin);
usrAttributes.put("First Name", fName);
usrAttributes.put("Last Name", lName);
usrAttributes.put("act_key", actKey);
usrAttributes.put("usr_password", password);
usrAttributes.put("Role", empType);
User user = new User(userLogin, usrAttributes);
userManager.create(user);
System.out.println("User created Successfully!!!");
}catch(Exception e) {
System.out.println("Error occured while creating user - " + e);
}
}
//Search user in OIM
public void searchUser(String userLogin){
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
HashSet<String> retAttrs = new HashSet<String>();
User user = userManager.getDetails(userLogin, retAttrs, true);
System.out.println("Display Name :: "+ user.getDisplayName());
System.out.println("Email :: "+ user.getEmail());
}catch(Exception e) {
System.out.println("Error occured while searching user - " + e);
}
}
//Disable user in OIM
public void disableUser(String userLogin) {
try{
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.disable(userLogin, true);
System.out.print("Disabled User Successfully!!!");
}catch(Exception e){
System.out.println("Error occured while disabling user - " + e);
}
}
//Enable user in OIM
public void enableUser(String userLogin) {
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.enable(userLogin, true);
System.out.print("Enabled User Successfully!!!");
}catch(Exception e){
System.out.println("Error occured while enabling user - " + e);
}
}
//Reset user password
public void resetPassword(String userLogin) {
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.resetPassword(userLogin, true, true);
System.out.println("Password Reset Successfully!!!");
}catch(Exception e){
System.out.println("Error occured while reset user password - " + e);
}
}
//Change user password
public void changePassword(String userId, char[] password, boolean isUserLogin, boolean sendNotification){
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.changePassword(userId, password, isUserLogin, sendNotification);
System.out.println("Password changed Successfully!!!");
}catch(Exception e){
System.out.println("Error occured while change user password - " + e);
}
}
//Lock User
public void lockUser(String userId) {
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.lock(userId, true);
System.out.println("Lock user Successfully!!!");
}catch(Exception e){
System.out.println("Error occured while locking user - " + e);
}
}
//Unlock User
public void unLockUser(String userId) {
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.unlock(userId, true);
System.out.println("User unlocked!!!");
} catch(Exception e) {
System.out.println("Error occured while unlocking user - " + e);
}
}
//Delete user in OIM
public void deleteUser(String userLogin){
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.delete(userLogin, true);
System.out.println("User deleted successfully!!!");
} catch (Exception e) {
System.out.println("Error occured while deleting user - " + e);
}
}
//Update the user attribute
public void modifyUserAttribute(String userKey, String attributeName, String attributeValue){
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
User usr = new User(userKey);
usr.setAttribute(attributeName, attributeValue);
userManager.modify(usr);
System.out.println("User attribute modified successfully!!!");
} catch(Exception e) {
System.out.println("Error occured while modifing user attribute - " + e);
}
}
Happy Learning!!!
public void createUser(){
String userLogin = "A12345";
String fName = "Anand";
String lName = "Badal";
long actKey = 1;
String password = "Test123";
String empType = "EMP";
try{
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
//create user attributes map
HashMap<String, Object> usrAttributes = new HashMap<String, Object>();
usrAttributes.put("User Login", userLogin);
usrAttributes.put("First Name", fName);
usrAttributes.put("Last Name", lName);
usrAttributes.put("act_key", actKey);
usrAttributes.put("usr_password", password);
usrAttributes.put("Role", empType);
User user = new User(userLogin, usrAttributes);
userManager.create(user);
System.out.println("User created Successfully!!!");
}catch(Exception e) {
System.out.println("Error occured while creating user - " + e);
}
}
//Search user in OIM
public void searchUser(String userLogin){
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
HashSet<String> retAttrs = new HashSet<String>();
User user = userManager.getDetails(userLogin, retAttrs, true);
System.out.println("Display Name :: "+ user.getDisplayName());
System.out.println("Email :: "+ user.getEmail());
}catch(Exception e) {
System.out.println("Error occured while searching user - " + e);
}
}
//Disable user in OIM
public void disableUser(String userLogin) {
try{
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.disable(userLogin, true);
System.out.print("Disabled User Successfully!!!");
}catch(Exception e){
System.out.println("Error occured while disabling user - " + e);
}
}
//Enable user in OIM
public void enableUser(String userLogin) {
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.enable(userLogin, true);
System.out.print("Enabled User Successfully!!!");
}catch(Exception e){
System.out.println("Error occured while enabling user - " + e);
}
}
//Reset user password
public void resetPassword(String userLogin) {
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.resetPassword(userLogin, true, true);
System.out.println("Password Reset Successfully!!!");
}catch(Exception e){
System.out.println("Error occured while reset user password - " + e);
}
}
//Change user password
public void changePassword(String userId, char[] password, boolean isUserLogin, boolean sendNotification){
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.changePassword(userId, password, isUserLogin, sendNotification);
System.out.println("Password changed Successfully!!!");
}catch(Exception e){
System.out.println("Error occured while change user password - " + e);
}
}
//Lock User
public void lockUser(String userId) {
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.lock(userId, true);
System.out.println("Lock user Successfully!!!");
}catch(Exception e){
System.out.println("Error occured while locking user - " + e);
}
}
//Unlock User
public void unLockUser(String userId) {
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.unlock(userId, true);
System.out.println("User unlocked!!!");
} catch(Exception e) {
System.out.println("Error occured while unlocking user - " + e);
}
}
//Delete user in OIM
public void deleteUser(String userLogin){
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
userManager.delete(userLogin, true);
System.out.println("User deleted successfully!!!");
} catch (Exception e) {
System.out.println("Error occured while deleting user - " + e);
}
}
//Update the user attribute
public void modifyUserAttribute(String userKey, String attributeName, String attributeValue){
try {
//get user manager service
UserManager userManager = Platform.getService(UserManager.class);
User usr = new User(userKey);
usr.setAttribute(attributeName, attributeValue);
userManager.modify(usr);
System.out.println("User attribute modified successfully!!!");
} catch(Exception e) {
System.out.println("Error occured while modifing user attribute - " + e);
}
}
Happy Learning!!!
resetPassword() doesn't work for multiple users. It is working only for first/single user.
ReplyDeleteUse a loop for multiple IDs.
Delete