Commits

David Roberts committed 5fc988f

Including readme.

  • Participants
  • Parent commits 6bc7d5f

Comments (0)

Files changed (1)

+#Loremipsum.Permissions#
+####Simple Permissions Based Authorization####
+
+**Loremipsum.Permissions is a .NET library you can use to perform permissions based authorization.** It allows you to administer the permissions as well as assert a member's authorization for a particular action, inheriting group permissions, and defaulting to deny anything not explicitly given.
+
+##Getting Started##
+-------------------------
+
+Start by creating a simple C# console application and installing the [Nuget package][]:
+	
+	Install-Package Loremipsum.Permissions
+
+You wil also need to install a permissions storage library. For this example just use the [RavenPermissionsStore Nuget package][]
+
+	Install-Package Loremipsum.Permissions.RavenPermissionsStore
+
+And the [RavenDB Embedded][] database library for the sample.
+
+    Install-Package RavenDB.Embedded
+
+If you would like more information on [RavenDb][] be sure to checkout their [website][RavenDb]
+
+Finally replace the `Main` function in `Program.cs` with the following:
+
+	static void Main(string[] args)
+	{
+		Console.WriteLine("Initializing in memory document store, just a moment please...");
+		IDocumentStore ravenStore = new EmbeddableDocumentStore() { RunInMemory = true };
+		ravenStore.Initialize();
+		IPermissionsStorage permissionsStore = new RavenPermissionsStorage(ravenStore);
+ 
+		// The default 'agent' provides permissions administration and assertion.
+		// See the PermissionsAdminister and PermissionsAssertion interfaces.
+		DefaultPermissionsAgent agent = new DefaultPermissionsAgent(permissionsStore);
+
+		IPermissionsAdminister administer = agent as IPermissionsAdminister;
+		administer.GrantRight("johndoe", "openfile");
+		administer.DenyRight("johndoe", "startmeeting");
+
+		administer.GrantRight("management", "startmeeting"); // Group permission
+		administer.GrantRight("developer", "writecode"); // Group permission
+
+		IPermissionsAssertion asserter = agent as IPermissionsAssertion;
+    
+		// Simple user right.
+		bool allowed = asserter.IsAllowed("johndoe", "openfile", "management");
+		Console.WriteLine("Is johndoe allowed to open a file? (expect true) " + allowed);
+
+		// User rights inherited from group.
+		allowed = asserter.IsAllowed("janesmith", "writecode", "developer");
+		Console.WriteLine("Is janesmith allowed to write code? (expect true) " + allowed);
+
+		// User explicit right overriding group right.
+		allowed = asserter.IsAllowed("johndoe", "startmeeting", "management");
+		Console.WriteLine("Is johndoe allowed to start a meeting? (expect false) " + allowed);
+
+		// User denied if not explicit right given.
+		allowed = asserter.IsAllowed("johndoe", "somerandomaction", "management");
+		Console.WriteLine("Is johndoe allowed to do some random action? (expect false) " + allowed);
+
+		Console.WriteLine("Done.");
+		Console.ReadKey();
+	}
+
+Now run the application. What this does is first creates an in memory [RavenDb] store which will hold the permissions. Then you're adding permissions for a sample user and some groups. Finally you're checking to see if the user is allowed certain actions. This is a *very* simple example application. You would more likely use this in an ASP.NET MVC web application, in which case you use a custom authorization attribute, this is in the works at the moment.
+
+
+Resoures
+========
+
+-------------------------
+
+Loremipsum.Permissions is open source and licensed under the [Apache 2.0 License][]. The [source code][] is on [Bitbucket][]. You can report any bugs or feature requests on the [issues board][], pull requests are always welcome and encouraged.
+
+[Nuget package]: https://nuget.org/packages/Loremipsum.Permissions/ 
+[RavenPermissionsStore Nuget package]: https://nuget.org/packages/Loremipsum.Permissions.RavenPermissions/
+[RavenDb]: http://www.ravendb.net/
+[Apache 2.0 License]: http://www.apache.org/licenses/LICENSE-2.0.html
+[source code]: https://bitbucket.org/davidroberts63/loremipsum.permissions
+[Bitbucket]: http://www.bitbucket.org/
+[issues board]: https://bitbucket.org/davidroberts63/loremipsum.permissions/issues?status=new&status=open
+[RavenDB Embedded]: http://nuget.org/packages/RavenDB.Embedded/2.0.2261