Announcement Announcement Module
Collapse
No announcement yet.
Connection DataSource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Connection DataSource

    I'm new in Spring.
    I'm building a sample web application for testing this framework.
    I have a issue:
    my application start with a web form Login (implemented with JSF, but i think this is not very important for issue)
    and I want to access a database datas (for example a Firebird database).
    I saw in most example a configuration of this type for data access:

    Code:
      <bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
          <list>
            <value>WEB-INF/masterdoc.properties</value>
            <value>WEB-INF/jdbc.properties</value>
          </list>
        </property>
      </bean>
    
      <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName"><value>$&#123;jdbc.driverClassName&#125;</value></property>
        <property name="url"><value>$&#123;jdbc.url&#125;</value></property>
        <property name="username"><value>$&#123;jdbc.username&#125;</value></property> 
        <property name="password"><value>$&#123;jdbc.password&#125;</value></property>
      </bean>
    The properties username and password are fixed (although I use a file properties).
    How can make Login with dinamical userId and password of DataSource?
    ApplicationContext is initialized at start of my Tomcat, while I would want dinamical userid and password
    for all my access data.
    A poor solution could be passing password and userId as parameter in this fashion:

    Code:
    public class myDAOJdbc implements myDAOInterface&#123;
    
      private DataSource datasource;
    
      public void setDatasource&#40;DataSource datasource&#41; &#123;
            this.datasource = datasource;
      &#125;
    
      public List getData&#40;String userId, String password&#41; &#123;
        datasource.setUsername&#40;userId&#41;;
        datasource.setPassword&#40;password&#41;;
        JdbcTemplate jt = new JdbcTemplate&#40;datasource&#41;;
        
        ....
        ....
        return "some List";
      &#125;
    
    &#125;
    but don't like it too much. I wouldn't parameters.
    I wish I can to config my Applicationcontext after my first Login operation with current
    inserted userid and password of dataSource.
    Someone have better ideas?
    Thanks very much for any feedback.
    Andrea

  • #2
    Where do the username and password come from? How are they known?

    Comment


    • #3
      In my application username and password are insert by the user through
      two input text in a jsf login page.
      But I think they could come from anywhere outside my applicationContext.
      Is possibile, after this autentication, the subsequent jsf pages access to database through
      applicationContext with the datasource username and password inserted?
      They are the username and password of DBMS.

      Comment

      Working...
      X