-
Notifications
You must be signed in to change notification settings - Fork 602
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Active Directory membership service
- Loading branch information
Ollienator
committed
Oct 8, 2015
1 parent
f6c6a5c
commit 082d357
Showing
43 changed files
with
1,212 additions
and
521 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
using System; | ||
using Microsoft.Practices.Unity; | ||
using Microsoft.Practices.Unity.Configuration; | ||
|
||
namespace Bonobo.Git.Server.App_Start | ||
{ | ||
/// <summary> | ||
/// Specifies the Unity configuration for the main container. | ||
/// </summary> | ||
public class UnityConfig | ||
{ | ||
#region Unity Container | ||
private static Lazy<IUnityContainer> container = new Lazy<IUnityContainer>(() => | ||
{ | ||
var container = new UnityContainer(); | ||
RegisterTypes(container); | ||
return container; | ||
}); | ||
|
||
/// <summary> | ||
/// Gets the configured Unity container. | ||
/// </summary> | ||
public static IUnityContainer GetConfiguredContainer() | ||
{ | ||
return container.Value; | ||
} | ||
#endregion | ||
|
||
/// <summary>Registers the type mappings with the Unity container.</summary> | ||
/// <param name="container">The unity container to configure.</param> | ||
/// <remarks>There is no need to register concrete types such as controllers or API controllers (unless you want to | ||
/// change the defaults), as Unity allows resolving a concrete type even if it was not previously registered.</remarks> | ||
public static void RegisterTypes(IUnityContainer container) | ||
{ | ||
// NOTE: To load from web.config uncomment the line below. Make sure to add a Microsoft.Practices.Unity.Configuration to the using statements. | ||
// container.LoadConfiguration(); | ||
|
||
// TODO: Register your types here | ||
// container.RegisterType<IProductRepository, ProductRepository>(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
using System.Linq; | ||
using System.Web.Mvc; | ||
using Microsoft.Practices.Unity.Mvc; | ||
|
||
[assembly: WebActivatorEx.PreApplicationStartMethod(typeof(Bonobo.Git.Server.App_Start.UnityWebActivator), "Start")] | ||
[assembly: WebActivatorEx.ApplicationShutdownMethod(typeof(Bonobo.Git.Server.App_Start.UnityWebActivator), "Shutdown")] | ||
|
||
namespace Bonobo.Git.Server.App_Start | ||
{ | ||
/// <summary>Provides the bootstrapping for integrating Unity with ASP.NET MVC.</summary> | ||
public static class UnityWebActivator | ||
{ | ||
/// <summary>Integrates Unity when the application starts.</summary> | ||
public static void Start() | ||
{ | ||
var container = UnityConfig.GetConfiguredContainer(); | ||
|
||
FilterProviders.Providers.Remove(FilterProviders.Providers.OfType<FilterAttributeFilterProvider>().First()); | ||
FilterProviders.Providers.Add(new UnityFilterAttributeFilterProvider(container)); | ||
|
||
DependencyResolver.SetResolver(new UnityDependencyResolver(container)); | ||
|
||
// TODO: Uncomment if you want to use PerRequestLifetimeManager | ||
// Microsoft.Web.Infrastructure.DynamicModuleHelper.DynamicModuleUtility.RegisterModule(typeof(UnityPerRequestHttpModule)); | ||
} | ||
|
||
/// <summary>Disposes the Unity container when the application is shut down.</summary> | ||
public static void Shutdown() | ||
{ | ||
var container = UnityConfig.GetConfiguredContainer(); | ||
container.Dispose(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
51 changes: 51 additions & 0 deletions
51
Bonobo.Git.Server/Configuration/ActiveDirectorySettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Configuration; | ||
using System.Linq; | ||
using System.Web; | ||
|
||
namespace Bonobo.Git.Server.Configuration | ||
{ | ||
public class ActiveDirectorySettings | ||
{ | ||
public static string DefaultDomain { get; private set; } | ||
public static string MemberGroupName { get; private set; } | ||
public static string BackendPath { get; private set; } | ||
public static IDictionary<string, string> RoleNameToGroupNameMapping { get; private set; } | ||
public static IDictionary<string, string> TeamNameToGroupNameMapping { get; private set; } | ||
|
||
private static IDictionary<string, string> CreateMapping(string definition) | ||
{ | ||
Dictionary<string, string> result = new Dictionary<string, string>(); | ||
|
||
if (!String.IsNullOrEmpty(definition)) | ||
{ | ||
foreach (string entry in definition.Split(',', ';')) | ||
{ | ||
string[] mapping = entry.Split('='); | ||
if (mapping.Length == 2) | ||
{ | ||
string key = mapping[0].Trim(); | ||
string value = mapping[1].Trim(); | ||
if (!String.IsNullOrEmpty(key) && !String.IsNullOrEmpty(value)) | ||
{ | ||
result.Add(key, value); | ||
} | ||
} | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
static ActiveDirectorySettings() | ||
{ | ||
DefaultDomain = ConfigurationManager.AppSettings["ActiveDirectoryDefaultDomain"]; | ||
MemberGroupName = ConfigurationManager.AppSettings["ActiveDirectoryMemberGroupName"]; | ||
BackendPath = ConfigurationManager.AppSettings["ActiveDirectoryBackendPath"]; | ||
|
||
RoleNameToGroupNameMapping = CreateMapping(ConfigurationManager.AppSettings["ActiveDirectoryRoleMapping"]); | ||
TeamNameToGroupNameMapping = CreateMapping(ConfigurationManager.AppSettings["ActiveDirectoryTeamMapping"]); | ||
} | ||
} | ||
} |
Oops, something went wrong.