diff --git a/src/Umbraco.Core/Security/BackOfficeUserManager.cs b/src/Umbraco.Core/Security/BackOfficeUserManager.cs index f84d333843..e4c58ed6f0 100644 --- a/src/Umbraco.Core/Security/BackOfficeUserManager.cs +++ b/src/Umbraco.Core/Security/BackOfficeUserManager.cs @@ -61,20 +61,58 @@ namespace Umbraco.Core.Security } #endregion + /// + /// Creates a BackOfficeUserManager instance with all default options and the default BackOfficeUserManager + /// + /// + /// + /// + /// + /// public static BackOfficeUserManager Create( IdentityFactoryOptions options, - IOwinContext context, IUserService userService, IExternalLoginService externalLoginService, MembershipProviderBase membershipProvider) { if (options == null) throw new ArgumentNullException("options"); - if (context == null) throw new ArgumentNullException("context"); if (userService == null) throw new ArgumentNullException("userService"); if (externalLoginService == null) throw new ArgumentNullException("externalLoginService"); var manager = new BackOfficeUserManager(new BackOfficeUserStore(userService, externalLoginService, membershipProvider)); + return InitUserManager(manager, membershipProvider, options); + } + + /// + /// Creates a BackOfficeUserManager instance with all default options and a custom BackOfficeUserManager instance + /// + /// + /// + /// + /// + public static BackOfficeUserManager Create( + IdentityFactoryOptions options, + BackOfficeUserStore customUserStore, + MembershipProviderBase membershipProvider) + { + if (options == null) throw new ArgumentNullException("options"); + if (customUserStore == null) throw new ArgumentNullException("customUserStore"); + + var manager = new BackOfficeUserManager(customUserStore); + + return InitUserManager(manager, membershipProvider, options); + } + + /// + /// Initializes the user manager with the correct options + /// + /// + /// + /// + /// + private static BackOfficeUserManager InitUserManager(BackOfficeUserManager manager, MembershipProviderBase membershipProvider, IdentityFactoryOptions options) + { // Configure validation logic for usernames manager.UserValidator = new UserValidator(manager) { @@ -102,7 +140,7 @@ namespace Umbraco.Core.Security } //custom identity factory for creating the identity object for which we auth against in the back office - manager.ClaimsIdentityFactory = new BackOfficeClaimsIdentityFactory(); + manager.ClaimsIdentityFactory = new BackOfficeClaimsIdentityFactory(); //NOTE: Not implementing these, if people need custom 2 factor auth, they'll need to implement their own UserStore to suport it diff --git a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.html b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.html index 37751bfab6..8346acfabb 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/dialogs/user.html @@ -30,7 +30,7 @@

-
+
External login providers
diff --git a/src/Umbraco.Web/Security/Identity/AppBuilderExtensions.cs b/src/Umbraco.Web/Security/Identity/AppBuilderExtensions.cs index 63d4efd2e6..912b19fd2e 100644 --- a/src/Umbraco.Web/Security/Identity/AppBuilderExtensions.cs +++ b/src/Umbraco.Web/Security/Identity/AppBuilderExtensions.cs @@ -17,8 +17,9 @@ namespace Umbraco.Web.Security.Identity public static class AppBuilderExtensions { #region Backoffice + /// - /// Configure Identity User Manager for Umbraco + /// Configure Default Identity User Manager for Umbraco /// /// /// @@ -36,12 +37,36 @@ namespace Umbraco.Web.Security.Identity app.CreatePerOwinContext( (options, owinContext) => BackOfficeUserManager.Create( options, - owinContext, appContext.Services.UserService, appContext.Services.ExternalLoginService, userMembershipProvider)); } + /// + /// Configure a custom UserStore with the Identity User Manager for Umbraco + /// + /// + /// + /// + /// + public static void ConfigureUserManagerForUmbracoBackOffice(this IAppBuilder app, + ApplicationContext appContext, + MembershipProviderBase userMembershipProvider, + BackOfficeUserStore customUserStore) + { + //Don't proceed if the app is not ready + if (appContext.IsConfigured == false + || appContext.DatabaseContext == null + || appContext.DatabaseContext.IsDatabaseConfigured == false) return; + + //Configure Umbraco user manager to be created per request + app.CreatePerOwinContext( + (options, owinContext) => BackOfficeUserManager.Create( + options, + customUserStore, + userMembershipProvider)); + } + /// /// Ensures that the UmbracoBackOfficeAuthenticationMiddleware is assigned to the pipeline ///