-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added an Authorize attribute for checking Sitecore user logged in a…
…nd redirecting if not. * Added an DisplayName attribute to use that uses the SC Dictionary for sourcing it's text.
- Loading branch information
1 parent
3d6d3dd
commit 9f65327
Showing
6 changed files
with
93 additions
and
4 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
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,32 @@ | ||
using Sitecore.Globalization; | ||
using System.ComponentModel; | ||
|
||
namespace CoreSitecore.Sys.ComponentModel | ||
{ | ||
/// <summary> | ||
/// A DisplayName attribute that gets the text to use from the Sitecore Dictionary (localised to current language). | ||
/// | ||
/// A better solution though is to use | ||
/// </summary> | ||
public class ScDisplayNameAttribute : DisplayNameAttribute | ||
{ | ||
private readonly string _dictionaryKey; | ||
|
||
/// <summary> | ||
/// Initializes a DisplayName field attribute that gets its text from the Sitecore Dictionary using <paramref name="dictionaryKey"/>. | ||
/// </summary> | ||
/// <param name="dictionaryKey">Key to lookup in Sitecore Dictionary.</param> | ||
public ScDisplayNameAttribute(string dictionaryKey) | ||
{ | ||
_dictionaryKey = dictionaryKey; | ||
} | ||
|
||
public override string DisplayName | ||
{ | ||
get | ||
{ | ||
return Translate.Text(_dictionaryKey); | ||
} | ||
} | ||
} | ||
} |
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,40 @@ | ||
using System; | ||
using System.Web; | ||
using System.Web.Mvc; | ||
|
||
namespace CoreSitecore.Sys.Web.Mvc | ||
{ | ||
/// <summary> | ||
/// An AuthorizeByDomain attribute implementation that checks the current Sitecore.Context.User is not null, authenticated and belongs to extranet domain. | ||
/// </summary> | ||
public class AuthorizeByDomainAttribute : AuthorizeAttribute | ||
{ | ||
private readonly string _domainName; | ||
|
||
/// <summary> | ||
/// If specified, on an unauthorized request, user will be redirected to this url. | ||
/// </summary> | ||
public string RedirectToUrl { get; set; } | ||
|
||
public AuthorizeByDomainAttribute(string domainName) | ||
{ | ||
_domainName = domainName; | ||
} | ||
|
||
protected override bool AuthorizeCore(HttpContextBase httpContext) | ||
{ | ||
var user = Sitecore.Context.User; | ||
return user != null && user.IsAuthenticated && user.GetDomainName().Equals(_domainName, StringComparison.OrdinalIgnoreCase); | ||
} | ||
|
||
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext) | ||
{ | ||
if (!string.IsNullOrWhiteSpace(RedirectToUrl)) | ||
{ | ||
filterContext.Result = new RedirectResult(RedirectToUrl); | ||
} | ||
|
||
base.HandleUnauthorizedRequest(filterContext); | ||
} | ||
} | ||
} |
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,14 @@ | ||
namespace CoreSitecore.Sys.Web.Mvc | ||
{ | ||
/// <summary> | ||
/// An Authorize attribute implementation that checks the current Sitecore.Context.User is not null, authenticated and belongs to extranet domain. | ||
/// </summary> | ||
public class AuthorizeExtranetAttribute : AuthorizeByDomainAttribute | ||
{ | ||
public AuthorizeExtranetAttribute() | ||
: base("extranet") | ||
{ | ||
|
||
} | ||
} | ||
} |