Managing Users in Web Logic Server Programatically

This Post describes about how to manage the users in weblogic server programatically.

A sample WebCenter Portal Application is created in that a page has been created for managing the users (creating) and a java class has been created which basically performs the required operations that we do from front end.

Steps to Create the Users Progrmatically:

1) Create the WebCenter Portal Framework Application


2) Create a java class which basically contains all the code to manage the users in weblogic server


Code for the customCreateUser class:

package portalbeans;

import java.util.logging.Level;

import javax.faces.event.ActionEvent;



import oracle.adf.share.logging.ADFLogger;

public class customCreateUser {
String firstname;
String lastname;
String mailId;
String loginName;
String password;
String phNumber;
String address;
// Initialize ADF Logger
private static ADFLogger adfLogger =

private static String CLASS_NAME = "customCreateUser";

* Creates user with the given attributes.
* @param firstName
* @param lastName
* @param mailId
* @param loginName
* @param password

public void runMehod(ActionEvent actionEvent) {
//createUser("Raviteja", "Yellina", "",
// "ravi", "welcome123", "123708459", "bangalore");

createUser(firstname,lastname, mailId,loginName, password, phNumber, address);
public static void createUser(String firstName, String lastName,
String mailId, String loginName,
String password, String phoneNum,
String address) {
try {
// Get the default identity store
IdentityStore idStore =

// Get the user manager object
UserManager um = idStore.getUserManager();
System.out.println("got user mgr");

// Create a property for the extra attributes
PropertySet ps = new PropertySet();

ps.put(new Property(UserProfile.FIRST_NAME, firstName));
System.out.println("FIRST_NAME:" + firstName);

ps.put(new Property(UserProfile.LAST_NAME, lastName));
System.out.println("LAST_NAME:" + lastName);

ps.put(new Property(UserProfile.BUSINESS_EMAIL, mailId));
System.out.println("BUSINESS_EMAIL:" + mailId);

ps.put(new Property(UserProfile.USER_NAME, loginName));
System.out.println("USER_NAME:" + loginName);

ps.put(new Property(UserProfile.DISPLAY_NAME,
firstName + " " + lastName));
System.out.println("DISPLAY_NAME:" + firstName + " " + lastName);

ps.put(new Property(UserProfile.HOME_PHONE, phoneNum));
System.out.println("HOME_PHONE:" + phoneNum);

ps.put(new Property(UserProfile.HOME_ADDRESS, address));
System.out.println("HOME_ADDRESS:" + address);

// to create it in weblogic server
// Call the create user api with loginame, password and extra properties
um.createUser(loginName, password.toCharArray(), ps);
System.out.println("created user");
} catch (Exception e) {
if (adfLogger.isWarning()) {
adfLogger.logp(Level.WARNING, "createUser", CLASS_NAME,
"Could not create user");
public void setFirstname(String firstname) {
this.firstname = firstname;

public String getFirstname() {
return firstname;

public void setLastname(String lastname) {
this.lastname = lastname;

public String getLastname() {
return lastname;

public void setMailId(String mailId) {
this.mailId = mailId;

public String getMailId() {
return mailId;

public void setLoginName(String loginName) {
this.loginName = loginName;

public String getLoginName() {
return loginName;

public void setPassword(String password) {
this.password = password;

public String getPassword() {
return password;

public void setPhNumber(String phNumber) {
this.phNumber = phNumber;

public String getPhNumber() {
return phNumber;

public void setAddress(String address) {
this.address = address;

public String getAddress() {
return address;

3) Create a jspx page for creating the users from front end


Code for the page  manageUsers.jspx

<?xml version='1.0' encoding='UTF-8'?>
<jsp:root xmlns:jsp="" version="2.1"
< contentType="text/html;charset=UTF-8"/>
<af:document id="d1" inlineStyle="background:#efefef">
<af:form id="f1">
<af:panelGroupLayout id="pgl1" layout="vertical" inlineStyle="background:#fff;padding:100px 200px;;">
<af:outputText value="User Creation:" inlineStyle="font-size:18px;"
<af:spacer height="10px" id="s1"/>
<af:panelFormLayout labelAlignment="top">
<af:inputText label="First Name" contentStyle="font-size:14px;" inlineStyle="padding:8px 0px;font-size:16px;"
value="#{customCreateUser.firstname}" id="it1"/>
<af:inputText label="Last Name" contentStyle="font-size:14px;" inlineStyle="padding:8px 0px;font-size:16px;"
value="#{customCreateUser.lastname}" id="it2"/>
<af:inputText label="Email Id" contentStyle="font-size:14px;" inlineStyle="padding:8px 0px;font-size:16px;"
value="#{customCreateUser.mailId}" id="it3"/>
<af:inputText label="Address" contentStyle="font-size:14px;" inlineStyle="padding:8px 0px;font-size:16px;"
value="#{customCreateUser.address}" id="it4"/>
<af:inputText label="Phone Number" contentStyle="font-size:14px;" inlineStyle="padding:8px 0px;font-size:16px;"
value="#{customCreateUser.phNumber}" id="it5"/>
<af:inputText label="Login Name" contentStyle="font-size:14px;" inlineStyle="padding:8px 0px;font-size:16px;"
value="#{customCreateUser.loginName}" id="it6"/>
<af:inputText label="Password" contentStyle="font-size:14px;" inlineStyle="padding:8px 0px;font-size:16px;"
value="#{customCreateUser.password}" id="it7" secret="true" />
<af:commandButton text="Create User" id="cb1" inlineStyle="padding:5px 10px;margin:10px 0px 0px -5px"

4)  Run the page and fill all the fields present in the page and click on button Create User


5) The user will be created successfully in the weblogic server. You can check the user details in the following location: Home -> Security Realms -> myrealm -> Users and groupsSnap9

6) Click on the user and in the attributes section you can see attribute values which you gave in the front end page



One thought on “Managing Users in Web Logic Server Programatically

  1. Srinivas February 4, 2018 / 11:45 pm

    HeyThanks for the post.
    Can you share how can we update username using this API.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s