Try our conversational search powered by Generative AI!

Authentication for IFrameComponent

Vote:
 

I have created the following widget:


[IFrameComponent(Url = "~/modules/Translation/Views/MyTranslationWidget.aspx",
ReloadOnContextChange = true,
PlugInAreas = "/episerver/cms/mainnavigation",
Title = "My Translation",
Categories = "cms",
MinHeight = 130,
MaxHeight = 500)]
public partial class MyTranslationWidget : Page
{

...

}

How to show it only to specific user groups?

#91179
Sep 29, 2014 10:57
Vote:
 

Hi!

This is my best guess without actually implementing anything myself.

You should create your own sub class for IFrameComponentAttribute and override the method CreateComponentDefinition().

Call base.CreateComponentDefinition(componentType) and add your restrictions the AllowedRoles property.

Please let us know if it works and share the code!

#91423
Oct 04, 2014 1:25
Vote:
 

Hi Fredrik!

Thanks for the advice, it worked. Here is the code:

    public class IFrameComponentWithAuthorization : IFrameComponentAttribute
    {
        public string AllowedRoles { get; set; }

        public override IComponentDefinition CreateComponentDefinition(Type attributedType)
        {
            var componentDefinition = base.CreateComponentDefinition(attributedType);
            if (AllowedRoles != null)
            {
                var allowedRoles = AllowedRoles.Split(new char[1] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()).ToArray();
                typeof(PluggableComponentDefinitionBase).GetProperty("AllowedRoles").SetValue(componentDefinition, allowedRoles, null);
            }

            return componentDefinition;
        }
    }

And the widget:

    [IFrameComponentWithAuthorization(Url = "~/modules/Translation/Views/TranslationGadget.aspx",
        ReloadOnContextChange = true, PlugInAreas = "/episerver/cms/mainnavigation", Title = "My Translation",
        Categories = "cms", AllowedRoles = "Administrators, TranslationEditors", MinHeight = 130, MaxHeight = 500)]
    public partial class TranslationGadget: Page
    {
    ...
    }

Thank you!

#91482
Oct 07, 2014 14:42
Vote:
 

Great! Please mark it as answered.

#91499
Oct 07, 2014 16:35
Vote:
 

Hi!

This feature has now been added to the base attribute and will be released within a few weeks.

#118020
Feb 26, 2015 7:15
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.