diff --git a/lib/ServiceStack.Common.dll b/lib/ServiceStack.Common.dll index adb20be..4e9c7e0 100644 Binary files a/lib/ServiceStack.Common.dll and b/lib/ServiceStack.Common.dll differ diff --git a/lib/ServiceStack.Interfaces.dll b/lib/ServiceStack.Interfaces.dll index 349f299..fcb504c 100644 Binary files a/lib/ServiceStack.Interfaces.dll and b/lib/ServiceStack.Interfaces.dll differ diff --git a/lib/ServiceStack.ServiceInterface.dll b/lib/ServiceStack.ServiceInterface.dll index 6268907..957c809 100644 Binary files a/lib/ServiceStack.ServiceInterface.dll and b/lib/ServiceStack.ServiceInterface.dll differ diff --git a/lib/ServiceStack.Text.dll b/lib/ServiceStack.Text.dll index 85cf7f8..8249cb9 100644 Binary files a/lib/ServiceStack.Text.dll and b/lib/ServiceStack.Text.dll differ diff --git a/lib/ServiceStack.dll b/lib/ServiceStack.dll index ee86f56..113b345 100644 Binary files a/lib/ServiceStack.dll and b/lib/ServiceStack.dll differ diff --git a/src/ServiceStack.Authentication.MongoDB/MongoDBAuthRepository.cs b/src/ServiceStack.Authentication.MongoDB/MongoDBAuthRepository.cs index 4b08fd5..8cd2121 100644 --- a/src/ServiceStack.Authentication.MongoDB/MongoDBAuthRepository.cs +++ b/src/ServiceStack.Authentication.MongoDB/MongoDBAuthRepository.cs @@ -136,7 +136,7 @@ public UserAuth CreateUserAuth(UserAuth newUser, string password) string hash; saltedHash.GetHashAndSaltString(password, out hash, out salt); var digestHelper = new DigestAuthFunctions(); - newUser.DigestHA1Hash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password); + newUser.DigestHa1Hash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password); newUser.PasswordHash = hash; newUser.Salt = salt; newUser.CreatedDate = DateTime.UtcNow; @@ -206,7 +206,7 @@ public UserAuth UpdateUserAuth(UserAuth existingUser, UserAuth newUser, string p saltedHash.GetHashAndSaltString(password, out hash, out salt); } // If either one changes the digest hash has to be recalculated - var digestHash = existingUser.DigestHA1Hash; + var digestHash = existingUser.DigestHa1Hash; if (password != null || existingUser.UserName != newUser.UserName) { var digestHelper = new DigestAuthFunctions(); @@ -215,7 +215,7 @@ public UserAuth UpdateUserAuth(UserAuth existingUser, UserAuth newUser, string p newUser.Id = existingUser.Id; newUser.PasswordHash = hash; newUser.Salt = salt; - newUser.DigestHA1Hash = digestHash; + newUser.DigestHa1Hash = digestHash; newUser.CreatedDate = existingUser.CreatedDate; newUser.ModifiedDate = DateTime.UtcNow; SaveUser(newUser); @@ -264,7 +264,7 @@ public bool TryAuthenticate(Dictionary digestHeaders, string Pri if (userAuth == null) return false; var digestHelper = new DigestAuthFunctions(); - if (digestHelper.ValidateResponse(digestHeaders, PrivateKey, NonceTimeOut, userAuth.DigestHA1Hash, sequence)) + if (digestHelper.ValidateResponse(digestHeaders, PrivateKey, NonceTimeOut, userAuth.DigestHa1Hash, sequence)) { //userId = userAuth.Id.ToString(CultureInfo.InvariantCulture); return true; diff --git a/src/ServiceStack.Authentication.MongoDB/ServiceStack.Authentication.MongoDB.csproj b/src/ServiceStack.Authentication.MongoDB/ServiceStack.Authentication.MongoDB.csproj index 43c2503..e8753c5 100644 --- a/src/ServiceStack.Authentication.MongoDB/ServiceStack.Authentication.MongoDB.csproj +++ b/src/ServiceStack.Authentication.MongoDB/ServiceStack.Authentication.MongoDB.csproj @@ -43,6 +43,9 @@ ..\..\lib\ServiceStack.Common.dll + + ..\..\lib\ServiceStack.Interfaces.dll + ..\..\lib\ServiceStack.ServiceInterface.dll diff --git a/src/ServiceStack.Authentication.NHibernate/NHibernateUserAuthRepository.cs b/src/ServiceStack.Authentication.NHibernate/NHibernateUserAuthRepository.cs index a51dc09..7a45b1e 100644 --- a/src/ServiceStack.Authentication.NHibernate/NHibernateUserAuthRepository.cs +++ b/src/ServiceStack.Authentication.NHibernate/NHibernateUserAuthRepository.cs @@ -115,7 +115,7 @@ public bool TryAuthenticate(Dictionary digestHeaders, string pri if (userAuth == null) return false; var digestHelper = new DigestAuthFunctions(); - return digestHelper.ValidateResponse(digestHeaders, privateKey, nonceTimeOut, userAuth.DigestHA1Hash, sequence); + return digestHelper.ValidateResponse(digestHeaders, privateKey, nonceTimeOut, userAuth.DigestHa1Hash, sequence); } public UserAuth GetUserAuthByUserName(string userNameOrEmail) diff --git a/src/ServiceStack.Authentication.RavenDb/RavenUserAuthRepository.cs b/src/ServiceStack.Authentication.RavenDb/RavenUserAuthRepository.cs index 20e7b5d..344000b 100644 --- a/src/ServiceStack.Authentication.RavenDb/RavenUserAuthRepository.cs +++ b/src/ServiceStack.Authentication.RavenDb/RavenUserAuthRepository.cs @@ -1,9 +1,11 @@ using System; using System.Collections.Generic; +using System.ComponentModel.Composition.Hosting; using System.Globalization; using System.Linq; using System.Text.RegularExpressions; using Raven.Client; +using Raven.Client.Indexes; using ServiceStack.Common; using ServiceStack.ServiceInterface.Auth; using ServiceStack.Text; @@ -16,25 +18,25 @@ public class RavenUserAuthRepository : IUserAuthRepository public Regex ValidUserNameRegEx = new Regex(@"^(?=.{3,15}$)([A-Za-z0-9][._-]?)*$", RegexOptions.Compiled); private readonly IDocumentStore _documentStore; + //Session object is created somewhere else and injected here + private readonly IDocumentSession _session; private static bool _isInitialized = false; - public static void CreateOrUpdateUserAuthIndex(IDocumentStore store) + //Change to allow for Multi- Tenancy cases + //User has to call this method every time he creates a new tenant DB + public static void CreateOrUpdateUserAuthIndex(IDocumentStore store,string databaseName) { // put this index into the ravendb database - new ServiceStack_UserAuth_ByUserNameOrEmail().Execute(store); - new ServiceStack_UserAuth_ByOAuthProvider().Execute(store); + var catalog = new CompositionContainer(new AssemblyCatalog(typeof(ServiceStack_UserAuth_ByUserNameOrEmail).Assembly)); + IndexCreation.CreateIndexes(catalog, store.DatabaseCommands.ForDatabase(databaseName), store.Conventions); _isInitialized = true; } - public RavenUserAuthRepository(IDocumentStore documentStore) + public RavenUserAuthRepository(IDocumentStore documentStore,IDocumentSession session) { _documentStore = documentStore; - - // if the user didn't call this method in their AppHostBase - // Let's call if for them. No worries if this is called a few - // times, we just don't want it running all the time - if (!_isInitialized) - CreateOrUpdateUserAuthIndex(documentStore); + _session = session; + } private void ValidateNewUser(UserAuth newUser, string password) @@ -69,16 +71,16 @@ public UserAuth CreateUserAuth(UserAuth newUser, string password) string hash; saltedHash.GetHashAndSaltString(password, out hash, out salt); var digestHelper = new DigestAuthFunctions(); - newUser.DigestHA1Hash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password); + newUser.DigestHa1Hash = digestHelper.CreateHa1(newUser.UserName, DigestAuthProvider.Realm, password); newUser.PasswordHash = hash; newUser.Salt = salt; newUser.CreatedDate = DateTime.UtcNow; newUser.ModifiedDate = newUser.CreatedDate; - using (var session = _documentStore.OpenSession()) + using (_session) { - session.Store(newUser); - session.SaveChanges(); + _session.Store(newUser); + _session.SaveChanges(); } return newUser; @@ -116,7 +118,7 @@ public UserAuth UpdateUserAuth(UserAuth existingUser, UserAuth newUser, string p saltedHash.GetHashAndSaltString(password, out hash, out salt); } // If either one changes the digest hash has to be recalculated - var digestHash = existingUser.DigestHA1Hash; + var digestHash = existingUser.DigestHa1Hash; if (password != null || existingUser.UserName != newUser.UserName) { var digestHelper = new DigestAuthFunctions(); @@ -125,14 +127,14 @@ public UserAuth UpdateUserAuth(UserAuth existingUser, UserAuth newUser, string p newUser.Id = existingUser.Id; newUser.PasswordHash = hash; newUser.Salt = salt; - newUser.DigestHA1Hash = digestHash; + newUser.DigestHa1Hash = digestHash; newUser.CreatedDate = existingUser.CreatedDate; newUser.ModifiedDate = DateTime.UtcNow; - using (var session = _documentStore.OpenSession()) + using (_session) { - session.Store(newUser); - session.SaveChanges(); + _session.Store(newUser); + _session.SaveChanges(); } return newUser; @@ -140,9 +142,9 @@ public UserAuth UpdateUserAuth(UserAuth existingUser, UserAuth newUser, string p public UserAuth GetUserAuthByUserName(string userNameOrEmail) { - using (var session = _documentStore.OpenSession()) + using (_session) { - var userAuth = session.Query() + var userAuth = _session.Query() .Customize(x => x.WaitForNonStaleResultsAsOfNow()) .Search(x => x.Search, userNameOrEmail) .OfType() @@ -175,7 +177,7 @@ public bool TryAuthenticate(Dictionary digestHeaders, string Pri if (userAuth == null) return false; var digestHelper = new DigestAuthFunctions(); - if (digestHelper.ValidateResponse(digestHeaders, PrivateKey, NonceTimeOut, userAuth.DigestHA1Hash, sequence)) + if (digestHelper.ValidateResponse(digestHeaders, PrivateKey, NonceTimeOut, userAuth.DigestHa1Hash, sequence)) { return true; } @@ -209,19 +211,22 @@ public UserAuth GetUserAuth(string userAuthId) { using (var session = _documentStore.OpenSession()) { - return session.Load(userAuthId); + int intAuthId; + return int.TryParse(userAuthId, out intAuthId) + ? session.Load(intAuthId) + : session.Load(userAuthId); } } public void SaveUserAuth(IAuthSession authSession) { - using (var session = _documentStore.OpenSession()) + using (_session) { int idInt = int.Parse(authSession.UserAuthId); var userAuth = !authSession.UserAuthId.IsNullOrEmpty() - ? session.Load(idInt) - : authSession.TranslateTo(); + ? _session.Load(idInt) + : authSession.TranslateTo(); if (userAuth.Id == default(int) && !authSession.UserAuthId.IsNullOrEmpty()) userAuth.Id = idInt; @@ -230,30 +235,30 @@ public void SaveUserAuth(IAuthSession authSession) if (userAuth.CreatedDate == default(DateTime)) userAuth.CreatedDate = userAuth.ModifiedDate; - session.Store(userAuth); - session.SaveChanges(); + _session.Store(userAuth); + _session.SaveChanges(); } } public void SaveUserAuth(UserAuth userAuth) { - using (var session = _documentStore.OpenSession()) + using (_session) { userAuth.ModifiedDate = DateTime.UtcNow; if (userAuth.CreatedDate == default(DateTime)) userAuth.CreatedDate = userAuth.ModifiedDate; - session.Store(userAuth); - session.SaveChanges(); + _session.Store(userAuth); + _session.SaveChanges(); } } public List GetUserOAuthProviders(string userAuthId) { - using (var session = _documentStore.OpenSession()) + using (_session) { var id = int.Parse(userAuthId); - return session.Query() + return _session.Query() .Customize(x => x.WaitForNonStaleResultsAsOfNow()) .Where(q => q.UserAuthId == id) .OrderBy(x => x.ModifiedDate) @@ -278,9 +283,9 @@ public UserAuth GetUserAuth(IAuthSession authSession, IOAuthTokens tokens) if (tokens == null || tokens.Provider.IsNullOrEmpty() || tokens.UserId.IsNullOrEmpty()) return null; - using (var session = _documentStore.OpenSession()) + using (_session) { - var oAuthProvider = session + var oAuthProvider = _session .Query() .Customize(x => x.WaitForNonStaleResultsAsOfNow()) .Where(q => q.Provider == tokens.Provider && q.UserId == tokens.UserId) @@ -289,7 +294,7 @@ public UserAuth GetUserAuth(IAuthSession authSession, IOAuthTokens tokens) if (oAuthProvider != null) { - var userAuth = session.Load(oAuthProvider.UserAuthId); + var userAuth = _session.Load(oAuthProvider.UserAuthId); return userAuth; } return null; @@ -300,9 +305,9 @@ public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens to { var userAuth = GetUserAuth(authSession, tokens) ?? new UserAuth(); - using (var session = _documentStore.OpenSession()) + using (_session) { - var oAuthProvider = session + var oAuthProvider = _session .Query() .Customize(x => x.WaitForNonStaleResultsAsOfNow()) .Where(q => q.Provider == tokens.Provider && q.UserId == tokens.UserId) @@ -325,8 +330,8 @@ public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens to if (userAuth.CreatedDate == default(DateTime)) userAuth.CreatedDate = userAuth.ModifiedDate; - session.Store(userAuth); - session.SaveChanges(); + _session.Store(userAuth); + _session.SaveChanges(); oAuthProvider.UserAuthId = userAuth.Id; @@ -334,8 +339,8 @@ public string CreateOrMergeAuthSession(IAuthSession authSession, IOAuthTokens to oAuthProvider.CreatedDate = userAuth.ModifiedDate; oAuthProvider.ModifiedDate = userAuth.ModifiedDate; - session.Store(oAuthProvider); - session.SaveChanges(); + _session.Store(oAuthProvider); + _session.SaveChanges(); return oAuthProvider.UserAuthId.ToString(CultureInfo.InvariantCulture); }