Windows Vista Forums
Vista Forums Home Join Vista Forums Donate Vista Tutorials Tags

Welcome to Vista Forums we are your forum to discuss Windows Vista x64 and x86 systems. Whether you need help or just want to post an idea you have on Vista, this is the forum for you.
Register at Vista forums...the world biggest Windows Vista resource Join Vista Forums Now

Go Back   Vista Forums > Microsoft Technical Newsgroups > Indigo

CustomValidator and CustomIPrincipal

 
 
Thread Tools Display Modes
Old 04-26-2007   #1 (permalink)
Jay Allard
Guest


 

CustomValidator and CustomIPrincipal

Greetings

I need to be able to:
- validate credentials against our own store (done)
- create an existing user object based on the store (done)
- create a custom Identity with an extra property that contains the user
object. (done)

I can do all three of those steps individually, but I'm having trouble with
some WCF implementation details. Where do I do which step?

I've been all over google and have found a lot of good information for this,
but a lot of it is from pre-release and doesn't necessarily apply anymore. I
also found this excellent post:

http://groups.google.co.uk/group/mic...40905d321cce17


When the CustomValidator is called, I have what I need (username and
password) to recreate our user object. However, I can't set the thread
principal or PrimaryPrincipal at that point because, apparently, that's not
the thread that the service method executes on. (Additionally, I don't see
how to set the PrimaryPrincipal yet. I saw examples using a properties
collection, but those were pre release and have notes that say they won't
work any more). I'd prefer to use the thread principal because that would
allow it to play well with the other kids.

Based on reading, it seems the place to set the principal is in the
Authorization Policy, but at that point I don't have the username and
password so I can't create the object.

If that strategy is correct, then how do I persiste an object between the
CustomValidator to the Authorization Policy?

I'm using the "Programming WCF Services" book, which is good. Any
recommendations for another good one?

Thanks in advance for your help.
Jay

Old 04-26-2007   #2 (permalink)
Jay Allard
Guest


 

Re: CustomValidator and CustomIPrincipal

Correction: I see now that CustomValidator does execute in the same thread
as the service method. However, the principal I set in the validator is
overwritten by a windows principal by the time it gets to the methods.


"Jay Allard" <jay@allardworks.com> wrote in message
news:7cudnZXVes5rYa3bnZ2dnUVZ_hKdnZ2d@adelphia.com...
> Greetings
>
> I need to be able to:
> - validate credentials against our own store (done)
> - create an existing user object based on the store (done)
> - create a custom Identity with an extra property that contains the user
> object. (done)
>
> I can do all three of those steps individually, but I'm having trouble
> with some WCF implementation details. Where do I do which step?
>
> I've been all over google and have found a lot of good information for
> this, but a lot of it is from pre-release and doesn't necessarily apply
> anymore. I also found this excellent post:
>
> http://groups.google.co.uk/group/mic...40905d321cce17
>
>
> When the CustomValidator is called, I have what I need (username and
> password) to recreate our user object. However, I can't set the thread
> principal or PrimaryPrincipal at that point because, apparently, that's
> not the thread that the service method executes on. (Additionally, I don't
> see how to set the PrimaryPrincipal yet. I saw examples using a properties
> collection, but those were pre release and have notes that say they won't
> work any more). I'd prefer to use the thread principal because that would
> allow it to play well with the other kids.
>
> Based on reading, it seems the place to set the principal is in the
> Authorization Policy, but at that point I don't have the username and
> password so I can't create the object.
>
> If that strategy is correct, then how do I persiste an object between the
> CustomValidator to the Authorization Policy?
>
> I'm using the "Programming WCF Services" book, which is good. Any
> recommendations for another good one?
>
> Thanks in advance for your help.
> Jay
>


Old 04-26-2007   #3 (permalink)
marc.gravell@gmail.com
Guest


 

Re: CustomValidator and CustomIPrincipal

In the validator you have access to name and password for the purposes
of authentication
In the authorization policy you have access to the name (but not
password) for the purpose of creating a custom principal; look for an
"Identities" property on the evaluation context, and enumerate each;
one of them will be authenticated and will have an authentication type
of your validator; from the name you should be able to construct a new
principal with the roles and assign the Principal property. Something
like:

bool IAuthorizationPolicy.Evaluate(EvaluationContext
evaluationContext, ref object state)
{
IList<IIdentity> idents;
object identsObject;
if
(evaluationContext.Properties.TryGetValue("Identities", out
identsObject) && (idents = identsObject as IList<IIdentity>) != null)
{
foreach (IIdentity ident in idents)
{
if (ident.IsAuthenticated &&
ident.AuthenticationType == MyTrustedAuthType)
{
evaluationContext.Properties["Principal"]
= {new principal from ident.Name}
return true; // we're done
}
}
}
if (!
evaluationContext.Properties.ContainsKey("Principal"))
{
evaluationContext.Properties["Principal"] = Anon;
}
return false; // keep trying

}

Old 04-27-2007   #4 (permalink)
JayA
Guest


 

Re: CustomValidator and CustomIPrincipal

That worked great. Thanks for your help.

Stay tuned. I'm sure I'll be back.

Jay


<marc.gravell@gmail.com> wrote in message
news:1177630355.104557.128830@b40g2000prd.googlegroups.com...
> In the validator you have access to name and password for the purposes
> of authentication
> In the authorization policy you have access to the name (but not
> password) for the purpose of creating a custom principal; look for an
> "Identities" property on the evaluation context, and enumerate each;
> one of them will be authenticated and will have an authentication type
> of your validator; from the name you should be able to construct a new
> principal with the roles and assign the Principal property. Something
> like:
>
> bool IAuthorizationPolicy.Evaluate(EvaluationContext
> evaluationContext, ref object state)
> {
> IList<IIdentity> idents;
> object identsObject;
> if
> (evaluationContext.Properties.TryGetValue("Identities", out
> identsObject) && (idents = identsObject as IList<IIdentity>) != null)
> {
> foreach (IIdentity ident in idents)
> {
> if (ident.IsAuthenticated &&
> ident.AuthenticationType == MyTrustedAuthType)
> {
> evaluationContext.Properties["Principal"]
> = {new principal from ident.Name}
> return true; // we're done
> }
> }
> }
> if (!
> evaluationContext.Properties.ContainsKey("Principal"))
> {
> evaluationContext.Properties["Principal"] = Anon;
> }
> return false; // keep trying
>
> }
>


 

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
CustomValidator in GridView getting "no message" on errors doug .NET General 4 03-16-2008 08:05 PM








Vistax64.com is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media 2005-2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50