How to change datasource's usename and password in a CMP contain

Discussions

EJB programming & troubleshooting: How to change datasource's usename and password in a CMP contain

  1. hi all

    I'm working in a CMP project on IBM WebSphere App. Server and WebSphere Studio App. Developer.

    As you know when we work with CMP beans the container manage all resources including datasource connections, but in order to maintain my security profile (you know.. client requirements...!!), I need to specify different values for datasource's username and password.

    (each user will connect with his own database username and password. It can't be a generic database user)

    Is possible change the datasource parameters in run time to my CMP container ? or it only works with the values that I set it in the general container configuration.

    thanks in advance
  2. Have you tried not defining the username and password in the configuration, and instead having the app use the getConnection(String username, String password) method?
  3. I think that you wrote me about a code like this:

    --------------------------
    DatabaseResources dbResources = DatabaseResources.getInstance() ;
    DataSource dataSource = dbResources.getDataSource() ;
    connection = dataSource.getConnection( userID, password ) ;
    -------------------------

    but, did you used this code with CMP beans ?
    thanks for advise me
  4. Differentiating users[ Go to top ]

    Can't use this type of code with a CMP. The container is responsible for obtaining and managing the data source connection. To utilize this style of programming you need to switch to a BMP.

    Why can't you allow the container to utilize a generic connection and configure the EJB's security to identify individual users?
  5. Differentiating users[ Go to top ]

    Admittedly I haven't tesed this at all, but I was thinking more along the lines of having the bean get a new connection...perhaps something like:

    InitialContext ctx = new InitialContext();
    DataSource dataSource = (DataSource)ctx.lookup(jndiName);
    Connection con = dataSource.getConnection(username, password);

    // use the connection

    con.close();