c# - What is GenericIdentity? -


Can someone briefly tell out what is the use of generic identity and who to use it.

>

Jenerikaidentiti and GenericPrincipal to a user The easiest way to describe as "principal" is. This can be used to perform an unknown security check in an implementation - that means the user logs in as "Fred" with "user" and "administrator" permissions:

  string [ ] Roles = {"user", "admin"}; Thread Contint Principal = New Generic Principal (New Genericity ("Fred"), roles);  

You can do this on a formform at the time of client login or there are specific points to do this in WCF, ASP.NET, etc.

Then in the code, how can control those permissions, check that permission - either, or declaratively:

  [PrincipalPermission (SecurityAction.Demand, Role = "Admin")] minus a few admin function () {}  

the zero-safe around some useful utility code origin / identity The wrapper is:

  public static string GetUsername () {IPRinal Principal = Thread. Current Principal; IIdentity Identity = Principal == Faucet? Zero: Principal. Recognise; Recognition of return == tap? Blank: Identity Name; } Public Static Bull Ice Inole (String Roll) {IParian Principal = Thread Content Principal; Return Principal == Empty? False: Principal. Interval (role); }  

Then there are some audit codes in your DAL:

  row.UpdatedBy = MyUtilityClass.GetUsername ();  

Generic principal is useful for a simple user name set of simple cases and known roles. For example, a more sophisticated major implementation can check access to "on demand" - that is, until you do not know about the "Foo" role that it does not know - then it shows (Web service, Database, active-directory, etc.) and cache the results for future access. This is useful when the list of potential roles is large and the number of roles commonly asked in reality is small.

You need only a few contexts can also use a principal to store an additional identification - for example, as a security token caller principal You can see that it supports additional data.

"because the principal is useful to use" Your logic processing code is abstract - whether talking about identity without winforms, asp.net, wcf, a window, etc. In addition, Some third parties will also talk to the code principal.

As another example - I wrote something that shows how to use the principal to control access to the winning control through the designer (a IExtenderProvider - which puts additional entries in the property grid in VS).


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -