Fixing possible stackoverflow in FormsAuthenticationService

--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2012-08-31 16:43:52 -07:00
parent aa504ed67e
commit 781d471d10
@@ -12,6 +12,7 @@ namespace Orchard.Security.Providers {
private readonly IContentManager _contentManager; private readonly IContentManager _contentManager;
private readonly IHttpContextAccessor _httpContextAccessor; private readonly IHttpContextAccessor _httpContextAccessor;
private IUser _signedInUser; private IUser _signedInUser;
private bool _isAuthenticated = false;
public FormsAuthenticationService(IClock clock, IContentManager contentManager, IHttpContextAccessor httpContextAccessor) { public FormsAuthenticationService(IClock clock, IContentManager contentManager, IHttpContextAccessor httpContextAccessor) {
_clock = clock; _clock = clock;
@@ -56,20 +57,24 @@ namespace Orchard.Security.Providers {
var httpContext = _httpContextAccessor.Current(); var httpContext = _httpContextAccessor.Current();
httpContext.Response.Cookies.Add(cookie); httpContext.Response.Cookies.Add(cookie);
_isAuthenticated = true;
_signedInUser = user; _signedInUser = user;
} }
public void SignOut() { public void SignOut() {
_signedInUser = null; _signedInUser = null;
_isAuthenticated = false;
FormsAuthentication.SignOut(); FormsAuthentication.SignOut();
} }
public void SetAuthenticatedUserForRequest(IUser user) { public void SetAuthenticatedUserForRequest(IUser user) {
_signedInUser = user; _signedInUser = user;
_isAuthenticated = true;
} }
public IUser GetAuthenticatedUser() { public IUser GetAuthenticatedUser() {
if (_signedInUser != null) if (_signedInUser != null || _isAuthenticated)
return _signedInUser; return _signedInUser;
var httpContext = _httpContextAccessor.Current(); var httpContext = _httpContextAccessor.Current();
@@ -84,6 +89,8 @@ namespace Orchard.Security.Providers {
Logger.Fatal("User id not a parsable integer"); Logger.Fatal("User id not a parsable integer");
return null; return null;
} }
_isAuthenticated = true;
return _signedInUser = _contentManager.Get(userId).As<IUser>(); return _signedInUser = _contentManager.Get(userId).As<IUser>();
} }
} }