In the PT, there are two class about security, which are Principal.cs and Identity.cs.
And to deal with your problem, you just need to call the Login or Logout method of Principal class.
public static bool Login(string username, string password)
{}
public static void Logout()
{}
Diz:I keep reading that by default WCF will pass the windows identity, but no combination of my experimenting has actually allowed this to happen.
That is true (sort of), but only when you host in IIS or WAS. If you host in your own custom process then you assume responsibility for things like impersonation and identity management - at least that's my understanding.
If you are using a custom CSLA principal, then the data portal will take care of the principal for you - but you'll still need to make sure your WCF host accepts requests without trying to do Windows impersonation - which probably requires some extra WCF configuration.
In my experience even hosting in IIS or WAS typically requires extra WCF configuration too. Rarely can you get away with the default WCF settings in a real app.
And you are right, nothing with WCF comes easy...
We are using a framework wrapping CSLA in my company. Until recently, in most projects the server was hosted in IIS. I have built a new solution and am hosting this in a windows service. In order to provide logging by the server, I need to obtain the windows login of the user and use in the database fetch method.
We were using the ApplicationContext to return the user ID, this now has the account info for the IIS account, not the actual user.
We are using basicHttpBinding and I have the credentials set up and working in a test project. This involves using [(ServiceBehaviour(InstanceContextMode = InstanceContectMode.PerCall)] and [OperationBehaviour(Impersonation = ImpersonationOption.Required)] around the methods.
What I need to be able to do, it get this working with CSLA, but am unsure how to do this.
ApplicationContext.User returns the current .NET principal. That’s
all it does.
So if you are using Windows security (and it sounds like you
are) then it is up to the server host (typically IIS) to impersonate the
caller. If you are running in a custom Windows service then you will have to
make your service do the impersonation – unless you can get WCF to do it
for you, but I don’t know if that is possible.
This sounds like a pretty advanced scenario – with luck
you can get some information from MSDN or either Juval or Michelle’s
books in terms of how to implement impersonation with WCF in a custom Windows
service.
Rocky
Thanks for the reply. I can get WCF to do it, can send you code if you want?
It easy for me to do it if I have full control over the operations contracts, but the way we are using the CSLA / IWcfPortal means that I haven't got control of the operations contracts. These are in the IWcfPortal.cs. I am wondering if I just wrap these methods with the impersonation operation contract specifics, it may just work. This will be nicer solution than me having to change the code to have to pass the user name.
The data portal is flexible, specifically to accommodate scenarios
where people have needs beyond the basic ones provided by the standard data
portal channels provided with CSLA.
In other words, you can create your own client-side proxy and
server-side host classes and plug them into the data portal. This is not hard
to do. Look at Chapter 5 in the Expert 2005 Business Objects book, or
better at the CSLA .NET Version 2.1 Handbook to see how a proxy/host is
created. You can take the existing WCF proxy/host classes and copy them into
your own project, modify them and tell CSLA to use them.
Rocky
From: DazedAndConfused
[mailto:cslanet@lhotka.net]
Sent: Monday, May 19, 2008 10:39 AM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] RE: WCF Data Portal and Identity Management
Thanks for the reply. I can get WCF to do it, can send you code if you want?
It easy for me to do it if I have full control over the operations
contracts, but the way we are using the CSLA / IWcfPortal means that I haven't
got control of the operations contracts. These are in the IWcfPortal.cs. I am
wondering if I just wrap these methods with the impersonation operation
contract specifics, it may just work. This will be nicer solution than me
having to change the code to have to pass the user name.
Copyright (c) Marimer LLC