Thursday 18 February 2016

Import and Export users from Embedded LDAP using WLST

Export
connect(‘weblogic’,’weblogic’, ‘t3://localhost:8003′)
domainRuntime()
cd(‘/DomainServices/DomainRuntimeService/DomainConfiguration/DomainA/SecurityConfiguration/DomainA/DefaultRealm/myrealm/AuthenticationProviders/DefaultAuthenticator’)
cmo.exportData(‘DefaultAtn’,’c:/export.ldif’, Properties())
Import
connect(‘weblogic’,’weblogic’, ‘t3://localhost:8003′)
domainRuntime()
cd(‘/DomainServices/DomainRuntimeService/DomainConfiguration/DomainB/SecurityConfiguration/DomainB/DefaultRealm/myrealm/AuthenticationProviders/DefaultAuthenticator’)
cmo.importData(‘DefaultAtn’,’c:/export.ldif’, Properties())

Example as follows:

To export security data to a file:
  1. In the left pane, select Security Realms and then select the realm whose security data you want to export (for example, myrealm).
  2. Expand Migration > Export.
  3. In the Export Directory on Server field, specify the directory on the Administration Server to which to export the security data.
  4. Click Save.The security data is saved in a file in the location you specified.


    Migrating Data with WLST:

    serverConfig() 

    cd('SecurityConfiguration/mydomain/DefaultR

    ealm/myrealm/path-to-MBean/mbeanname')

    cmo.importData(format,filename,constraints)  



WLST Script to add users, groups and modify roles

connect(‘weblogic’,’weblogic’,’t3://localhost:7001′)
edit()
startEdit(-1,-1,’false’)
serverConfig()
cd(‘/SecurityConfiguration/First_Domain/Realms/myrealm/AuthenticationProviders/DefaultAuthenticator’)
cmo.createUser(‘faisal’,’weblogic’,”)
cmo.groupExists(‘TestGrp’)
cmo.createGroup(‘TestGrp’,”)
cmo.addMemberToGroup(‘testgrp’,’faisal’)
cd(‘/SecurityConfiguration/First_Domain/Realms/myrealm/RoleMappers/XACMLRoleMapper’)
cmo.setRoleExpression(”,’Admin’,’Grp(TestGrp)|Grp(Administrators)’)
edit()
undo(defaultAnswer=’y’, unactivatedChanges=’true’)
stopEdit(‘y’)

Creating Datasource using WLST

connect(‘weblogic’,’weblogic’,’t3://localhost:7001′)
edit()
startEdit()
cd(‘/’)
cmo.createJDBCSystemResource(‘PegaRULES’)
cd(‘/JDBCSystemResources/PegaRULES/JDBCResource/PegaRULES’)
cmo.setName(‘PegaRULES’)
cd(‘/JDBCSystemResources/PegaRULES/JDBCResource/PegaRULES/JDBCDataSourceParams/PegaRULES’)
set(‘JNDINames’,jarray.array([String(‘jdbc/PegaRULES’)], String))
cd(‘/JDBCSystemResources/PegaRULES/JDBCResource/PegaRULES/JDBCDriverParams/PegaRULES’)
cmo.setUrl(‘jdbc:sqlserver://localhost:1433′)
cmo.setDriverName(‘com.microsoft.sqlserver.jdbc.SQLServerDriver’)
cmo.setPassword(‘pega612′)
cd(‘/JDBCSystemResources/PegaRULES/JDBCResource/PegaRULES/JDBCConnectionPoolParams/PegaRULES’)
cmo.setTestTableName(‘SQL SELECT 1\r\n\r\n’)
cd(‘/JDBCSystemResources/PegaRULES/JDBCResource/PegaRULES/JDBCDriverParams/PegaRULES/Properties/PegaRULES’)
cmo.createProperty(‘user’)
cd(‘/JDBCSystemResources/PegaRULES/JDBCResource/PegaRULES/JDBCDriverParams/PegaRULES/Properties/PegaRULES/Properties/user’)
cmo.setValue(‘pega612′)
cd(‘/JDBCSystemResources/PegaRULES/JDBCResource/PegaRULES/JDBCDriverParams/PegaRULES/Properties/PegaRULES’)
cmo.createProperty(‘databaseName’)
cd(‘/JDBCSystemResources/PegaRULES/JDBCResource/PegaRULES/JDBCDriverParams/PegaRULES/Properties/PegaRULES/Properties/databaseName’)
cmo.setValue(‘prpc612′)
cd(‘/JDBCSystemResources/PegaRULES/JDBCResource/PegaRULES/JDBCDataSourceParams/PegaRULES’)
cmo.setGlobalTransactionsProtocol(‘OnePhaseCommit’)
cd(‘/SystemResources/PegaRULES’)
set(‘Targets’,jarray.array([ObjectName(‘com.bea:Name=AdminServer,Type=Server’)], ObjectName))
activate()
dumpStack()
exit()

DISABLING AND ENABLING ADMIN CONSOLE

Disabling your Admin Console:

We can disable our weblogic admin console in two different ways
1)Admin console
2)Weblogic Scripting Tool

From Admin console:-

To disable access to the Administration Console:

After you log in to admin console click Lock & Edit.
In the left pane of the Console, under Domain Structure, select the domain name.
Select Configuration > General, and click Advanced at the bottom of the page.
Deselect Console Enabled.
Click Save.
To activate these changes, click Activate Changes.

From WLST:-

connect(“weblogic“,”weblogic“,”t3://localhost:7001“)
edit()
startEdit()
cmo.setConsoleEnabled(false)
save()
activate()
disconnect()
exit()


Enabling the Admin Console:

After we disable the admin console we can enable it again by using WLST.
Following are the steps on the same:
connect(“weblogic“,”weblogic“,”t3://localhost:7001“)
edit()
startEdit()
cmo.setConsoleEnabled(true)
save()
activate()
disconnect()
exit()


Note: Here,

1)      weblogic and weblogic are the user id and password of admin console.
2)      t3://localhost:7001 is the admin console URL
3)      After we enable/disable the admin console RESTART your admin server