Changing password for existing user (passwordchange.py)

Using WLST (WebLogic Scripting Tool):


connect('weblogic', 'current_password', 't3://localhost:7001')
edit()
startEdit()

# Change password for user 'testuser'
cd('/SecurityConfiguration/mydomain/Realms/myrealm/Users/testuser')
cmo.setPassword('new_password')

save()
activate()
exit()

Script Mode:


Save as passwordchange.py and run with wlst.sh passwordchange.py:

username = 'weblogic'  # Admin username
old_password = 'old_password'  # Current password
new_password = 'new_password'  # New password
admin_url = 't3://localhost:7001'  # Admin server URL
target_user = 'testuser'  # User whose password to change

try:
    connect(username, old_password, admin_url)
    edit()
    startEdit()

    # Navigate to user in security realm
    cd('/SecurityConfiguration/mydomain/Realms/myrealm/Users/' + target_user)
    cmo.setPassword(new_password)

    save()
    activate()
    print('Password changed successfully for user: ' + target_user)
except Exception, e:
    print('Error changing password: ' + str(e))
    undo('true', 'y')
finally:
    disconnect()
    exit()

Using REST API (WebLogic 12.2.1+):


curl -X POST \
  -H "X-Requested-By: MyClient" \
  -H "Content-Type: application/json" \
  -u weblogic:current_password \
  -d '{"password": "new_password"}' \
  http://localhost:7001/management/weblogic/latest/edit/userConfigurers/testuser


Using WebLogic Admin Console (GUI):


DomainName = "base_domain"

ADMINUrl = "t3://localhost:7001"

ADMINUser = "pavan"

oldPassword = "pavan123"

newPassword = "pavan456"

print  '*****************'
connect(ADMINUser,oldPassword,ADMINUrl)

cd('/SecurityConfiguration/'+DomainName+'/Realms/myrealm/AuthenticationProviders/DefaultAuthenticator')

cmo.resetUserPassword(ADMINUser,newPassword)

print  '*****************'

disconnect()

print '*** connecting with new password***......................................'


connect(ADMINUser,newPassword,ADMINUrl)

Comments

Popular posts from this blog

Interview question for File and FTP Adapter

What is boot.properties file and how to create

SSL Exceptions in Admin Server and Node Manager.