Anders Hattestad
Dec 27, 2010
  11164
(5 votes)

Multiplexing providers

Sometimes you want to use more than one security provider. And that's what the EPiServer multiplex provider can help us. You can add one or more providers in the MultiplexingMembershipProvider section and the same numbers of items in the MultiplexingRoleProvider for the roles.

 

But if one provider allows search for emails, and another doesn't it throws an error. Bit annoying, but is easy to fix. you can add your own multiplexing provider like this:(only added try catch from the underline code)

Code Snippet
  1. public class MultiplexingMembershipProvider : EPiServer.Security.MultiplexingMembershipProvider
  2. {
  3.     public override string GetUserNameByEmail(string email)
  4.     {
  5.         foreach (MembershipProvider provider in this.Providers)
  6.         {
  7.             try
  8.             {
  9.                 string userNameByEmail = provider.GetUserNameByEmail(email);
  10.                 if (userNameByEmail != null)
  11.                 {
  12.                     this.CurrentUsername = userNameByEmail;
  13.                     return userNameByEmail;
  14.                 }
  15.             }
  16.             catch { }
  17.         }
  18.         return null;
  19.     }
  20. }

But there are also times when you want to have 2 user providers and only one role provider. When you have made a page based user provider, and want them to share the same roles. Then its a bit hassle, since if you add 2 of the same role providers, all roles are duplicated.

<add name="MultiplexingRoleProvider" type="Itera.Security.MultiplexingRoleProvider, Itera.Security" 
     provider1="SqlServerRoleProvider" 
     provider2="WindowsRoleProvider" 
     provider3="SqlServerRoleProvider" 
     providerMap1="SqlServerMembershipProvider" 
     providerMap2="WindowsMembershipProvider"
     providerMap3="EPiServerMembershipProvider"/>

The trick is to create your own MultiplexingRoleProvider. At the first glance it is pretty straight forward, but there are stuff inside the AdminGroup page that detects if your role provider inherits form MultiplexingRoleProvider, and gets all the users from the Providers from the role provider. And that is not virtual and is not possible to override.image

image

So to have 2 user providers and only one role provider you have to make your own. And as most of the time you need to copy the code from reflector, and make your modifications.

My modification was that I created a DisitinctProvider list and replaced all references that needed to use that one instead of the Providers.

Code Snippet
  1. public IList<RoleProvider> Providers
  2. {
  3.     get
  4.     {
  5.         if (this._providers == null)
  6.         {
  7.             this.InitProviders();
  8.         }
  9.         return this._providers;
  10.     }
  11. }
  12.  
  13. public IList<RoleProvider> DistinctProviders
  14. {
  15.     get
  16.     {
  17.         if (this._distinctProviders == null)
  18.         {
  19.             this.InitProviders();
  20.         }
  21.         return this._distinctProviders;
  22.     }
  23. }

The only trouble then is that in the admin group page you don’t get provider behind the role

image

This is what i would like to call a mistake by the code team that created the AdminGroup page. They should have checked for an interface instead of hardcode in the MultiPlexRoleProvider. or at least made all the properties there virtual.

 

Itera.Security.MultiplexingMembershipProvider

and

Itera.Security.MultiplexingRoleProvider

is inside the zip file here.

Dec 27, 2010

Comments

Anders Hattestad
Anders Hattestad Jan 3, 2011 06:37 PM

Not my best blog, but rate it 1 was a bit harse:)

Anders Hattestad
Anders Hattestad Jan 20, 2011 10:12 AM

Wow, got 2 fives :) thx

Dennis Malmgren
Dennis Malmgren Mar 4, 2011 08:33 PM

We ran into this issue with one customer wanting to authenticate against double AD nodes. Unfortunately that was before this post so had to solve it haphazardly :) great 'fix' to the builtin functionality.

Please login to comment.
Latest blogs
Optimizely finally releases new and improved list properties!

For years, the Generic PropertyList has been widely used, despite it being unsupported. Today a better option is released!

Tomas Hensrud Gulla | Mar 28, 2023 | Syndicated blog

Official List property support

Introduction Until now users were able to store list properties in three ways: Store simple types (int, string, DateTime, double) as native...

Bartosz Sekula | Mar 28, 2023

New dashboard implemented in CMS UI 12.18.0

As part of the CMS UI 12.18.0 release , a new dashboard has been added as a ‘one stop shop’ to enable editors to access all of their content items,...

Matthew Slim | Mar 28, 2023

How to Merge Anonymous Carts When a Customer Logs In with Optimizely Commerce 14

In e-commerce, it is common for users to browse a site anonymously, adding items to their cart without creating an account. Later, when the user...

Francisco Quintanilla | Mar 27, 2023

How to Write an xUnit Test to Verify Unique Content Type Guids in Content Management

When developing an Optimizely CMS solution, it is important to ensure that each content type has a unique GUID. If two or more content types share...

Minesh Shah (Netcel) | Mar 27, 2023

Extend TinyMCE in Optimizely CMS 12

Since technologies are upgraded to newer versions the ways to extend or override the out-of-the-box functionality are also changed a little bit so...

Ravindra S. Rathore | Mar 27, 2023 | Syndicated blog