Configure applications for session management in Web modules using scripting

 

+

Search Tips   |   Advanced Search

 

Use scripting and the wsadmin tool to configure applications for session management in Web modules.

Before starting this task, the wsadmin tool must be running. See the Start the wsadmin scripting client article for more information.

 

Overview

You can use the AdminApp object to set configurations in an application. Some configuration settings are not available through the AdminApp object.

The following task uses the AdminConfig object to configure a session manager for a Web module in the application.

 

Procedure

  1. Identify the deployment configuration object for the application and assign it to the deployment variable...

    • Use Jacl:

      set deployments [$AdminConfig getid /Deployment:myApp/]

    • Use Jython:

      deployments = AdminConfig.getid('/Deployment:myApp/') print deployments

    Example output:

    myApp(cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#Deployment_1)
    

  2. Get all the modules in the application and assign them to the modules variable....

    • Use Jacl:

      set appDeploy [$AdminConfig showAttribute $deployments deployedObject]
      set mod1 [$AdminConfig showAttribute $appDeploy modules]
      Example output:

      (cells/mycell/applications/myApp.ear/deployments/myApp:deployment.xml#WebModuleDeployment_1) (cells/mycell/applications/myApp.ear/deployments/myApp:deployment.xml#EJBModuleDeployment_1) (cells/mycell/applications/myApp.ear/deployments/myApp:deployment.xml#WebModuleDeployment_2)
      

    • Use Jython:

      appDeploy = AdminConfig.showAttribute(deployments, 'deployedObject')
      mod1 = AdminConfig.showAttribute(appDeploy, 'modules') print mod1
      Example output:

      [(cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#WebModuleDeployment_1)  (cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#EJBModuleDeployment_1) (cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#EJBModuleDeployment_2)]
      

  3. To obtain a list of attributes that you can set for a session manager, use the attributes command....

    • Use Jacl:

      $AdminConfig attributes SessionManager

    • Use Jython:

      print AdminConfig.attributes('SessionManager')

    Example output:

    "accessSessionOnTimeout Boolean"
    "allowSerializedSessionAccess Boolean"
    "context ServiceContext@"
    "defaultCookieSettings Cookie"
    "enable Boolean"
    "enableCookies Boolean"
    "enableProtocolSwitchRewriting Boolean"
    "enableSSLTracking Boolean"
    "enableSecurityIntegration Boolean"
    "enableUrlRewriting Boolean"
    "maxWaitTime Integer"
    "properties Property(TypedProperty)*"
    "sessionDRSPersistence DRSSettings"
    "sessionDatabasePersistence SessionDatabasePersistence"
    "sessionPersistenceMode ENUM(DATABASE, DATA_REPLICATION, NONE)"
    "tuningParams TuningParams"
    

  4. Set up the attributes for session manager.

    The following example sets four top-level attributes in the session manager. You can modify the example to set other attributes in the session manager, including the nested attributes in Cookie, DRSSettings, SessionDataPersistence, and TuningParms object types. To list the attributes for those object types, use the attributes command of AdminConfig object.

    • Use Jacl:

      set attr0 [list enable true]
      set attr1 [list enableSecurityIntegration true]
      set attr2 [list maxWaitTime 30]
      set attr3 [list sessionPersistenceMode NONE]
      set attr4 [list enableCookies true]
      set attr5 [list invalidationTimeout 45]
      set tuningParmsDetailList [list $attr5]
      set tuningParamsList [list tuningParams $tuningParmsDetailList]
      set pwdList [list password 95ee608]
      set userList [list userId Administrator]
      set dsNameList [list datasourceJNDIName jdbc/session]
      set dbPersistenceList [list $dsNameList $userList $pwdList]
      set sessionDBPersistenceList [list $dbPersistenceList]
      set sessionDBPersistenceList [list sessionDatabasePersistence $dbPersistenceList]
      set kuki [list maximumAge 1000]
      set cookie [list $kuki]
      set cookieSettings [list defaultCookieSettings $cookie]
      set sessionManagerDetailList [list $attr0 $attr1 $attr2 $attr3 $attr4 $cookieSettings
      $tuningParamsList $sessionDBPersistenceList]
      set sessionMgr [list sessionManagement $sessionManagerDetailList]
      set id [$AdminConfig create ApplicationConfig $appDeploy [list $sessionMgr] configs]
      set targetMappings [lindex [$AdminConfig showAttribute $appDeploy targetMappings] 0]
      set attrs [list config $id]
      $AdminConfig modify $targetMappings [list $attrs]
      Example output using Jacl:

      sessionManagement {{enableSecurityIntegration true} {maxWaitTime 30} 
      {sessionPersistenceMode NONE} {enabled true}}
      

    • Use Jython:


      attr0 = ['enable', 'true']
      attr1 = ['enableSecurityIntegration', 'true']
      attr2 = ['maxWaitTime', 30]
      attr3 = ['sessionPersistenceMode', 'NONE']
      attr4 = ['enableCookies', 'true']
      attr5 = ['invalidationTimeout', 45]

      tuningParmsDetailList = [attr5]
      tuningParamsList = ['tuningParams', tuningParmsDetailList]
      pwdList = ['password', '95ee608']
      userList = ['userId', 'Administrator']
      dsNameList = ['datasourceJNDIName', 'jdbc/session']
      dbPersistenceList = [dsNameList, userList, pwdList]
      sessionDBPersistenceList = [dbPersistenceList]
      sessionDBPersistenceList = ['sessionDatabasePersistence', dbPersistenceList]
      kuki = ['maximumAge', 1000]
      cookie = [kuki]
      cookieSettings = ['defaultCookieSettings', cookie]

      sessionManagerDetailList = [attr0, attr1, attr2, attr3, attr4, cookieSettings, tuningParamsList, sessionDBPersistenceList]

      sessionMgr = ['sessionManagement', sessionManagerDetailList]

      id = AdminConfig.create('ApplicationConfig', appDeploy,[sessionMgr], 'configs')
      targetMappings = AdminConfig.showAttribute(appDeploy, 'targetMappings')
      targetMappings = targetMappings[1:len(targetMappings)-1]
      print targetMappings
      attrs = ['config', id]
      AdminConfig.modify(targetMappings,[attrs])

      Example output using Jython:

      [sessionManagement, [[enableSecurityIntegration, true], [maxWaitTime, 30], [sessionPersistenceMode, NONE]]
      

  5. Set up the attributes for the Web module...

    • Use Jacl:

      set nameAttr [list name myWebModuleConfig]
      set descAttr [list description "Web Module config post create"]
      set webAttrs [list $nameAttr $descAttr $sessionMgr]
      Example output:

      {name myWebModuleConfig} {description {Web Module config post create}} 
      {sessionManagement {{enableSecurityIntegration true} {maxWaitTime 30} 
      {sessionPersistenceMode NONE} {enabled true}}}
      
      

    • Use Jython:

      nameAttr = ['name', 'myWebModuleConfig']
      descAttr = ['description', "Web Module config post create"]
      webAttrs = [nameAttr, descAttr, sessionMgr]
      Example output:

      [[name, myWebModuleConfig], [description, "Web Module config post create"], 
      [sessionManagement, [[enableSecurityIntegration, true], [maxWaitTime, 30],  
      [sessionPersistenceMode, NONE], [enabled, true]]]]
      

  6. Create the session manager for each Web module in the application. You can modify the following example to set other attributes of the session manager in a Web module configuration. You must also define a target mapping for this step.

    • Use Jacl:

       foreach module $modules {
        if {[regexp WebModuleDeployment $module]  == 1} {
          $AdminConfig create WebModuleConfig $module $webAttrs
          set targetMappings  lindex  $AdminConfig showAttribute $module targetMappings  0
          set attrs  list config $moduleConfig
          $AdminConfig modify $targetMappings  list $attrs
        }
      }
      

    • Use Jython:

      arrayModules = mod1[1:len(mod1)-1].split(" ") for module in arrayModules:
        if module.find('WebModuleDeployment') != -1:
          AdminConfig.create('WebModuleConfig', module, webAttrs)
          targetMappings = targetMappings[1:len(targetMappings)-1]
          attrs = ['config', moduleConfig]
          AdminConfig.modify (targetMappings, [attrs])
      

    Example output:

    myWebModuleConfig(cells/mycell/applications/myApp.ear/deployments/myApp|deployment.xml#WebModuleConfiguration_1)
    

    If you do not specify the tuningParamsList attribute when you create the session manager, you will receive an error when you start the deployed application.

  7. Save the configuration changes. See the Saving configuration changes with the wsadmin tool article for more information.

  8. In a network deployment environment only, synchronize the node. See the Synchronizing nodes with the wsadmin tool article for more information.