Question & Answer
Question
How do I use Jython scripting to import or export Lightweight Third Party Authentication (LTPA) keys with IBM® WebSphere® Application Server Version 6.1 and 7.0?
Answer
This document provides examples of how to use Jython scripting to import and export LTPA keys with WebSphere Application Server Version 6.1 and 7.0.
These scripts are examples only.
Note: When you use the following scripts in a deployment manager environment, change
security=AdminControl.queryNames('*:*,name=SecurityAdmin')
to
security=AdminControl.queryNames( 'process=dmgr,
type=SecurityAdmin,*' )
Importing LTPA keys
import java.lang.String as jstr
import java.util.Properties as jprops
import java.io as jio
import javax.management as jmgmt
def printUsage():
print ""
print "Usage: install_root/bin/wsadmin -lang jython"
print "[-user username]" [-password password]"
print "-f LTPAKeyFile key_password"
print "where install_root is the root directory for WebSphere"
print " Application Server"
print " username is the WebSphere Application Server"
print " user"
print " password is the user password"
print " LTPAKeyFile is the file from which you are"
print " importing the LTPA keys"
print " key_password is the password that was used to"
print " encrypt the keys"
print ""
print "Sample:"
print "===================================================================="
print "wsadmin -lang jython -user tipadmin -password admin123"
print " -f \"c:\\temp\\importLTPAKeys.py\""
print " \"c:\\\\temp\\\\ltpakeys.txt\" admin123"
print "===================================================================="
print ""
# Verify that the correct number of parameters exist
if not (len(sys.argv) == 2):
sys.stderr.write("Invalid number of arguments\n")
printUsage()
sys.exit(101)
password=jstr(sys.argv[1]).getBytes()
security=AdminControl.queryNames('*:*,name=SecurityAdmin')
securityON=jmgmt.ObjectName(security)
fin=jio.FileInputStream(sys.argv[0])
ltpaKeys=jprops()
ltpaKeys.load(fin)
fin.close()
params=[ltpaKeys, password]
signature=['java.util.Properties', '[B']
AdminControl.invoke_jmx(securityON,'importLTPAKeys', params, signature)
Exporting LTPA keys
import java.lang.String as jstr
import java.util.Properties as jprops
import java.io as jio
import javax.management as jmgmt
def printUsage():
print ""
print "Usage: install_root/bin/wsadmin -lang jython"
print "[-user username] [-password password]"
print "-f LTPAKeyFile file_password"
print "where install_root is the root directory for WebSphere"
print " Application Server"
print " username is the WebSphere Application Server"
print " user"
print " password is the user password"
print " LTPAKeyFile is the file to which you are"
print " exporting the LTPA keys"
print " key_password is the password that is used to"
print " encrypt the exported keys
print ""
print "Sample:"
"===================================================================="
print "wsadmin -lang jython -user tipadmin -password admin123"
print " -f \"c:\\temp\\exportLTPAKeys.py\""
print " \"c:\\\\temp\\\\ltpakeys.txt\" admin123"
print "===================================================================="
print ""
# Verify that the correct number of parameters were passed
if not (len(sys.argv) == 2):
sys.stderr.write("Invalid number of arguments\n")
printUsage()
sys.exit(101)
ltpaKeyFile=sys.argv[0]
password=jstr(sys.argv[1]).getBytes()
security=AdminControl.queryNames('*:*,name=SecurityAdmin')
securityON=jmgmt.ObjectName(security)
params=[password]
signature=['[B']
ltpaKeys=AdminControl.invoke_jmx(securityON,'exportLTPAKeys', params, signature)
fout=jio.FileOutputStream(ltpaKeyFile)
ltpaKeys.store(fout,'')
fout.close()
[{"Product":{"code":"SSEQTP","label":"WebSphere Application Server"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Security","Platform":[{"code":"PF002","label":"AIX"},{"code":"PF010","label":"HP-UX"},{"code":"PF012","label":"IBM i"},{"code":"PF016","label":"Linux"},{"code":"PF027","label":"Solaris"},{"code":"PF033","label":"Windows"}],"Version":"7.0;6.1","Edition":"Base;Express;Network Deployment","Line of Business":{"code":"LOB45","label":"Automation"}},{"Product":{"code":"SS7K4U","label":"WebSphere Application Server for z\/OS"},"Business Unit":{"code":"BU053","label":"Cloud & Data Platform"},"Component":"Security","Platform":[{"code":"PF035","label":"z\/OS"}],"Version":"7.0;6.1","Edition":"","Line of Business":{"code":"LOB45","label":"Automation"}}]
Was this topic helpful?
Document Information
Modified date:
15 June 2018
UID
swg21320758