我创建了一个 WLST 脚本来检查用户是否属于特定组。 shell 脚本读取用户和组名的输入并将其发送到 python 脚本。这是Python脚本:
d_user=sys.argv[1]
print 'User is ' +d_user
d_group=sys.argv[2]
print 'Group is ' +d_group
connect(userConfigFile='WebLogicConfig.properties',userKeyFile='WebLogicKey.properties',url='t3://wl-test.com:80')
realmName=cmo.getSecurityConfiguration().getDefaultRealm()
authProvider = realmName.getAuthenticationProviders()
from weblogic.management.security.authentication import GroupEditorMBean
print "Checking if 'd_user' is a member of the group 'd_group' ... "
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider("DefaultAuthenticator")
if atnr.isMember('d_group','d_user',true) == 0:
print "+d_user is not member of +d_group"
else:
print "+d_user is a member of +d_group"
这是输出:
./UserGroupCheck.sh
Enter the user name you want to check : weblogic
Enter the group name you want to check for weblogic : Administrators
CLASSPATH=...
PATH=...
Your environment has been set.
Initializing WebLogic Scripting Tool (WLST) ...
Welcome to WebLogic Server Administration Scripting Shell
Type help() for help on available commands
User is weblogic
Group is Administrators
Connecting to t3://wl-test.com:80 with userid weblogic ...
Successfully connected to Admin Server..
...
Checking if 'd_user' is a member of the group 'd_group' ...
Problem invoking WLST - Traceback (innermost last):
File "UserGroupCheck.py", line 20, in ?
weblogic.management.utils.NotFoundException: [Security:090259]Group d_group can not be found.
at weblogic.utils.StackTraceDisabled.unknownMethod()
weblogic.management.utils.NotFoundException: weblogic.management.utils.NotFoundException: [Security:090259]Group d_group can not be found.
它未能抱怨找不到组。 python 脚本d_user
最初能够接受 和 的变量d_group
,但是一旦连接到 Weblogic 域,它就无法识别为d_user
&给出的值d_group
,而是将变量名称作为实际输入。
Checking if 'd_user' is a member of the group 'd_group'
如果我用实际用户和组替换d_user
& ,该脚本工作正常。d_group
我无法弄清楚我忽略了什么。
答案1
中的引号
atnr.isMember('d_group','d_user',true)
问题是:
atnr.isMember(d_group,d_user,true)