Skip to main content

WLST scripts

Here I will be covering few most commonly used WLST topics as below:


  1. Creating application roles
  2. Deleting application roles
  3. Assigning users to the application roles
  4. Revoking users from the application roles
  5. Listing out users in an application role(s)
  6. Creating users
In all these scripts I will be using a csv file as an input source (as it is more convenient). You may also prefer to user various input sources for the WLST scripts which are indeed python scripts, but you would need to have those relevant modules installed as well. csv module comes with the OS package.

WLST scripts are python scripts (.py).

All the scripts are preferred to be kept under the below location:
<middleware_home>/oracle_common/common/bin

1. Creating application roles:

Here the source is  Resp.csv file; this file contains the list of Application roles to be created as below.


Note: The source file in this scenario is placed at the same location of the file.

We use the createAppRole function in this script.


import sys
import os
WLS_HOST = '<hostname>'
WLS_PORT = '<admin server port number-non SSL port>'
WLS_USER = '<weblogic user>'
WLS_PW = '<weblogic password>'
connect (WLS_USER,WLS_PW,WLS_HOST+ ':'+WLS_PORT)
f = open('Resp.csv')
try:
for line in f.readlines():
items = line.split(',')
for item in items:
try:
createAppRole(appStripe='obi',appRoleName=item.strip())
print 'Creating new role: "'+item.strip()+'"'
except Exception, e:
print 'Cannot create "'+item.strip()+'" role, as it already exists'
print e
continue
except Exception, e:
print e
exit ()

2. Deleting application roles:

Here the source is DelResp.csv; this file contains the list of Application roles to be deleted as shown below.


We use the deleteAppRole function in this script.

import sys
import os
WLS_HOST = '<hostname>'
WLS_PORT = '<admin server port number-non SSL port>'
WLS_USER = '<weblogic user>'
WLS_PW = '<weblogic password>'
connect (WLS_USER,WLS_PW,WLS_HOST+ ':'+WLS_PORT)
f = open('DelResp.csv')
try:
for line in f.readlines():
items = line.split(',')
for item in items:
try:
deleteAppRole(appStripe='obi',appRoleName=item.strip())
print 'Deleting role: "'+item.strip()+'"'
except Exception, e:
print 'Cannot delete "'+item.strip()+'" role, as it does not exist'
print e
continue
except Exception, e:
print e
exit ()

3. Assigning users to the application roles:

Here the source is RespUsers.csv; this file contains the list of Application roles and users to be assigned to it as shown below.


We use the grantAppRole function in this script.

import sys
import os
WLS_HOST = '<hostname>'
WLS_PORT = '<admin server port number-non SSL port>'
WLS_USER = '<weblogic user>'
WLS_PW = '<weblogic password>'
connect (WLS_USER,WLS_PW,WLS_HOST+ ':'+WLS_PORT)
f = open('RespUsers.csv')
v=0
try:
for line in f.readlines():
items = line.split(',')
try:
grantAppRole('obi',items[0].strip(),'weblogic.security.principal.WLSUserImpl',items[1].strip())
print 'User name "'+items[1].strip()+'" is successfully assigned to "'+items[0].strip()+'" Role'
except Exception, e:
print  'Cannot assign "' +items[1].strip()+ '" to "' +items[0].strip()+ '" Role, as the user is already assigned to it'
continue
except Exception, e:
print e
exit ()

4. Revoking users from the application roles:

Here the source is DelUsers.csv; this file contains the list of Application roles and users to be revoked from it as shown below.


We use the revokeAppRole function in this script.

import sys
import os
WLS_HOST = '<hostname>'
WLS_PORT = '<admin server port number-non SSL port>'
WLS_USER = '<weblogic user>'
WLS_PW = '<weblogic password>'
connect (WLS_USER,WLS_PW,WLS_HOST+ ':'+WLS_PORT)
f = open('DelUsers.csv')
v=0
try:
for line in f.readlines():
items = line.split(',')
try:
revokeAppRole('obi',items[0].strip(),'weblogic.security.principal.WLSUserImpl',items[1].strip())
print 'User name "'+items[1].strip()+'" is successfully revoked from "'+items[0].strip()+'" Role'
except Exception, e:
print  'Cannot revoke "' +items[1].strip()+ '" from "' +items[0].strip()+ '" Role, as the user is not assigned to this Role'
continue
except Exception, e:
print e
exit ()

5. Listing out users in an application role:

This displays the list of users present/assigned to BIAuthor role.

In case you need this list in a csv file, you can use the shell script to spool the output.

import sys
import os
WLS_HOST = '<hostname>'
WLS_PORT = '<admin server port number-non SSL port>'
WLS_USER = '<weblogic user>'
WLS_PW = '<weblogic password>'
connect (WLS_USER,WLS_PW,WLS_HOST+ ':'+WLS_PORT)
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider('DefaultAuthenticator')
listAppRoleMembers('obi','BIAuthor')
exit ()

6. Creating Users:

Here the source is Users.csv; this file contains the list of Users to be created.

We use the atnr.createUser function in this script.

import sys
import os
WLS_HOST = '<hostname>'
WLS_PORT = '<admin server port number-non SSL port>'
WLS_USER = '<weblogic user>'
WLS_PW = '<weblogic password>'
connect (WLS_USER,WLS_PW,WLS_HOST+ ':'+WLS_PORT)
f = open('Users.csv')
try:
for line in f.readlines():
items = line.split(',')
for item in items:
try:
print 'Creating User',item.strip()
atnr=cmo.getSecurityConfiguration().getDefaultRealm().lookupAuthenticationProvider("DefaultAuthenticator")
atnr.createUser(item.strip(),'oracle123','This is a loadrunner user')
print 'User',item.strip(),'Created'
except Exception, e:
continue
except Exception, e:
print e
exit ()

For further more WLST functions follow the below URL:


In case of further doubt please write a comment.

Comments

  1. Hi,

    When we are trying to create App role we are getting errors

    ReplyDelete

Post a Comment

Popular posts from this blog

Custom Writeback in OBIEE using JS and JSP

First we will look into how to write into a database table using only JS and also the limitations. Then how to overcome those limitations. Writeback using JS: Create a JS function to write into a database table as below: eg: In this example I am using a Oracle 11g R2 database function <function_name> ( < parameter1, parameter2,... > )  { var conObj = new ActiveXObject('ADODB.Connection'); var connectionString = "Provider=OraOLEDB.Oracle;Data Source= <tns-entry> ;User Id= <schema name> ;Password= <schema password> ;"; conObj.Open(connectionString); var rs = new ActiveXObject("ADODB.Recordset"); var sql = " INSERT INTO DUMMY_TABLE(X1,X2,...) VALUES ("+parameter1+","+parameter2+",...) "; rs.Open(sql,conObj); var sq = "commit"; rs.Open(sq,conObj); //rs.close; conObj.close; location.reload(); //close(); } Append the above code after modification in common.js file loca...

Custom Button or Link in OBIEE Analytics Header

Create an xml file somewhere in the middleware home: eg: "<middleware_home>/obieecustomLinks/ customlinks.xml " <?xml version="1.0" encoding="utf-8"?> <customLinks xmlns="com.siebel.analytics.web/customlinks/v1"> <link id="l5" name=" <name of the tag> " description=" <any description> " src=" <copy paste the dashboard page url or provide any custom url> " target="self">    <locations>       <location name=" header " insertBefore=" home " />    </locations> </link> </customLinks> Add the below tags into instanceconfig.xml file: <CustomLinks>       <Enabled>true</Enabled>       <filePath> <middleware_home> /obieecustomLinks/customlinks.xml</filePath> </CustomLinks> You see the custom link is now available on the left side of home .