{"id":20755202,"url":"https://github.com/formix/megacityone","last_synced_at":"2025-04-28T18:25:14.990Z","repository":{"id":27329367,"uuid":"30803907","full_name":"formix/MegaCityOne","owner":"formix","description":"Windows Advanced Authorization System","archived":false,"fork":false,"pushed_at":"2016-08-03T13:25:33.000Z","size":994,"stargazers_count":2,"open_issues_count":0,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-19T06:57:29.149Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/formix.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-02-14T17:54:34.000Z","updated_at":"2023-01-21T09:04:55.000Z","dependencies_parsed_at":"2022-08-17T17:40:42.405Z","dependency_job_id":null,"html_url":"https://github.com/formix/MegaCityOne","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formix%2FMegaCityOne","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formix%2FMegaCityOne/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formix%2FMegaCityOne/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/formix%2FMegaCityOne/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/formix","download_url":"https://codeload.github.com/formix/MegaCityOne/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251363619,"owners_count":21577661,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T09:23:47.081Z","updated_at":"2025-04-28T18:25:14.972Z","avatar_url":"https://github.com/formix.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# MegaCityOne\nWindows Advanced Authorization System\n\n[![Join the chat at https://gitter.im/formix/MegaCityOne](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/formix/MegaCityOne?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge)\n\n[Google Group](http://bit.ly/19bXnDv)\n\n* This is not an authentication library.\n* This project uses Judge Dredd metaphor to implement autorization.\n* This library integrates:\n    * seamlessly with Windows Standard Security;\n    * prefectly with ASP.NET security;\n    * without issue with anything that sets an IPrincipal to Thread.CurrentPrincipal;\n    * with some work for anything else that is not Windows Standard Security.\n\nThis Project uses [Semantic Versioning](http://semver.org/).\n\n# Installation\n\nMegaCityOne is available at [Nuget.org](https://www.nuget.org/packages/MegaCityOne/) and\ncan be installed as a package using VisualStudio NuGet package manager or via the NuGet\ncommand line:\n\n\u003e Install-Package MegaCityOne\n\n# Documentation\n\n* [Api Reference](https://github.com/formix/MegaCityOne/blob/master/MegaCityOne/doc/api.md)\n* [Class Diagram](https://raw.githubusercontent.com/formix/MegaCityOne/master/MegaCityOne/doc/ClassDiagram.gif)\n\n# Usage\n\n## Authentication\n\nAs stated in the premice, MegaCityOne has nothing to do with authentication.\nYou are responsible to request user name and password in your application and \nthen validate the password against the corresponding credentials in your \nsystem's database. Then see instructions below to set the credentials to\nthe current thread. For MVC 5 integration, install the nuget package \n[MegaCityOne-Mvc](https://github.com/formix/MegaCityOne-Mvc) and read\nprovided instructions on the project page.\n\n### Attaching Credentials to Your Application Thread\n\nSet the authenticated user's credentials in the current HttpContext or the \ncurrent thread.\n\n```c#\n// Or for desktop applications:\nSystem.Threading.Thread.CurrentPrincipal = new GenericPrincipal(\n    new GenericIdentity(\"garry\"),\n    new string[] {\"SiteAdmin\", \"Author\", \"SomeOtherUsefulGroup\"});\n```\n\n## How to Judge\n\nJudging perps and interpreting the Law require years of long lasting studies\nand a lot of bloody practices in dangerous dark alleys. To help you do \nthis dangerous task, MegaCityOne offers Judges that will execute your \nlegislation in different ways.\n\n### JudgeDredd\n\nUnderstands Laws defined as lambda expressions.\n\n```c#\nJudgeDread judge = new JudgeDread();\ndredd.Laws.Add(\n    \"AllowOpenChannel\", \n    (principal, arguments) =\u003e principal.IsInRole(\"SiteAdmin\"));\n```\n\nJudgeDredd can discover and load a set of laws from any library \n(i.e. assembly) having a JusticeDepartment (i.e. implementing \nthe JusticeDepartment interface) defined in it.\n\n### JudgeAnderson\n\nUnderstands Laws defined in a JavaScript file.\n\n```c#\nJudgeAnderson judge = new JudgeAnderson();\nanderson.Load(new FileInfo(\"laws.js\"));\n```\n\nWith Laws defined as functions returning true or false:\n\n```javascript\n//// laws.js \\\\\\\\\n\nfunction AllowOpenChannel(principal) {\n    return principal.IsInRole(\"SiteAdmin\");\n}\n```\n\n### Altering Application Behavior and Code Protection\n\nFor any Judge, you have the following two methods: Advise and Enforce. The\nAdvise method is called to display or hide user interface elements. The \nEnforce method is called to protect a section of code from illegal activity.\nEnforce will throw an exception if the Law is broken.\n\n```c#\nif (judge.Advise(\"AllowOpenChannel\"))\n{\n    // Display the Open Channel button...\n}\n\n\n// Before executing sensitive code, call Enforce\n\njudge.Enforce(\"AllowOpenChannel\");\n\n// If your thread have not been killed by a LawgiverException here\n// (SecurityException specialized class), you are ok to go on.\n\n```\n\n## Make Your Case\n\nSometimes, a Judge will need some arguments from you to help him distinguish\nthe truth and deliver Justice. Those arguments can be optionaly given to the \nJudge when you ask him an advice (Advise) or when you ask him to Enforce a \nLaw.\n\n```c#\nJudgeDread judge = new JudgeDread();\ndredd.Laws.Add(\n    \"CanSaveQuote\", \n    (principal, arguments) \n        =\u003e \n        principal.IsInRole(\"SalesRep\")) \u0026\u0026\n        ((Quote)arguments[0]).Owner == principal.Identity.Name;\n\n\nif (dredd.advise(\"CanSaveQuote\", currentQuote))\n{\n    // show the save button\n}\n```\n\nIn this particular case, The JavaScript rule definition is way more \nconvenient:\n\n```javascript\n\n// A JavaScript rule with an argument!\n\nfunction CanSaveQuote(principal, quote) {\n    return principal.IsInRole(\"SalesRep\") \u0026\u0026 \n           quote.Owner === principal.Identity.Name\n}\n```\n\n## I am The Law\n\nMegaCityOne is easily extensible and \n[IoC](http://en.wikipedia.org/wiki/Inversion_of_control) friendly. \nAll public and protected methods are virtual. You can extends existing \nJudges or create a brand new one from AbstractJudge or Judge interface \nif needs be.\n\n# Example\n\n[Bank account example using JudgeDredd](https://github.com/formix/MegaCityOne/blob/master/MegaCityOne.Example.ConsoleEx/BankAccountExample.cs)\n\n# Regarding Interfaces\n\nEven if I come from a Java World, I respect the unpleasant hungarian \nnotation prefix \"I\" for interface names when coding .NET. But for this \nparticular library, I found that the \"I\" prefix broke the coding storyline \ncreated by the JudgeDredd metaphor, so I stripped it.\n\n# One Last Word\n\n\u003e You got what you deserved, bum. There is no iso chamber in my MegaCityOne \n\u003e implementation. Death sentences prevail.\n\u003e\n\u003e _- JudgeDredd_\n \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformix%2Fmegacityone","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fformix%2Fmegacityone","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fformix%2Fmegacityone/lists"}