9 Replies Latest reply on Apr 21, 2010 9:12 AM by 765582

    How to pass the encrypted DB pwd in python script

    765582
      Hi,

      I am trying to configure a domain using the python script.

      The script looks like as follows:

      cd('JDBCSystemResource/MYConnectionPool/JdbcResource/MyConnectionPool')
      create('myJdbcDriverParams','JDBCDriverParams')
      cd('JDBCDriverParams/NO_NAME_0')
      set('DriverName','oracle.jdbc.OracleDriver')
      set('URL',os.environ['DATASERVER_DB_URL'])
      set('PasswordEncrypted', 'user1')

      I am hardcoding the password as "user1" in the script. Whereas I dont want to hardcode the password in the script as it might be different in production environment.

      I wish to encrypt the pwd and place in some file and give the file reference here in the script. That file's reference can be stored as an env variable and then passed to the script as follows-

      set('PasswordEncrypted', os.environ['DATASERVER_DB_PWD'])

      Can someone help me to know how can I encrypt the pwd and how can I pass that to the python script.

      Thanks,
      Shalini
        • 1. Re: How to pass the encrypted DB pwd in python script
          Jay SenSharma MiddlewareMagic
          Hi Shalini,

          Please use this to encrypt the DataBase password.:

          <font color=maroon>Step1).</font> run the "setDomainEnv.sh" in the command Shell.

          <font color=maroon>Step2).</font> Run the following command to encrypt the Password of the DataSource.
          *java weblogic.security.Encrypt ${Clear_Text_Password}*

          Example:
          $ encrypt_password.ksh weblogic
          {3DES}0HYiEySifDiz0IcqDhelGA==

          <font color=maroon>Step3).</font> Now paste the above Encrypted value in a Text File somewhere: "dBpassword.properties"
          password={3DES}0HYiEySifDiz0IcqDhelGA==

          <font color=maroon>Step4).</font> Now in your WLST script write the code somewhere to read the File Data:


          from java.io import FileInputStream
          propInputStream = FileInputStream("dBpassword.properties")
          configProps = Properties()
          configProps.load(propInputStream)
          passwordEncrypted = configProps.get("password")


          <font color=maroon>Step5).</font> Edit your existing WLST by adding the Password there.

          from java.io import FileInputStream
          propInputStream = FileInputStream("dBpassword.properties")
          configProps = Properties()
          configProps.load(propInputStream)
          <font color=green>passwordEncrypted = configProps.get("password")</font><BR>


          cd('JDBCSystemResource/MYConnectionPool/JdbcResource/MyConnectionPool')
          create('myJdbcDriverParams','JDBCDriverParams')
          cd('JDBCDriverParams/NO_NAME_0')
          set('DriverName','oracle.jdbc.OracleDriver')
          set('URL','yourDBURL')
          <font color=green>set('PasswordEncrypted',passwordEncrypted )</font><BR>
          .
          .
          Thanks
          Jay SenSharma
          http://jaysensharma.wordpress.com (WebLogic Wonders Are Here)
          1 person found this helpful
          • 2. Re: How to pass the encrypted DB pwd in python script
            765582
            Thanks Jay for the quick reply. I have another question too regarding the following statement -

            set('PasswordEncrypted', 'user1')

            When I use the option "PasswordEncrypted" in the set(....) function, does the password "user1" get encrypted and then stored ? If yes, then if I am passing the encrypted password then how will I ensure that the password is set in the form I am passing as.

            Thanks,
            Shalini
            • 3. Re: How to pass the encrypted DB pwd in python script
              Jay SenSharma MiddlewareMagic
              Actually I have never done it...earlier.
              Let me try that once.
              • 4. Re: How to pass the encrypted DB pwd in python script
                Jay SenSharma MiddlewareMagic
                Yes It Works:


                C:\bea103\user_projects\domains\base_domain\bin>setDomainEnv.cmd
                <font color=maroon>C:\bea103\user_projects\domains\base_domain>java weblogic.security.Encrypt PBPUBLIC
                *{3DES}IQHx+vYPxQI5k1W1Dbwubw==* </font>


                ---------------------------------------------CreateDS.py----------------------------------------------------
                import sys
                from java.lang import System
                print "@@@ Starting the script ..."
                url = 't3://localhost:7001'
                usr = 'weblogic'
                password = 'weblogic'
                connect(usr,password, url)

                edit()
                startEdit()

                print("----------------------------1")
                print("*** Creating JDBC DataSource ")
                myResourceName = *"TestDSA"*
                print("Here is the Resource Name: " + myResourceName)
                print("----------------------------2")
                jdbcSystemResource = create(myResourceName,"JDBCSystemResource")
                myFile = "TestDSA.xml"
                print ("HERE IS THE JDBC FILE NAME: " + myFile)
                jdbcResource = jdbcSystemResource.getJDBCResource()
                jdbcResource.setName("<b>MyJdbcResource</b>")
                print("----------------------------3")
                # Create the DataSource Params
                dpBean = jdbcResource.getJDBCDataSourceParams()
                myName="MyJNDINameA"
                dpBean.setJNDINames([myName])
                print("----------------------------4")
                # Create the Driver Params
                drBean = jdbcResource.getJDBCDriverParams()
                <font color=maroon><b>drBean.setPassword("{3DES}IQHx+vYPxQI5k1W1Dbwubw==")</b></font><BR>
                drBean.setUrl("jdbc:pointbase:server://localhost/demo")
                drBean.setDriverName("com.pointbase.jdbc.jdbcUniversalDriver")
                print("----------------------------5")
                propBean = drBean.getProperties()
                driverProps = Properties()
                driverProps.setProperty("user","PBPUBLIC")
                print("----------------------------6")
                e = driverProps.propertyNames()
                while e.hasMoreElements() :
                     propName = e.nextElement()
                     myBean = propBean.createProperty(propName)
                     myBean.setValue(driverProps.getProperty(propName))
                print("----------------------------7")
                save()
                activate()
                -------------------------------------------------------------------------------------------------

                Now after running the CreateDB.py script when i checked the DataSource XML File

                <?xml version='1.0' encoding='UTF-8'?>
                <jdbc-data-source xmlns="http://www.bea.com/ns/weblogic/jdbc-data-source" xmlns:sec="http://www.bea.com/ns/weblogic/90/security" xmlns:wls="http://www.bea.com/ns/weblogic/90/security/wls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/jdbc-data-source http://www.bea.com/ns/weblogic/jdbc-data-source/1.0/jdbc-data-source.xsd">
                <name>MyJdbcResource</name>
                <jdbc-driver-params>
                <url>jdbc:pointbase:server://localhost/demo</url>
                <driver-name>com.pointbase.jdbc.jdbcUniversalDriver</driver-name>
                <properties>
                <property>
                <name>user</name>
                <value>PBPUBLIC</value>
                </property>
                </properties>
                <font color=maroon><b> <password-encrypted>{3DES}IQHx+vYPxQI5k1W1Dbwubw==</password-encrypted> </b></font><BR>
                </jdbc-driver-params>
                <jdbc-data-source-params>
                <jndi-name>MyJNDINameA</jndi-name>
                </jdbc-data-source-params>
                </jdbc-data-source>

                .
                .
                Thanks
                Jay SenSharma
                http://jaysensharma.wordpress.com (WebLogic Wonders Are Here)
                1 person found this helpful
                • 5. Re: How to pass the encrypted DB pwd in python script
                  765582
                  I tried using setPassword(), but its not working for me.

                  Error thrown -
                  Caused by: com.bea.plateng.domain.script.ScriptException: Unable to find attribute Password

                       at co m.bea.plateng.domain.script.ScriptExecutor.setAttrValue(ScriptExecutor.java:3353)

                       at com.bea.plateng.domain.script.ScriptExecutor.setValue(ScriptExecutor.java:1152)

                       at com.bea.plateng.domain.script.jython.ScriptInvocationHandler.set(ScriptInvocationHandler.java:208)

                       at com.bea.plateng.domain.script.jython.ScriptInvocationHandler.invoke(ScriptInvocationHandler.java:101)

                       ... 21 more

                  I am using weblogic 9.4.2 , Is it smthg like setPassword(...) is not supported in this version of weblogic ?

                  Can you point me to the location where I can download the list of supported attributes by various versions of weblogic.

                  Thanks in advance,
                  Shalini
                  • 6. Re: How to pass the encrypted DB pwd in python script
                    Jay SenSharma MiddlewareMagic
                    Weblogic 9.4.2 was never released.

                    Please run the followng command in the command prompt to knwo the exact version of WLS (After running setWLSEnv.sh or setDomainEnv.sh)

                    java weblogic.version

                    I tried it in WLS10.3, The WLST script which i posted in my previous post. Let me check it in WLS9.2 as well ...

                    Can u please post your Script once again which is giving this error "setPassword" one...May be something is missing there.
                    Can u please try the Script which i Posted...Just incase if your script is causing any issue....(For testing purpose)


                    .
                    .
                    Thanks
                    Jay SenSharma
                    1 person found this helpful
                    • 7. Re: How to pass the encrypted DB pwd in python script
                      765582
                      I executed the script provided by you and it works, didn't get any errors in weblogic 9.2.

                      But when I checked from the console, the password field had blank value.
                      • 8. Re: How to pass the encrypted DB pwd in python script
                        Jay SenSharma MiddlewareMagic
                        Hi,

                        <font color=RED><b>NOTE: If you enter a Wrong Encrypted Password in the WLST script ...then It will not be visible in the AdminConsole...</b></font><BR>

                        I understood what mistake you did. You might have directly Pasted My WLST script in your Machine and Didnot replace the Encrypted pssword (Or may be some Wrong Characters got included in the Encrypted password while replacing it in the WLST script ) with your own encrypted value...thats why you dont see any Password in the Password TextField.. I m able to reproduce the same thing at my end ...with the same mistake.

                        Please try this...

                        <font color=maroon><b>Step1).</b></font> Open a Shell Prompt...

                        <font color=maroon><b>Step2).</b></font> Move inside your Domain Root directory and then run *"setDomainEnv.sh"*
                        Example:
                        C:\bea\user_projects\domains\base_domain\bin

                        <font color=maroon><b>Step3).</b></font> run the following command from your Domain Root Directory:

                        Example:
                        C:\bea\user_projects\domains\base_domain>java weblogic.security.Encrypt PBPUBLIC
                        {3DES}4NT9WiBG7MXYBiEteLogvA==

                        <font color=maroon><b>Step4).</b></font> Now replace this Encrypted Value in My WLST script ...

                        <font color=maroon><b>Step5).</b></font> Now Run the WLST Script to create the dataSource.


                        .
                        .
                        Thanks
                        Jay SenSharma