File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

IBatis - using user credentials

 
raghuveer rao
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I was looking to use IBatis in a web app. I would like to run my queries using the credentials of the user logged in. A google on this came up with UserCredentialsDataSourceAdapter in spring. Can you refer me to some sample code on how to configure IBatis with spring. What would you recommed to call the setCredentialsForCurrentThread method.

Do you have any other suggestions to solve this issue.

Thanks

Raghuveer Rao
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"raghuveer_rao@yahoo.com"

Please click on the My Profile link above and change your display name to remove the "@yahoo.com" and remove the "_" to be a blank space between your first and last names. Thanks

Mark
 
Clinton Begin
author
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds like a great question for the Spring support mailing list.

Cheers,
Clinton
 
raghuveer rao
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me rephrase my question
How would you do this?


Raghu
 
Brandon Goodin
author
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following link shows how you would configure the UserCredentialsDataSourceAdapter datasource in spring.

http://www.springframework.org/docs/api/org/springframework/jdbc/datasource/UserCredentialsDataSourceAdapter.html

As far as providing the datasource to iBATIS you would need to do something like. WARNING: THIS IS TOTALLY UNTESTED:

<bean id="myTargetDataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName"><value>java:comp/env/jdbc/myds</value></property>
</bean>

<bean id="dataSource" class="org.springframework.jdbc.datasource.UserCredentialsDataSourceAdapter">
<property name="targetDataSource"><ref bean="myTargetDataSource"/></property>
<property name="username"><value>myusername</value></property>
<property name="password"><value>mypassword</value></property>
</bean>

<bean name="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>

<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation" value="classpath:com/foo/sqlmap/SqlMapConfig.xml"/>
<property name="dataSource" ref="dataSource"/>
<property name="useTransactionAwareDataSource" value="true" />
</bean>

<bean id="sqlMapClientTemplate" class="org.springframework.orm.ibatis.SqlMapClientTemplate">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>

<bean id="myDao" class="com.foo.sqlmap.FooDao">
<property name="sqlMapClient" ref="sqlMapClient"/>
</bean>
 
raghuveer rao
Greenhorn
Posts: 21
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brandon,
I have this part configured rght. My problem is where do I set the user name and password on the datasouce from the user context.
Do I need to set this in a servelet filter. I would personaly like to do this in my service tier. Can AOP help me out there.

Thanks

Raghu
 
Brandon Goodin
author
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This thread appears to provide information about what you are looking for.

http://forum.springframework.org/showthread.php?t=19241

I also googled on UserCredentialsDataSourceAdapter and got quite a few hits.

I would encourage you to post this question to the Spring list.

Hope that helps,
Brandon Goodin
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic