c# - Using a fluent security custom policy with castle windsor -
I have flint security setup (and work) to protect my controller tasks and I have to solve everything The castle used Windsor (too much you can download castlewindsor-fluentsecurity is shown in the project). What I want to do now is creating a custom policy that runs queries on our Active Directory. I have created a test policy that implements the ISecurity policy but I do not have a default constructor because I need to inject the interface to reach AD. Here's the policy: -
Public class test policy: iCity Policy {Private Readonly IQueryHandler & lt; GetUserQuery, Users & gt; UserQueryHandler; Public Testing Policy (IQueryHandler & lt; GetUserQuery, User & gt; User SearchHandler) {this.userQueryHandler = userQueryHandler; } Public Policy Result Enforce (Escrowity Contact Reference) {var adUser = userQueryHandler.Handle (New GetUserQuery ()); If (adUser.HasManager ()) {Return PolicyResult.CreateSuccessResult (this); } Return Policy Results Create FileResult (this, "Access Denied!"); }}
IQueryHandler is used elsewhere and fixes correctly I have added the policy to the controller: -
configuration. For & lt; Area. People Controller Info Controller & gt; (). AddPolicy & lt; TestPolicy & gt; ();
But when it is called: - The examination policy could not be loaded! Ensure that the policy has an empty constructor or is registered in your IoC-container. Now looking for documentation it seems that I remember the phase where I tell the security converter that I am using the IOC document does not show a special Castle windsor, but I 'came with': -
Configure the security. Configure (Configuration => Configuration. ResolveVides (type = & gt; _ Container. Resolve all types) .Cast & LT; Object & gt; ()));
It does not work well and it seems weird that security configurations require Castle Windsor containers, as long as the security is configured. Registry Security Rule () is called I can not get too close with Castle Windsor, can anyone show me how to configure Fluent Security in this example?
OK - I finally got it working: I have security in the Configurator Configuration. Resolveviceaging (type = & gt; container.resolve all (type) .stafaft & lt; object & gt; (), type = & gt; container.colnell.hascomponent (type)? Container leakage (type): zero );
I changed the controller policy to add the interface instead of a real policy:
configuration < Areas.People.Controllers.InfoController & gt; () AddPolicy. & Lt; ITestPolicy & gt; ();
Issues ISecurityPolicy:
Public Interface ITestPolicy: ISecurityPolicy {}
And then the interface can be wired with Castle:
Container Registrar (component. Forte & lt; ITestPolicy & gt; (); applied; Test Policy & gt; ());
I think that by placing this on Fluent Docs, you may need to use the policy interface so that it can be resolved by CastleWindsor ... ( Unless I am using it wrong!)
Comments
Post a Comment