public static bool AuthAndSetPrinciple(ICacheProvider cacheProvider, IDepartmentsRepository departmentsRepository, string authTokenString, HttpContextBase context, bool v3) { if (String.IsNullOrWhiteSpace(authTokenString)) { return(false); } var encodedUserPass = authTokenString.Trim(); if (v3) { var authToken = V3AuthToken.Decode(encodedUserPass); string userId; if (Config.SecurityConfig.SystemLoginCredentials.ContainsKey(authToken.UserName)) { if (Config.SecurityConfig.SystemLoginCredentials[authToken.UserName] != encodedUserPass) { return(false); } authToken.UserId = authToken.UserName; } else { if (!ValidateUserAndDepartmentByUser(cacheProvider, departmentsRepository, authToken.UserName, authToken.DepartmentId, null, out userId)) { return(false); } authToken.UserId = userId; } var principal = new ResgridPrincipleV3(authToken); Thread.CurrentPrincipal = principal; if (context != null) { context.User = principal; } } else { var authToken = AuthToken.Decode(encodedUserPass); string userId; if (!ValidateUserAndDepartmentByUser(cacheProvider, departmentsRepository, authToken.UserName, authToken.DepartmentId, authToken.DepartmentCode, out userId)) { return(false); } var principal = new ResgridPrinciple(authToken); Thread.CurrentPrincipal = principal; if (context != null) { context.User = principal; } } return(true); }
public ResgridPrincipleV3(V3AuthToken authToken) { AuthToken = authToken; IsSystem = false; _identity = new GenericIdentity(authToken.UserName, "Basic"); }