GithubHelp home page GithubHelp logo

foc- / mongomembership Goto Github PK

View Code? Open in Web Editor NEW
16.0 16.0 5.0 9.12 MB

Store user profiles and roles in MongoDB storage. And allow easy access to use thems from MemberShipProvider, ProfileProvider, RoleProvider in ASP.NET

License: MIT License

C# 87.83% JavaScript 0.05% CSS 0.10% ASP.NET 0.12% HTML 11.91%

mongomembership's People

Contributors

foc- avatar hkato avatar kohenkatz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mongomembership's Issues

Error in Membership.CreateUser(string username, string password) method causes null reference exception

As far as I can see, any invocation of the CreateUser method with a null email address results in a null reference exception. This includes the CreateUser(string username, string password) overload, and any other overload with a null passed in for the email string.

I suspect this is caused by your .ToLowerInvariant() call, MSDN doesn't say, but I'm guessing that calling .ToLowerInvariant on a null string is bad. Maybe you need a null check?

Case Sensitivity inconsistency

User Login is case insensitive, the default behavior of ASP.Net results in the logged in username of an given session being case insensitive, you match the lower case field. However, checking for presence in a role is not case insensitive.

In other words:
A user can register with the name "Test"

They can then log in with the name "tesT", using the correct password, because the Membership provider only matches the lower case (is case insensitive).

The Default Internet Application Template for MVC with forms authentication uses the User entered username (not one from the database) to set the username in the authcookie.

When a role check happens, a call is made to GetRolesForUser in your MongoGateway, but this does not use case insensitivity, nor does it dereference the user name into the true username, as such if the user is logged in as "tesT" it will throw an exception.

There are a number of ways to fix this:
1.) If this behaviour is correct, it can be mitigated by the application writer (which I'm doing anyways) by simply using the real username to populate the AuthCookie.

If the Behavior is wrong (as I assume it is, as I doubt the default template would be designed such that it cannot be used with roles) there are 2 options:

2.) Query the Mongo db as lowercase, and compare with a lower case copy of the username, thus not breaking existing implementations

3.) Change the creation of role membership records so they use a lowercase username, and compare thusly, this breaks existing datastores

I vote Option 2, as it maximizes compatibility with the stock template while not breaking working existing implementations

Licensing

Maybe I missed it, but you ought to put some sort of licensing marks on this so that its usability is clearly stated.

Add multiple users to lowercase saved rolename dosen't work?

Hi,

i might figured out an issue, please check it by yourself if it's right, or just a special problem on my project.

I added a new Role with Roles.CreateRole("admin") to my mongodb. After that i assigned a username to that role. Now if i want to add another username to that role, it dont works.

If i repeat the Steps with another role, that was created with Roles.CreateRole("Admin"), it works.

I figured out the Section of Code who was responsible for that:

In MongoGateway.cs line 348:


public bool IsUserInRole(string applicationName, string username, string roleName)
        {
            if (username.IsNullOrWhiteSpace() || roleName.IsNullOrWhiteSpace())
                return false;

            return UsersCollection
                    .AsQueryable()
                    .Any(user
                        => user.ApplicationName == applicationName
                        && user.UsernameLowercase == username.ToLowerInvariant()
                        && (user.Roles.Contains(roleName.ToLowerInvariant())) || user.Roles.Contains(roleName));

        }

if i change that into this, it works fine:


public bool IsUserInRole(string applicationName, string username, string roleName)
        {
            if (username.IsNullOrWhiteSpace() || roleName.IsNullOrWhiteSpace())
                return false;

            return UsersCollection
                    .AsQueryable()
                    .Any(user
                        => user.ApplicationName == applicationName
                        && user.UsernameLowercase == username.ToLowerInvariant()
                        && user.Roles.Contains(roleName.ToLowerInvariant()));
        }

I dont know if this is the best solution, but it seems to work for me.

Updating Mongo C# driver

First off, many thanks for this project.

I've just started using MongoRepository project in my ASP.NET app and would like to continue using
both MongoMembership & MongoRepository.
Unfortunately MongoRepository uses a more up to date version of the 10gen C# driver (1.7 vs 1.4.2)
which breaks MongoMembership when installed (both the WAT & regular FormsAuth methods fail)

I've cloned your project & updated the Mongo driver to latest via NuGet.
I've also changed the MongoGateway to use GetClient-GetServer-GetDatabase & MongoUrl and all is working for me.

I would however prefer to depend on a NuGet package rather than my custom built version of MongoMembership.
Are you planning on updating the referenced Mongo C# driver to >=1.7 any time soon?

Thanks again

MongoCommandException always occurs in CreateIndex()

I'm not good at GitHub. I created issue #9 and pull request #12 .
Applying this change we can run tests, but all tests are failed when creating indexes. (also failed in Sample Web project and my application by using nuget package)

The Exception message as below. Sorry my environment is Japanese.
MongoDB.Driver.MongoCommandException はユーザー コードによってハンドルされませんでした。 Code=85 ErrorMessage=Index: { v: 2, key: { _fts: "text", _ftsx: 1 }, name: "ApplicationName_text_EmailLowercase_text", ns: "TestMongoMembershipProvider.User", weights: { ApplicationName: 1, EmailLowercase: 1 }, default_language: "english", language_override: "language", textIndexVersion: 3 } already exists with different options: { v: 2, key: { _fts: "text", _ftsx: 1 }, name: "ApplicationName_text", ns: "TestMongoMembershipProvider.User", weights: { ApplicationName: 1 }, default_language: "english", language_override: "language", textIndexVersion: 3 } HResult=-2146233088 Message=Command createIndexes failed: Index: { v: 2, key: { _fts: "text", _ftsx: 1 }, name: "ApplicationName_text_EmailLowercase_text", ns: "TestMongoMembershipProvider.User", weights: { ApplicationName: 1, EmailLowercase: 1 }, default_language: "english", language_override: "language", textIndexVersion: 3 } already exists with different options: { v: 2, key: { _fts: "text", _ftsx: 1 }, name: "ApplicationName_text", ns: "TestMongoMembershipProvider.User", weights: { ApplicationName: 1 }, default_language: "english", language_override: "language", textIndexVersion: 3 }. Source=MongoDB.Driver.Core StackTrace: 場所 MongoDB.Driver.Core.WireProtocol.CommandWireProtocol1.ProcessReply(ConnectionId connectionId, ReplyMessage1 reply) 場所 MongoDB.Driver.Core.WireProtocol.CommandWireProtocol1.Execute(IConnection connection, CancellationToken cancellationToken)
場所 MongoDB.Driver.Core.Servers.Server.ServerChannel.ExecuteProtocol[TResult](IWireProtocol1 protocol, CancellationToken cancellationToken) 場所 MongoDB.Driver.Core.Servers.Server.ServerChannel.Command[TResult](DatabaseNamespace databaseNamespace, BsonDocument command, IElementNameValidator commandValidator, Func1 responseHandling, Boolean slaveOk, IBsonSerializer1 resultSerializer, MessageEncoderSettings messageEncoderSettings, CancellationToken cancellationToken) 場所 MongoDB.Driver.Core.Operations.CommandOperationBase1.ExecuteProtocol(IChannelHandle channel, ServerDescription serverDescription, ReadPreference readPreference, CancellationToken cancellationToken)
場所 MongoDB.Driver.Core.Operations.CommandOperationBase1.ExecuteProtocol(IChannelSource channelSource, ReadPreference readPreference, CancellationToken cancellationToken) 場所 MongoDB.Driver.Core.Operations.WriteCommandOperation1.Execute(IWriteBinding binding, CancellationToken cancellationToken)
場所 MongoDB.Driver.Core.Operations.CreateIndexesUsingCommandOperation.Execute(IWriteBinding binding, CancellationToken cancellationToken)
場所 MongoDB.Driver.Core.Operations.CreateIndexesOperation.Execute(IWriteBinding binding, CancellationToken cancellationToken)
場所 MongoDB.Driver.OperationExecutor.ExecuteWriteOperation[TResult](IWriteBinding binding, IWriteOperation1 operation, CancellationToken cancellationToken) 場所 MongoDB.Driver.MongoCollectionImpl1.ExecuteWriteOperation[TResult](IWriteOperation1 operation, CancellationToken cancellationToken) 場所 MongoDB.Driver.MongoCollectionImpl1.MongoIndexManager.CreateMany(IEnumerable1 models, CancellationToken cancellationToken) 場所 MongoMembership.Mongo.MongoGateway.CreateIndex() 場所 C:\Users\kato\Source\Repos\MongoMembership\MongoMembership\Mongo\MongoGateway.cs:行 297 場所 MongoMembership.Mongo.MongoGateway..ctor(String mongoConnectionString) 場所 C:\Users\kato\Source\Repos\MongoMembership\MongoMembership\Mongo\MongoGateway.cs:行 22 場所 MongoMembership.Tests.StubsBase.CreateMongoGateway() 場所 C:\Users\kato\Source\Repos\MongoMembership\MongoMembership.Tests\StubsBase.cs:行 45 場所 MongoMembership.Tests.Mongo.IsRoleExists_when_called_and_search_with_lovercased_role_name.<>c.<.ctor>b__6_0() 場所 C:\Users\kato\Source\Repos\MongoMembership\MongoMembership.Tests\Mongo\IsRoleExists_when_called_and_search_with_lovercased_role_name.cs:行 12 InnerException:

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.