question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Question] Is there any way to force reload authorization provider during runtime?

See original GitHub issue

Assume the following authorization provider:


namespace Languages.Authorization
{
    public class LanguagesAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            using (var scope = IocManager.Instance.CreateScope())
            {
                var _permissionProvider = IocManager.Instance.Resolve<IPermissionManager>();
                var _langManager = IocManager.Instance.Resolve<ILanguageManager>();

                var administration = context.CreatePermission(PermissionNames.Administration);
                var languages = administration.CreateChildPermission(PermissionNames.Administration_Languages);
                languages.CreateChildPermission(PermissionNames.Administration_Languages_Create);
                languages.CreateChildPermission(PermissionNames.Administration_Languages_Read);
                languages.CreateChildPermission(PermissionNames.Administration_Languages_Update);
                languages.CreateChildPermission(PermissionNames.Administration_Languages_Delete);
                languages.CreateChildPermission(PermissionNames.Administration_Languages_List);

                var languageTexts = languages.CreateChildPermission(PermissionNames.Administration_Languages_Texts);
                languageTexts.CreateChildPermission(PermissionNames.Administration_Languages_Texts_List);
                var languageTextsUpdate = languageTexts.CreateChildPermission(PermissionNames.Administration_Languages_Texts_Update);
                var LanguageTextsRead = languageTexts.CreateChildPermission(PermissionNames.Administration_Languages_Texts_Read);


                foreach (var lang in _langManager.GetLanguages())
                {
                    languageTextsUpdate.CreateChildPermission($"{PermissionNames.Administration_Languages_Texts_Update}.{lang.Name}");
                }

                foreach (var lang in _langManager.GetLanguages())
                {
                    LanguageTextsRead.CreateChildPermission($"{PermissionNames.Administration_Languages_Texts_Read}.{lang.Name}");
                }


            }
        }

Now a new language is added but permissions provider is not aware of newly added language. Is there a way to force Authorization to reload permissions? It is somehow related to #3538 but the difference here is that permissions usage is predicted during design time: see for example part of LocalizationTextsAppService:

  public async Task AddEditTranslation(LanguageTextsInput input)
        {
            
            await PermissionChecker.AuthorizeAsync(PermissionNames.Administration_Languages_Texts_Update + "." + input.Language);
            if (input.Value == null) input.Value = "";
            await _langTextsManager.UpdateStringAsync(null, input.Source, new System.Globalization.CultureInfo(input.Language), input.Key, input.Value);
        }

For development i can easily restart app pool, but this is not an option to a highly traffic web app due to app pool warm up

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
A-Ghorabcommented, Jun 19, 2019

@raphaeldiasrj today i was facing this issue and just made this solution up you can try it i’m still in the middle of project building and it’s working fine with me

  1. I copied this files and pasted them in my project (PermissionDefinitionContextBase , PermissionDictionary,PermissionManager).

  2. In my Core Module in PreInitialize()

//Added this Handler so i can redirect every IPermissionManager to my Custom Implementation
            IocManager.IocContainer.Kernel.AddHandlerSelector(new PermissionManagerHandler());

And The PermissionManagerHandler

public class PermissionManagerHandler : IHandlerSelector 
    {      
        public bool HasOpinionAbout(string key, Type service)
        {
            return typeof(IPermissionManager) == service;
        }
        public IHandler SelectHandler(string key, Type service, IHandler[] handlers)
        {
            return handlers.First(x => x.ComponentModel.Implementation == typeof(PermissionManager));
        }
    }
  1. In Custom Permission Manager i Modified the Initialize Function by adding
    Permissions.Clear(); then every time i add a new Permission i call the initialize function so i can republish every thing

  2. in Core Module PostInitilize Method add IocManager.Resolve<PermissionManager>().Initialize();

0reactions
A-Ghorabcommented, Aug 13, 2019

@tamys : Did @AhmedGoGo’s solution work? I have tried but faced the error “No component for supporting the service Abp.Authorization.PermissionManager was found”. Could you share some advices?

Try to change the Namespace of the copied files to yours instead of Abp.Authorization

and be sure that the copied PermissionManager implements ISingletonDependency

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to reload authorities on user update with Spring Security
If a session exist, I can invalidate his session using : expireNow() (from SessionInformation ) to force re-authentication. But I don't ...
Read more >
Auto Refresh Settings Changes in ASP.NET Core Runtime
Is there a way to refresh and apply it automatically after you modify the settings? Background. Let's take a look at a website...
Read more >
Reload Java Classes at Runtime With JRebel
Read this post to learn how to reload Java classes at runtime, classloaders, and how JRebel bypasses reloads.
Read more >
Three(+1) ways to refresh the claims of a logged-in user
In this article I describe three approaches: 1. Update user claims via cookie event: This is a relatively easy way to update the...
Read more >
Live Reloading Server And Client Side ASP.NET Core Apps ...
Open a command Window in your Web project's folder · Type dotnet watch run · Open your browser and navigate to an API...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found