forked from FubuMvcArchive/FubuMVC.AntiForgery
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving policy towards an action filter FubuMvcArchive#7
- Loading branch information
Showing
4 changed files
with
48 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.Net; | ||
using FubuMVC.Core.Continuations; | ||
|
||
namespace FubuMVC.AntiForgery | ||
{ | ||
public interface IAntiForgeryFilter | ||
{ | ||
FubuContinuation Filter(string salt); | ||
} | ||
|
||
public class AntiForgeryFilter : IAntiForgeryFilter | ||
{ | ||
private readonly IAntiForgeryValidator _validator; | ||
|
||
public AntiForgeryFilter(IAntiForgeryValidator validator) | ||
{ | ||
_validator = validator; | ||
} | ||
|
||
public FubuContinuation Filter(string salt) | ||
{ | ||
if (_validator.Validate(salt)) | ||
{ | ||
return FubuContinuation.NextBehavior(); | ||
} | ||
|
||
return FubuContinuation.EndWithStatusCode(HttpStatusCode.InternalServerError); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using FubuMVC.Core; | ||
using FubuMVC.Core.Registration; | ||
|
||
using FubuMVC.Core.Registration; | ||
using FubuMVC.Core.Registration.Nodes; | ||
|
||
namespace FubuMVC.AntiForgery | ||
{ | ||
[ConfigurationType(ConfigurationType.InjectNodes)] | ||
public class AntiForgeryPolicy : IConfigurationAction | ||
{ | ||
public void Configure(BehaviorGraph graph) | ||
{ | ||
var antiForgerySettings = graph.Settings.Get<AntiForgerySettings>(); | ||
graph.Behaviors.Where(antiForgerySettings.AppliesTo) | ||
.Each(x => x.Prepend(new AntiForgeryNode(x.InputType().FullName))); | ||
} | ||
} | ||
[ConfigurationType(ConfigurationType.InjectNodes)] | ||
public class AntiForgeryPolicy : IConfigurationAction | ||
{ | ||
public void Configure(BehaviorGraph graph) | ||
{ | ||
var antiForgerySettings = graph.Settings.Get<AntiForgerySettings>(); | ||
graph.Behaviors.Where(antiForgerySettings.AppliesTo) | ||
.Each(x => x.Prepend(ActionFilter.For<IAntiForgeryFilter>(f => f.Filter(x.InputType().FullName)))); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters