'change-password.py' Source Code

#!/usr/bin/env python

###########################################################################
#                                                                         #
# This script demonstrates how to use the ISE ERS internal users          #
# API  by executing a Python script.                                      #
#                                                                         #
# SECURITY WARNING - DO NOT USE THIS SCRIPT IN PRODUCTION!                #
# The script allows connections to SSL sites without trusting             #
# the server certificates.                                                #
# For production, it is required to add certificate check.                #
#                                                                         #
# Usage: change-password.py <ISE host> <ERS user> <ERS password>          #
#  <user ID> <new password>                                               #
###########################################################################

import http.client
import base64
import ssl
import sys

# parameters
user_id = sys.argv[4] # "f330048f-cfb0-45db-8ef0-39efc650b711"
new_passwd = sys.argv[5] # "Password6"

# host and authentication credentials
host = sys.argv[1] # "10.20.30.40"
user = sys.argv[2] # "ersad"
password = sys.argv[3] # "Password1"


conn = http.client.HTTPSConnection("{}:9060".format(host), context=ssl.SSLContext(ssl.PROTOCOL_TLSv1))

creds = str.encode(':'.join((user, password)))
encodedAuth = bytes.decode(base64.b64encode(creds))

req_body_json = """  {{
    "InternalUser" : {{
        "id" : "{}",
        "name" : "chris",
        "password" : "{}",
        "customAttributes" : {{
        }}
    }}
}}
""".format(user_id,new_passwd)

headers = {
    'accept': "application/json",
    'content-type': "application/json",
    'authorization': " ".join(("Basic",encodedAuth)),
    'cache-control': "no-cache",
    }

conn.request("PUT", "/ers/config/internaluser/{}".format(user_id), headers=headers, body=req_body_json)

res = conn.getresponse()
data = res.read()

print("Status: {}".format(res.status))
print("Header:\n{}".format(res.headers))
print("Body:\n{}".format(data.decode("utf-8")))

Execution

python change-password.py 10.20.30.40 ersad Password1 f330048f-cfb0-45db-8ef0-39efc650b711 Password9

Status: 200 (OK)
Header:
Cache-Control: no-cache, no-store, must-revalidate
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Set-Cookie: JSESSIONIDSSO=393EEB74840EC51C8443F2190028CA03; Path=/; Secure; HttpOnly
Set-Cookie: APPSESSIONID=2C3E8DCC5B58F9E39E698E7B262A39B4; Path=/ers; Secure; HttpOnly
Pragma: no-cache
Date: Thu, 01 Dec 2016 17:40:41 GMT
Content-Type: application/json;charset=utf-8
Content-Length: 58
Server: 


Body:
{
  "UpdatedFieldsList" : {
    "updatedField" : [ ]
  }
}