userconfig与userkey理解与应用

为什么需要userconfig与userkey?

举例来说:如果我们想让某人去执行编写一些WLST管理脚本,但又不想告诉对方管理员与用户名密码,如何实现呢?再比如,我们想写一些自动执行的WLST脚本,不想在执行过程中弹出题示框让用户输入用户名与密码,同时又不想把用户名与密码写死在脚本中,又如何实现?所有这些就需要用到userconfig与userkey,简单来说userconfig文件就代表用户名,而userkey文件则代表密码,当需要用户认证时,只要出示这两个文件即可。

如何生成userconfig与userkey?

1.  进入目录WL_HOME/common/bin

2. 执行wlst.cmd/sh

3. 连接到Admin Server

connect( username, password, url )

4. 执行命令生成userconfig与userkey文件

storeUserConfig(‘<userConfigFile>’, <userKeyFile>’)

例如:

storeUserConfig(‘C:/myFiles/myuserconfigfile.secure’, ‘C:/myFiles/myuserkeyfile.secure’)

这样,我们就得到了userconfig与userkey文件

如何使用userconfig与userkey?

userconfig与userkey一般是用在WLS脚本中,例如:

connect(userConfigFile=’C:/bea922/user_projects/domains/config-file’,userKeyFile=’C:/bea922/user_projects/domains/keyfile’,url=’t3://10.10.71.79:7001′)

nmConnect(userConfigFile=’C:/bea922/user_projects/domains/config-file’,userKeyFile=’C:/bea922/user_projects/domains/keyfile’, host=’10.10.71.79′, port=’5556′, domainName=’SAML_SOURCE’, domainDir=’C:/bea922/user_projects/domains/SAML_SOURCE’, nmType=’plain’)

如何通过userconfig与userkey文件反解析出用户名与密码?

样例Java代码:

import weblogic.security.UserConfigFileManager;
import weblogic.security.UsernameAndPassword;
public class SecureReader {
	public static void main( String[] args ) {
		UsernameAndPassword usernameAndPassword = UserConfigFileManager.getUsernameAndPassword( "d:/myuserconfigfile.secure", "d:/myuserkeyfile.secure", "weblogic.management" );
		String username = new String( usernameAndPassword.getUsername() );
		String password = new String( usernameAndPassword.getPassword() );
		System.out.println( "Username=" + username + ", Password=" + password );
	}
}

编译执行:

D:\>javac -classpath S:\fmw\wlserver_10.3\server\lib\weblogic.jar SecureReader.java

D:\>java -classpath S:\fmw\wlserver_10.3\server\lib\weblogic.jar;. SecureReader
Username=weblogic, Password=welcome1

(完)

配置Unicast WebLogic Cluster WLST脚本

connect(username,password,url)
edit()
startEdit()
#创建群集
theCluster = cmo.createCluster( 'mycluster' )
theCluster.setClusterMessagingMode( 'unicast' )
theCluster.setClusterBroadcastChannel( 'myclusterChannel' )
#创建被管理服务器
ms = cmo.createServer( 'ms1' )
ms.setListenAddress( 'localhost' )
ms.setListenPort( 8001 )
ms.setCluster( theCluster )
#创建Unicast使用的通道
channel = ms.createNetworkAccessPoint( 'myclusterChannel' )
channel.setListenPort( 5001 ) #-1指通道监听端口与服务器实例监听端口相同
channel.setPublicPort( -1 ) #-1指通道外部监听端口与通道监听端口相同
channel.setProtocol( 'cluster-broadcast' ) #想更安全使用 cluster-broadcast-secure
#通道其它选项
#channel.setAddress( null ) #null 指通道监听地址与服务器实例监听地址相同
#channel.setPublicAddress( null ) #null指通道外部监听地址与通道监听地址相同
#下面三个必须Enabled
channel.setOutboundEnabled( true ) #默认是false
channel.setHttpEnabledForThisProtocol(true)
channel.setEnabled( true )
#其它选项
#channel.setTunnelingEnabled( false )
#channel.setTwoWaySSLEnabled( false )
#channel.setClientCertificateEnforced( false )
ms = cmo.createServer( 'ms2' )
ms.setListenAddress( 'localhost' )
ms.setListenPort( 9001 )
ms.setCluster( theCluster )
channel = ms.createNetworkAccessPoint( 'myclusterChannel' )
channel.setListenPort( 6001 )
channel.setPublicPort( -1 )
channel.setProtocol( 'cluster-broadcast' )
channel.setOutboundEnabled( true )
channel.setHttpEnabledForThisProtocol(true)
channel.setEnabled( true )
save()
activate()
disconnect()

原文件下载:unicast_cluster.zip