PDA

View Full Version : setting thread credentials


si_lance
05-08-2007, 01:09 AM
Has anyone used AOP to set the credentials for a thread attempting database access via a DAO? This is for row-level (vpd) security. Thanks. :)

In Java Spring, one would use UserCredentialsDataSourceAdapter and use the MethodInterceptor interface. Implementing something like this:

public Object invoke(MethodInvocation i) throws Throwable {

// get credentials from secure context
String[] credentials = ... ommitted ...
credentialsDataSourceAdapter.setCredentialsForCurr entThread(credentials[0], credentials[1]);

Object ret=i.proceed();
credentialsDataSourceAdapter.removeCredentialsFrom CurrentThread();
return ret;
}


Is there an equivalent in Spring.NET?

Erich Eichinger
05-21-2007, 12:34 AM
Hi,

No - there is no equivalent yet. And I doubt that this is an easy one to solve when using connectionstrings and database users due to connection pooling. But if you are using "Integrated Security" mode, you may use the code attached to my post.


public Object Invoke(MethodInvocation i)
{

// get credentials from secure context
String[] credentials = ... ommitted ...

using( new Impersonation(user,password,domain) )
{
Object ret=i.proceed();
return ret;
}
}


-Erich