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

View File

@@ -12,6 +12,7 @@ namespace Orchard.Security.Providers {
private readonly IContentManager _contentManager;
private readonly IHttpContextAccessor _httpContextAccessor;
private IUser _signedInUser;
private bool _isAuthenticated = false;
public FormsAuthenticationService(IClock clock, IContentManager contentManager, IHttpContextAccessor httpContextAccessor) {
_clock = clock;
@@ -56,20 +57,24 @@ namespace Orchard.Security.Providers {
var httpContext = _httpContextAccessor.Current();
httpContext.Response.Cookies.Add(cookie);
_isAuthenticated = true;
_signedInUser = user;
}
public void SignOut() {
_signedInUser = null;
_isAuthenticated = false;
FormsAuthentication.SignOut();
}
public void SetAuthenticatedUserForRequest(IUser user) {
_signedInUser = user;
_isAuthenticated = true;
}
public IUser GetAuthenticatedUser() {
if (_signedInUser != null)
if (_signedInUser != null || _isAuthenticated)
return _signedInUser;
var httpContext = _httpContextAccessor.Current();
@@ -84,6 +89,8 @@ namespace Orchard.Security.Providers {
Logger.Fatal("User id not a parsable integer");
return null;
}
_isAuthenticated = true;
return _signedInUser = _contentManager.Get(userId).As<IUser>();
}
}