WebLogic Scripting Tool ガイド
![]() |
![]() |
![]() |
![]() |
WebLogic Scripting Tool (WLST) は、WebLogic Server ドメイン、サーバ、およびリソースの作成および管理の自動化に使用できます。WLST は、コンフィグレーション MBean のインスタンスの作成、それらの値の取得と設定、そのインスタンスに対する処理の呼び出し、およびインスタンスの削除を行うコマンドと、実行時 MBean の値を取得して、それらに対する処理を呼び出すコマンドを提供します。以下の節では、一般的なドメインおよびサーバのコンフィグレーション タスクを自動化するための WLST コマンドのオンラインでの使用について説明します。
また、以下の技術のいずれかを使用して、WebLogic Server ドメインのコンフィグレーションを自動化することもできます。
weblogic.Server
、weblogic.Admin
(このリリースの WebLogic Server では非推奨)、および weblogic.Deployer
コマンドの機能は同じである。『WebLogic Server アプリケーションの開発』の「Using Ant Tasks to Configure and Use a WebLogic Server Domain」を参照。
「サンプル ドメインを作成およびコンフィグレーションするスクリプト」では、変更された MedRec ドメインを作成するためのサンプル スクリプトを提供しています。このスクリプトは、現在のディレクトリの下に新規ディレクトリ MedRecDomain
を作成し、管理サーバを作成および起動します。WLST はサーバに接続して、MedRec ドメインの変更されたバージョンをビルドします。
deploy
コマンドを呼び出して J2EE モジュール (EJB やエンタープライズ アプリケーションなど) をデプロイします。「アプリケーションのデプロイ」を参照してください。すべての WebLogic Server コマンドで、環境の PATH
変数に SDK が指定され、CLASSPATH
変数に一連の WebLogic Server クラスが指定されている必要があります。
次のスクリプトを使用して、SDK を PATH
変数に追加し、WebLogic Server クラスを CLASSPATH
変数に追加します。
WL_HOME
\server\bin\setWLSEnv.cmd
(Windows の場合)WL_HOME
/server/bin/setWLSEnv.sh
(UNIX の場合)
WL_HOME
は、WebLogic Server の最上位インストール ディレクトリです。
JDBC リソースを使用してデータベースに接続する場合、データベース ベンダの要件に従って環境を変更します。通常、そのためには、ドライバ クラスを CLASSPATH
変数に追加し、ベンダ固有のディレクトリを PATH
変数に追加します。SDK を PATH
変数に追加し、WebLogic Server クラスを CLASSPATH
変数に追加するだけでなく、サンプル PointBase データベースで必要な環境を設定するには、次のスクリプトを呼び出します。
WL_HOME
\samples\domains\wl_server\setExamplesEnv.cmd
(Windows の場合) WL_HOME
/samples/domains/wl_server/setExamplesEnv.sh
(UNIX の場合)
コード リスト 6-1 のコマンドは、ポート 8001 をリスンする medrec-adminServer という管理サーバで MedRecDomain という名前のドメインを作成し、WLST をサーバ インスタンスに接続します。
from java.io import File
domainDir = File("MedRecDomain")
bool = domainDir.mkdir()
if bool==1:
print 'Successfully created a new Directory'
else:
if domainDir.delete()==1:
domainDir.mkdir()
print 'Successfully created a new Directory'
else:
print 'Could not create new directory, dir already exists'
stopExecution("cannot create a new directory")
debug()
dsname="myJDBCDataSource"
adminServerName="medrec-adminServer"
domainName="MedRecDomain"
_url="t3://localhost:8001"
uname="weblogic"
pwd="weblogic"
startNewServer(adminServerName,domainName,_url,domainDir=domainDir.getPath(),
block="true")
connect(uname, pwd, _url)
edit()
startEdit()
注意 : WebLogic Server がインストールするサンプル MedRec ドメインのデフォルト ポートは 7001 なので、このコマンドでは、リスン ポートとして 8001 を指定します。サンプル MedRec ドメインが実行されている場合、他のサーバ インスタンスはリスン ポート 7001 を使用できません。
コード リスト 6-2 のコマンドは、MedRecDomain のための JDBC システム リソースを作成およびコンフィグレーションします。
dsname="myJDBCDataSource"
# JDBC システム リソースの作成とコンフィグレーション
print 'Creating JDBCSystemResource with name '+dsname
jdbcSR = create(dsname,"JDBCSystemResource")
theJDBCResource = jdbcSR.getJDBCResource()
theJDBCResource.setName("myJDBCDataSource")
connectionPoolParams = theJDBCResource.getJDBCConnectionPoolParams()
connectionPoolParams.setConnectionReserveTimeoutSeconds(25)
connectionPoolParams.setMaxCapacity(100)
connectionPoolParams.setTestTableName("SYSTABLES")
dsParams = theJDBCResource.getJDBCDataSourceParams()
dsParams.addJNDIName("ds.myJDBCDataSource")
driverParams = theJDBCResource.getJDBCDriverParams()
driverParams.setUrl("jdbc:pointbase:server://localhost/demo")
driverParams.setDriverName("com.pointbase.xa.xaDataSource")
#driverParams.setUrl("jdbc:oracle:thin:@my-oracle-server:my-oracle-server-port:my-oracle-sid")
#driverParams.setDriverName("oracle.jdbc.driver.OracleDriver")
driverParams.setPassword("examples")
#driverParams.setLoginDelaySeconds(60)
driverProperties = driverParams.getProperties()
proper = driverProperties.createProperty("user")
#proper.setName("user")
proper.setValue("examples")
proper1 = driverProperties.createProperty("DatabaseName")
#proper1.setName("DatabaseName")
proper1.setValue("jdbc:pointbase:server://localhost/demo")
コード リスト 6-3 のコマンドは、MedRecDomain 内に JMS システム リソースを作成します。
# JMS システム リソースの作成
jmsSystemResource = create("medrec-jms-resource","JMSSystemResource")
theJMSResource = jmsSystemResource.getJMSResource()
# JMS 接続ファクトリの作成
mrqFactory = theJMSResource.createConnectionFactory("MedRecQueueFactory")
mrqFactory.setJNDIName("jms/MedRecQueueConnectionFactory")
# JMS JDBC ストアの作成とコンフィグレーション
mrjStore = create("MedRecJMSJDBCStore","JDBCStore")
mrjStore.setDataSource(jdbcSR)
mrjStore.setPrefixName("MedRec")
# JMS サーバの作成とコンフィグレーション
mrJMSServer = create("MedRecJMSServer","JMSServer")
mrJMSServer.setStore(mrjStore)
# キューの作成とコンフィグレーション
regQueue = theJMSResource.createQueue("RegistrationQueue")
regQueue.setJNDIName("jms/REGISTRATION_MDB_QUEUE")
# 追加のキューの作成とコンフィグレーション
mailQueue = theJMSResource.createQueue("MailQueue")
mailQueue.setJNDIName("jms/MAIL_MDB_QUEUE")
『WebLogic JMS のコンフィグレーションと管理』の「Using the WebLogic Scripting Tool to Manage JMS Servers and JMS System Resources」を参照してください。
コード リスト 6-4 のコマンドは、MailSessionMBean
を作成およびコンフィグレーションして、MedRecDomain 内のサンプル アプリケーションに電子メール機能を追加します。
# メール リソースの作成
mrMailSession = create("MedicalRecordsMailSession","MailSession")
mrMailSession.setJNDIName("mail/MedRecMailSession")
mrMailSession.setProperties(makePropertiesObject("mail.user=joe;mail.host=mail.mycompany.com"))
MailSessionMBean
のすべての属性および有効な値を確認するには、『WebLogic Server® MBean リファレンス』の「MailSessionMBean
」を参照してください。WebLogic Server メール サービスの詳細については、Administration Console オンライン ヘルプの「JavaMail へのアクセスのコンフィグレーション」を参照してください。
コード リスト 6-5 のコマンドは、MedRecDomain 内のサンプル アプリケーションをデプロイします。
# アプリケーションのデプロイ
deploy("PhysicianEAR","C:/bea/weblogic90/samples/server/medrec/src/physicianEar","medrec-adminServer",securityModel="Advanced",block="true")
deploy("StartupEAR","C:/bea/weblogic90/samples/server/medrec/src/startupEar","medrec-adminServer",securityModel="Advanced",block="true")
deploy("MedRecEAR","C:/bea/weblogic90/samples/server/medrec/src/medrecEAR","medrec-adminServer",securityModel="Advanced",block="true")
CLASSPATH
環境変数に JDBC ドライバを指定する必要があります。「環境の設定」を参照してください。 WL_HOME
\samples\server\medrec\src
ディレクトリにあります。 WLST を使用してのアプリケーションのデプロイの詳細については、『WebLogic Server 9.0 アプリケーションのデプロイメント』の「Overview of Deployment Tools」を参照してください。
コード リスト 6-6 は、変更された MedRec ドメインを作成するためのサンプル スクリプトを提供します。このスクリプトは、一般的な WebLogic Server ドメインを作成およびコンフィグレーションするためのテンプレートとして使用できます。
注意 : このサンプル スクリプトでは、WebLogic Server と一緒にインストールされたデモ用の PointBase Server を使用します。スクリプトを実行する前に、次のコマンドのいずれかを発行して、PointBase Server を起動する必要があります。
Windows の場合 : WL_HOME
\common\eval\pointbase\tools\startPointBase.cmd
UNIX の場合 : WL_HOME
/common/eval/pointbase/tools/startPointBase.sh
MedRec サンプル ドメインなどのドメインを作成およびコンフィグレーションするには、次の手順に従います。
cloneDomain.py
) として保存します。 java weblogic.WLST <
filepath
>/cloneDomain.py
このスクリプトを実行する方法の詳細については、「スクリプトの実行」を参照してください。
from java.io import File
domainDir = File("MedRecDomain")
bool = domainDir.mkdir()
if bool==1:
print 'Successfully created a new Directory'
else:
if domainDir.delete()==1:
domainDir.mkdir()
print 'Successfully created a new Directory'
else:
print 'Could not create new directory, dir already exists'
stopExecution("cannot create a new directory")
debug()
dsname="myJDBCDataSource"
adminServerName="medrec-adminServer"
domainName="MedRecDomain"
_url="t3://localhost:8001"
uname="weblogic"
pwd="weblogic"
startNewServer(adminServerName,domainName,_url,domainDir=domainDir.getPath(),
block="true")
connect(uname, pwd, _url)
edit()
startEdit()
# JDBC システム リソースの作成とコンフィグレーション
print 'Creating JDBCSystemResource with name '+dsname
jdbcSR = create(dsname,"JDBCSystemResource")
theJDBCResource = jdbcSR.getJDBCResource()
theJDBCResource.setName("myJDBCDataSource")
connectionPoolParams = theJDBCResource.getJDBCConnectionPoolParams()
connectionPoolParams.setConnectionReserveTimeoutSeconds(25)
connectionPoolParams.setMaxCapacity(100)
connectionPoolParams.setTestTableName("SYSTABLES")
dsParams = theJDBCResource.getJDBCDataSourceParams()
dsParams.addJNDIName("ds.myJDBCDataSource")
driverParams = theJDBCResource.getJDBCDriverParams()
driverParams.setUrl("jdbc:pointbase:server://localhost/demo")
driverParams.setDriverName("com.pointbase.xa.xaDataSource")
#driverParams.setUrl("jdbc:oracle:thin:@my-oracle-server:my-oracle-server-port:my-oracle-sid")
#driverParams.setDriverName("oracle.jdbc.driver.OracleDriver")
driverParams.setPassword("examples")
#driverParams.setLoginDelaySeconds(60)
driverProperties = driverParams.getProperties()
proper = driverProperties.createProperty("user")
#proper.setName("user")
proper.setValue("examples")
proper1 = driverProperties.createProperty("DatabaseName")
#proper1.setName("DatabaseName")
proper1.setValue("jdbc:pointbase:server://localhost/demo")
# JMS システム リソースの作成
jmsSystemResource = create("medrec-jms-resource","JMSSystemResource")
theJMSResource = jmsSystemResource.getJMSResource()
# JMS 接続ファクトリの作成
mrqFactory = theJMSResource.createConnectionFactory("MedRecQueueFactory")
mrqFactory.setJNDIName("jms/MedRecQueueConnectionFactory")
# JMS JDBC ストアの作成とコンフィグレーション
mrjStore = create("MedRecJMSJDBCStore","JDBCStore")
mrjStore.setDataSource(jdbcSR)
mrjStore.setPrefixName("MedRec")
# JMS サーバの作成とコンフィグレーション
mrJMSServer = create("MedRecJMSServer","JMSServer")
mrJMSServer.setPersistentStore(mrjStore)
# キューの作成とコンフィグレーション
regQueue = theJMSResource.createQueue("RegistrationQueue")
regQueue.setJNDIName("jms/REGISTRATION_MDB_QUEUE")
# 追加のキューの作成とコンフィグレーション
mailQueue = theJMSResource.createQueue("MailQueue")
mailQueue.setJNDIName("jms/MAIL_MDB_QUEUE")
# メール リソースの作成
mrMailSession = create("MedicalRecordsMailSession","MailSession")
mrMailSession.setJNDIName("mail/MedRecMailSession")
mrMailSession.setProperties(makePropertiesObject("mail.user=joe;mail.host=mail.mycompany.com"))
# サーバの対象の取得とコンフィグレーション
tgt = getMBean("/Servers/medrec-adminServer")
tgt.setJavaCompiler("javac")
tgt.setListenAddress("localhost")
tgt.setListenPort(8001)
#tgt.setIIOPEnabled(0)
tgt.setInstrumentStackTraceEnabled(1)
ssl = tgt.getSSL()
ssl.setEnabled(1)
ssl.setIdentityAndTrustLocations("KeyStores")
ssl.setListenPort(9992)
# medrec 管理サーバへのリソースの対象指定
jdbcSR.addTarget(tgt)
jmsSystemResource.addTarget(tgt)
mrjStore.addTarget(tgt)
mrJMSServer.addTarget(tgt)
mrMailSession.addTarget(tgt)
save()
activate(block="true")
shutdown(force="true",block="true")
print 'end of the script ... '
WebLogic Server には、リソースの実行時の状態に関する情報を提供する MBean が数多く用意されています。ドメイン内の各サーバ インスタンスは、固有のリソースをコンフィグレーションおよびモニタする MBean のみをホストします。しかし、管理サーバでは、ドメイン全体のサービスの MBean は、ルートを DomainRuntimeMBean
とした単一の階層内にあります。ドメイン実行時 MBean 階層は、アプリケーションのデプロイメント、JMS サーバ、JDBC 接続プールなどのドメイン全体のサービスの MBean に加えて、ドメイン内の任意のサーバ上の任意の実行時 MBean へのアクセスを提供します。
ドメインの実行時情報にアクセスする主な手順は、次のとおりです。
-r-- AllProcessorsAverageLoad 0.0
-r-- Concurrent true
-r-- FreeHeap 15050064
-r-- FreePhysicalMemory 900702208
-r-- GCHandlesCompaction true
-r-- GcAlgorithm Dynamic GC currently running
strategy: Nursery, parallel mark, parallel sweep
-r-- Generational true
-r-- HeapFreeCurrent 14742864
-r-- HeapFreePercent 5
-r-- HeapSizeCurrent 268435456
-r-- HeapSizeMax 268435456
-r-- Incremental false
-r-- JVMDescription BEA JRockit Java Virtual Machine
-r-- JavaVMVendor BEA Systems, Inc.
-r-- JavaVendor BEA Systems, Inc.
-r-- JavaVersion 1.5.0
...
以下の節では、WebLogic Server サーバ インスタンスおよびドメイン リソースに関する実行時情報を取得するためのサンプル スクリプトを提供しています。
コード リスト 6-7 の WLST オンライン スクリプトは、5 秒ごとに管理対象サーバのステータスをチェックし、サーバ状態が RUNNING
から他のステータスに変わると、サーバを再起動します。
このスクリプトを実行する方法については、「スクリプトの実行」を参照してください。
# このスクリプトを実行するには、ノード マネージャが実行中であることが必要である。
import thread
import time
def checkHealth(serverName):
while 1:
slBean = getSLCRT(serverName)
status = slBean.getState()
print 'Status of Managed Server is '+status
if status != "RUNNING":
print 'Starting server '+serverName
start(serverName, block="true")
time.sleep(5)
def getSLCRT(svrName):
domainRuntime()
slrBean = cmo.lookupServerLifecycleRuntime(svrName)
return slcBean
コード リスト 6-8 の WLST オンライン スクリプトは、ドメイン内のすべての実行中のサーバの HJVMHeapSize
をモニタします。3 分ごとにヒープ サイズをチェックし、指定したしきい値をヒープ サイズが上回ると、警告を出力します。
このスクリプトを実行する方法については、「スクリプトの実行」を参照してください。
waitTime=300000
THRESHOLD=100000000
uname = "weblogic"
pwd = "weblogic"
url = "t3://localhost:7001"
def monitorJVMHeapSize():
connect(uname, pwd, url)
while 1:
serverNames = getRunningServerNames()
domainRuntime()
for name in serverNames:
print 'Now checking '+name.getName()
try:
cd("/ServerRuntimes/"+name.getName()+"/JVMRuntime/"+name.getName())
except WLSTException,e:
# これは通常、サーバがアクティブでないことを意味しているので、無視する
pass
heapSize = cmo.getHeapSizeCurrent()
if heapSize > THRESHOLD:
# 必要な処理を実行する (アラートの送信、電子メールの送信など)
print 'WARNING: The HEAPSIZE is Greater than the Threshold'
else:
print heapSize
java.lang.Thread.sleep(1800000)
def getRunningServerNames():
domainConfig()
return cmo.getServers()
if __name__== "main":
monitorJVMHeapSize()
WebLogic Security サービスでは、認証プロバイダはユーザまたはシステム プロセスの身元を証明するソフトウェア コンポーネントです。認証プロバイダでは、ID 情報を記憶したり、転送したり、その情報が必要な場合にシステムのさまざまなコンポーネントで利用できるようにしたりします。セキュリティ レルムは、さまざまな種類の認証プロパティを使用して異なるユーザおよびグループのセットを管理できます。『WebLogic セキュリティ プロバイダの開発』の「Authentication Providers」を参照してください。
WLST を使用すると、次のタイプの認証プロバイダの操作を呼び出すことができます。
weblogic.management.security.authentication.AuthenticatorMBean
。デフォルトでは、セキュリティ レルムはこの認証プロバイダを使用してユーザとグループを管理します。weblogic.security.spi.AuthenticationProvider
と任意 Authentication SSPI MBean を拡張したカスタム認証プロバイダ。詳細については、『WebLogic セキュリティ プロバイダの開発』の「SSPI MBean Quick Reference」を参照してください。以下の節では、WLST を使用してユーザおよびグループを管理するための基本的なタスクについて説明します。
AuthenticationProvider
および任意の MBean がサポートする追加のタスクについては、『WebLogic Server® MBean リファレンス』の「weblogic.management.security.authentication
」のパッケージを参照してください。
注意 : WebLogic Server 6.0 方式のセキュリティ MBean は、WLST を使用してアクセス可能ですが、ls
コマンドでは表示されません。たとえば、次のコマンドを入力すると、WLST はドメイン MBean を表示しますが、FileRealms などの除外された属性は表示しません。
java weblogic.WLST
connect()
ls()
しかし、次のコマンドを入力した場合、WLST は DomainMBean
のファイル レルムを表示します。
java weblogic.WLST
connect()
cmo.getFileRealms()
ユーザを作成するには、UserEditorMBean.createUser
メソッドを呼び出します。このメソッドは、セキュリティ レルムの AuthenticationProvider
MBean によって拡張されます。詳細については、『WebLogic Server® MBean リファレンス』の「createUser
」メソッドを参照してください。
username password user-description
次の WLST オンライン スクリプトは、デフォルトの認証プロバイダに対して createUser
を呼び出します。このスクリプトを実行する方法については、「スクリプトの実行」を参照してください。
from weblogic.management.security.authentication import UserEditorMBean
print "Creating a user ..."
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider("DefaultAuthenticator")
atnr.createUser('my_user','my_password','new_admin')
print "Created user successfully"
ユーザをグループに追加するには、GroupEditorMBean.addMemberToGroup
メソッドを呼び出します。このメソッドは、セキュリティ レルムの AuthenticationProvider
MBean によって拡張されます。詳細については、『WebLogic Server® MBean リファレンス』の「addMemberToGroup
」メソッドを参照してください。
次の WLST オンライン スクリプトは、デフォルトの認証プロバイダに対して addMemberToGroup
を呼び出します。このスクリプトを実行する方法については、「スクリプトの実行」を参照してください。
from weblogic.management.security.authentication import GroupEditorMBean
print "Adding a user ..."
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider("DefaultAuthenticator")
atnr.addMemberToGroup
('Administrators','my_user')
print "Done adding a user"
ユーザがグループのメンバーであるかどうかを検証するには、GroupEditorMBean.isMember
メソッドを呼び出します。このメソッドは、セキュリティ レルムの AuthenticationProvider
MBean によって拡張されます。詳細については、『WebLogic Server® MBean リファレンス』の「isMember
」メソッドを参照してください。
boolean
は、子グループ内を検索するかどうかを指定します。true
を指定した場合、指定したグループまたはその子グループにメンバーが属していれば true
が返されます。
次の WLST オンライン スクリプトは、デフォルトの認証プロバイダに対して isMember
を呼び出します。このスクリプトを実行する方法については、「スクリプトの実行」を参照してください。
コード リスト 6-11 ユーザがグループのメンバーであるかどうかの検証
from weblogic.management.security.authentication import GroupEditorMBean
print "Checking if isMember of a group ..."
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider("DefaultAuthenticator")
if atnr.isMember('Administrators','my_user',true) == 0:
print "my_user is not member of Administrators"
else:
print "my_user is a member of Administrators"
ユーザまたはグループが含まれるグループのリストを表示するには、MemberGroupListerMBean.listMemberGroups
メソッドを呼び出します。このメソッドは、セキュリティ レルムの AuthenticationProvider
MBean によって拡張されます。詳細については、『WebLogic Server® MBean リファレンス』の「listMemberGroups
」メソッドを参照してください。
memberUserOrGroupName
は既存のユーザまたはグループの名前を指定します。
次の WLST オンライン スクリプトは、デフォルトの認証プロバイダに対して listMemberGroups
を呼び出します。このスクリプトを実行する方法については、「スクリプトの実行」を参照してください。
コード リスト 6-12 ユーザが所属するグループのリスト表示
from weblogic.management.security.authentication import MemberGroupListerMBean
print "Listing the member groups ..."
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider("DefaultAuthenticator")
x = atnr.listMemberGroups
('my_user')
print x
このメソッドは、名前のリストを参照するカーソルを返します。weblogic.management.utils.NameLister.haveCurrent
、getCurrentName
、および advance
の各メソッドは、返されたリスト内で繰り返し実行され、現在のカーソル位置が指し示す名前を取得します。『WebLogic Server® MBean リファレンス』の「weblogic.management.utils.NameLister
」インタフェースを参照してください。
ユーザ名またはグループ名のリストを確認するには、AuthenticationProvider
インタフェースを介して使用できる一連のメソッドを呼び出します。
GroupReaderMBean.listGroups
メソッドおよび UserReaderMBean.listUsers
メソッドは 2 つの入力パラメータを取ります。1 つは検索するユーザまたはグループ名のパターンで、もう 1 つは取得する名前の最大数です。セキュリティ レルムにはパターンに一致するユーザ名またはグループ名が数千 (またはそれ以上) 存在する場合があるので、このメソッドでは名前のリストを指し示すカーソルが返されます。
詳細については、『WebLogic Server® MBean リファレンス』の「listGroups
」および「listUsers
」メソッドを参照してください。
NameLister
.haveCurrent
、getCurrentName
、および advance
の各メソッドは、返されたリスト内で繰り返し実行され、現在のカーソル位置が指し示す名前を取得します。詳細については、『WebLogic Server® MBean リファレンス』の「NameListerMBean
」インタフェースを参照してください。NameLister
.close
メソッドは、リストの代わりに保持されていたサーバ側リソースを解放します。コード リスト 6-13 の WLST オンライン スクリプトは、レルム内のすべてのユーザと、それらのユーザが属するグループをリスト表示します。このスクリプトを実行する方法については、「スクリプトの実行」を参照してください。
from weblogic.management.security.authentication import UserReaderMBean
from weblogic.management.security.authentication import GroupReaderMBean
realm=cmo.getSecurityConfiguration().getDefaultRealm()
atns = realm.getAuthenticationProviders()
for i in atns:
if isinstance(i,UserReaderMBean):
userReader = i
cursor = i.listUsers("*",0)
print 'Users in realm '+realm.getName()+' are: '
while userReader.haveCurrent(cursor):
print userReader.getCurrentName(cursor)
userReader.advance(cursor)
userReader.close(cursor)
for i in atns:
if isinstance(i,GroupReaderMBean):
groupReader = i
cursor = i.listGroups("*",0)
print 'Groups in realm are: '
while groupReader.haveCurrent(cursor):
print groupReader.getCurrentName(cursor)
groupReader.advance(cursor)
groupReader.close(cursor)
ユーザのパスワードを変更するには、UserPasswordEditorMBean.changeUserPassword
メソッドを呼び出します。このメソッドは、セキュリティ レルムの AuthenticationProvider
MBean によって拡張されます。詳細については、『WebLogic Server® MBean リファレンス』の「changeUserPassword
」メソッドを参照してください。
次の WLST オンライン スクリプトは、デフォルトの認証プロバイダに対して changeUserPassword
を呼び出します。このスクリプトを実行する方法については、「スクリプトの実行」を参照してください。
from weblogic.management.security.authentication import UserPasswordEditorMBean
print "Changing password ..."
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider("DefaultAuthenticator")
atnr.changeUserPassword('my_user','my_password','new_password')
print "Changed password successfully"
WebLogic Server には、侵入者からユーザ アカウントを保護する一連の属性が用意されています。デフォルトでは、これらの属性は最高の保護レベルに設定されています。このユーザ アカウントの保護レベルを下げることもできます。たとえば、アカウントがロックされるまでの無効なログイン試行回数を増やしたり、ユーザ アカウントがロックされるまでの無効なログイン試行期間を延ばしたり、ユーザ アカウントのロック時間を変更したりできます。
AuthenticationProvider
MBean は、ユーザ アカウントを保護するためにメソッドを拡張しません。代わりに、UserLockoutManagerMBean
を取得してそのメソッドを呼び出します。詳細については、『WebLogic Server® MBean リファレンス』の「UserLockoutManagerMBean
」インタフェースを参照してください。
以下のタスクでは、UserLockoutManagerMBean
メソッドを呼び出す例を示します。
次の WLST オンライン スクリプトでは、ユーザ アカウントがロックされるまでの連続する無効なログイン試行回数が設定されます。このスクリプトを実行する方法については、「スクリプトの実行」を参照してください。
コード リスト 6-15 連続する無効なログイン試行回数の設定
from weblogic.management.security.authentication import UserLockoutManagerMBean
edit()
startEdit()
# コンフィグレーションするユーザ ロックアウト マネージャを取得する際、2 つの選択肢がある
# 1 - デフォルトのレルムの UserLockoutManager をコンフィグレーションする :
ulm=cmo.getSecurityConfiguration().getDefaultRealm().getUserLockoutManager()
# 2 - 別のレルムの UserLockoutManager をコンフィグレーションする :
#ulm=cmo.getSecurityConfiguration().lookupRealm("anotherRealm").getUserLockoutManager()
ulm.setLockoutThreshold(3)
save()
activate()
次の WLST オンライン スクリプトは、ユーザ アカウントのロックを解除します。このスクリプトを実行する方法については、「スクリプトの実行」を参照してください。
from weblogic.management.security.authentication import UserLockoutManagerMBean
serverRuntime()
ulm=cmo.getServerSecurityRuntime().getDefaultRealmRuntime().getUserLockoutManagerRuntime()
# 注意 1 : サーバ起動時に起動したデフォルトのレルム (他の非アクティブなレルムではなく) のユーザ ロックアウトのみ管理できる。
#注意 2 : デフォルトのレルムのユーザ ロックアウト マネージャの LockoutEnabled が false であれば、ユーザ ロックアウト マネージャの実行時 MBean は null となる。
# つまり、ユーザ ロックアウト マネージャが有効である場合のみ、デフォルト レルム内のユーザ ロックアウトを管理できる。
if ulm != None:
ulm.clearLockout("myuser")
WLST を使用すると、サーバ インスタンスのロギングおよびメッセージ出力をコンフィグレーションできます。
コンフィグレーションできるログ属性を判断するには、『WebLogic Server® MBean リファレンス』の「LogMBean
」および「LogFileMBean
」を参照してください。このリファレンスでは、各属性の有効な値も示されています。
コード リスト 6-17 の WLST オンライン スクリプトは、いくつかの LogMBean
および LogFileMBean
属性を取得および設定します。このスクリプトを実行する方法については、「スクリプトの実行」を参照してください。
from java.lang import Boolean
from java.lang import System
from java.lang import Integer
username = System.getProperty("user","weblogic
")
password = System.getProperty("password","weblogic
")
adminHost = System.getProperty("adminHost","localhost")
adminPort = System.getProperty("adminPort","7001")
protocol = System.getProperty("protocol","t3")
url = protocol+"://"+adminHost+":"+adminPort
fileCount = Integer.getInteger("fileCount", 5)
fileMinSize = Integer.getInteger("fileMinSize", 400)
fileName = System.getProperty("fileName","config\\mydomain
\\myserver
\\myserver
.log")
fileTimeSpan = Integer.getInteger("fileTimeSpan", 12)
log4jEnabled = System.getProperty("log4jEnabled", "true")
stdoutSeverity = System.getProperty("stdoutSeverity", "Info")
logBRSeverity = System.getProperty("logBRSeverity", "Info")
logFileSeverity = System.getProperty("logFileSeverity", "Info")
memBufferSeverity = System.getProperty("memBufferSeverity", "Info")
memBufferSize = Integer.getInteger("memBufferSize", 400)
numOfFilesLimited = System.getProperty("numOfFilesLimited", "true")
redirectStdout = System.getProperty("redirectStdout", "true")
redirectStdErr = System.getProperty("redirectStdErr", "true")
rotateOnStartup = System.getProperty("rotateOnStartup", "false")
rotateTime = System.getProperty("rotateTime", "00:10")
rotateType = System.getProperty("rotateType", "byTime")
print "Connecting to " + url + " as [" + \
username + "," + password + "]"
# サーバに接続する
connect(username,password,url)
edit()
startEdit()
# CMO をサーバのログ コンフィグレーションに設定する
cd("Servers/myserver
/Log/myserver
")
ls ()
# LogFileMBean および LogMBean 属性を変更する
print "Original FileCount is " + 'get("FileCount")'
print "Setting FileCount to be " + \QfileCount\Q
set("FileCount", fileCount)
print "Original FileMinSize is " + 'get("FileMinSize")'
print "Setting FileMinSize to be " + 'fileMinSize'
set("FileMinSize", fileMinSize)
print "Original FileName is " + 'get("FileName")'
print "Setting FileName to be " + 'fileName'
set("FileName", fileName)
print "Original FileTimeSpan is " + 'get("FileTimeSpan")'
print "Setting FileTimeSpan to be " + 'fileTimeSpan'
set("FileTimeSpan", fileTimeSpan)
print "Original Log4jEnabled is " + 'get("Log4jLoggingEnabled")'
print "Setting Log4jLoggingEnabled to be " + 'log4jEnabled'
set("Log4jLoggingEnabled", log4jEnabled)
print "Original StdoutSeverity is " + 'get("StdoutSeverity")'
print "Setting StdoutSeverity to be " + 'stdoutSeverity'
set("StdoutSeverity", stdoutSeverity)
print "Original DomainLogBroadcastSeverity is " + \Qget("DomainLogBroadcastSeverity")\Q
print "Setting DomainLogBroadcastSeverity to be " + 'logBRSeverity'
set("DomainLogBroadcastSeverity", logBRSeverity)
print "Original LogFileSeverity is " + 'get("LogFileSeverity")'
print "Setting LogFileSeverity to be " + 'logFileSeverity'
set("LogFileSeverity", logFileSeverity)
print "Original MemoryBufferSeverity is " + 'get("MemoryBufferSeverity")'
print "Setting MemoryBufferSeverity to be " + 'memBufferSeverity'
set("MemoryBufferSeverity", memBufferSeverity)
print "Original MemoryBufferSize is " + 'get("MemoryBufferSize")'
print "Setting MemoryBufferSize to be " + 'memBufferSize'
set("MemoryBufferSize", memBufferSize)
print "Original NumberOfFilesLimited is " + 'get("NumberOfFilesLimited")'
print "Setting NumberOfFilesLimited to be " + 'numOfFilesLimited'
set("NumberOfFilesLimited", numOfFilesLimited)
print "Original RedirectStdoutToServerLogEnabled is " + 'get("RedirectStdoutToServerLogEnabled")'
print "Setting RedirectStdoutToServerLogEnabled to be " + 'redirectStdout'
set("RedirectStdoutToServerLogEnabled", redirectStdout)
print "Original RedirectStderrToServerLogEnabled is " + 'get("RedirectStderrToServerLogEnabled")'
print "Setting RedirectStderrToServerLogEnabled to be " + 'redirectStdErr'
set("RedirectStderrToServerLogEnabled", redirectStdErr)
print "Original RotateLogOnStartup is " + 'get("RotateLogOnStartup")'
print "Setting RotateLogOnStartup to be " + 'rotateOnStartup'
set("RotateLogOnStartup", rotateOnStartup)
print "Original RotationTime is " + 'get("RotationTime")'
print "Setting RotationTime to be " + 'rotateTime'
set("RotationTime", rotateTime)
print "Original RotationType is " + 'get("RotationType")'
print "Setting RotationType to be " + 'rotateType'
set("RotationType", rotateType)
save()
activate()
ls ()
# すべて完了...
exit()
WLST を使用しての WebLogic 診断フレームワークのコンフィグレーションを示すサンプル スクリプトについては、『WebLogic 診断フレームワークのコンフィグレーションと使い方』の「WebLogic Scripting Tool Examples」を参照してください。
![]() ![]() |
![]() |
![]() |