4 Replies Latest reply on Aug 21, 2017 12:11 PM by nitin gautam

    Data source configuration during runtime

    Grzegorz Gwoźdź Newbie

      Hi everyone. I need to implement a solution that would enable me to change data source configuration during runtime. There is a system A that admins have access to and whre they put configuration for stuff, including db configuration. You can think of it as "Configuration Central".

       

      Component in another system - lets call it B - periodically reads that configuration. When configuration in A changes, system B detects that change and updets itself. I need to implement a solution that would enable me to change datasource configuration on the fly to use new configuration from system A without a need to restart the jboss.

       

      Conenction URL change

       

      I am able to change the connection url infollowing way...

      1. DataSource has few underlying components (MBeans). One of them is ManagedConnectionFactory.
      2. I do a JNDI lookup on this one, then cast it to org.jboss.resource.connectionmanager.RARDeploymentMBean to have access to properties
      3. I use RARDeploymentMBean#setManagedConnectionFactoryAttribute(arg0, arg1, arg2) to set the url

      Looks good so far.

       

      Credentials switch

       

      Then I need to update the the credentials - username and password. There is a component named org.jboss.security.auth.login.DynamicLoginConfig with a parameter AuthConfig that points to a file that stores various policies conatining username and password. Here is an abstract from this file:

        <application-policy name="MyName_LoginDomain">
          <authentication>
            <login-module code="org.jboss.resource.security.SecureIdentityLoginModule" flag="required">
          <module-option name="username">username</module-option>
          <module-option name="password">password</module-option>
          <module-option name="managedConnectionFactoryName">jboss.jca:service=LocalTxCM,name=MyName_DS</module-option>
            </login-module>
          </authentication>
        </application-policy>

       

      I also found that each datasource has a ConnectionManager attribute, and this connection manager could also be found using JNDI lookup. It has an attribute called SecurityDomainJndiName with value of MyName_LoginDomain. Using this one I could switch between predefined LoginDomain as I like to call them. Those are in fact instances of org.jboss.security.plugins.SecurityDomainContext.

       

      Problem

      Admins switch data base to which in system A  to which system B should connect. I change te url, then I switch to correct SecurityDomainContext and that is fine. However when database username or password changes I have no idea what to do other than updating the file pointed by DynamicLoginConfig.AuthConfig and restarting jboss after it. Is there any way to change username and password associated with given SecurityDomainContext during runtime?

       

      Sorry for such a large post, but I wanted to describe the whole problem to be clear. If you need any addtional information so that we could think it out together just let me know. Thanks a lot for any help!