aspose file tools*
The moose likes Object Relational Mapping and the fly likes IBatis - using user credentials Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "IBatis - using user credentials" Watch "IBatis - using user credentials" New topic
Author

IBatis - using user credentials

raghuveer rao
Greenhorn

Joined: Oct 09, 2002
Posts: 21
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

Joined: Feb 05, 2001
Posts: 17249
    
    6

"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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Clinton Begin
author
Greenhorn

Joined: Nov 08, 2006
Posts: 21
That sounds like a great question for the Spring support mailing list.

Cheers,
Clinton
raghuveer rao
Greenhorn

Joined: Oct 09, 2002
Posts: 21
Let me rephrase my question
How would you do this?


Raghu
Brandon Goodin
author
Greenhorn

Joined: Nov 08, 2006
Posts: 14
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>


Brandon Goodin<br />Independent Consultant<br /><a href="http://www.silvermindsoftware.com" target="_blank" rel="nofollow">http://www.silvermindsoftware.com</a>
raghuveer rao
Greenhorn

Joined: Oct 09, 2002
Posts: 21
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

Joined: Nov 08, 2006
Posts: 14
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IBatis - using user credentials
 
Similar Threads
Implementing Persistance with Spring
iBattis with multiple data sources.
Ibatis + SQLMAP
Future industry direction?
How to get error codes using java program