Ticket Q261403
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

ConditionalAppearance - Make it possible to manage Action availability against the currently logged user

Custom Action permission help

created 15 years ago

Hi,

I'm trying to implement a custom permission to determine access to Actions. But I think something is wrong and need a little push.

<code lang="cs>
using System;
using System.Security;
using DevExpress.ExpressApp.Security;
using DevExpress.ExpressApp.Utils;
using DevExpress.Xpo;

namespace XXX.Security
{
    [NonPersistent]
    public class ActionAccessPermission : PermissionBase
    {
        public ActionAccessPermission()
        {

}

public ActionAccessPermission(string actionId, ActionAccessModifier modifier)
        {
            this.ActionId = actionId;
            this.Modifier = modifier;
        }

public string ActionId { get; set; }
        public ActionAccessModifier Modifier { get; set; }

public override System.Security.IPermission Copy()
        {
            return new ActionAccessPermission(ActionId, Modifier);
        }

public override string ToString()
        {
            EnumDescriptor enumDescriptor = new EnumDescriptor(typeof(ActionAccessModifier));
            return String.Format("{0} {1} ({2})", CaptionHelper.GetClassCaption(GetType().FullName), ActionId, enumDescriptor.GetCaption(Modifier));
        }

public override void FromXml(SecurityElement e)
        {
            ActionId = e.Attributes["actionId"].ToString();
            Modifier = (ActionAccessModifier)Enum.Parse(typeof(ActionAccessModifier), e.Attributes["modifier"].ToString());
        }

public override SecurityElement ToXml()
        {
            SecurityElement result = base.ToXml();
            result.AddAttribute("actionId", ActionId);
            result.AddAttribute("modifier", Modifier.ToString());
            return result;
        }

public override bool IsSubsetOf(System.Security.IPermission target)
        {
            if (base.Intersect(target) != null)
            {
                if (((ActionAccessPermission)target).ActionId == this.ActionId
                    && ((ActionAccessPermission)target).Modifier == this.Modifier)
                {
                    return true;
                }
                return false;
            }
            return false;
        }
    }
}
</code>

If I only have one of these permissions in a role, it works fine. However, If I have multiple instances, things don't work right and it only ever checks one permission.

For example:

SecuritySystem.IsGranted("ResetPassword", ActionAccessModifier.Allow) (works fine)
SecuritySystem.IsGranted("SomeOtherAction", ActionAccessModifier.Allow) (doesn't work, inside my ActionAccessPermission class, it keeps checking for the first one I passed in… why?)

Do you see anything immediatley wrong wih my permission?

Thanks!

Show previous comments (9)

    Hey Dennis,
    Yes, please feel free to strip this issue and make it public.
    RE: the Conditional appearance portion, I don't think that will work for this case, since the goal of this is to create totally customizable roles, giving end-users, not the developers full control over every aspect of the software.
    I really think the best option is an ActionAccessPermission with a simple Allow/Deny modifier and an ActionId and it definitely seems do-able, I just can't seem to figure it out. It would benefit XAF developers to the extent that I would highly suggest you consider it as a KB article (you do such good ones, you know! :))

    Dennis Garavsky (DevExpress) 15 years ago

      >>Yes, please feel free to strip this issue and make it public.
      Thanks!
      >>RE: the Conditional appearance portion, I don't think that will work for this case, since the goal of this is to create totally customizable roles, giving end-users, not the developers full control over every aspect of the software.
      It's possible to create Appearance rules via the Model Editor in the Model.XAFML (intended for application's administrators). Creating these rules doesn't need extensive development skills. Does this suit you?
      >>I really think the best option is an ActionAccessPermission with a simple Allow/Deny modifier and an ActionId and it definitely seems do-able
      To be honest, we don't think that this is a good solution, due to the strong reasons described above. We will unlikely implement the ActionAccessPermission in XAF, but anyway, thanks for the idea about creating a KB.
      Thanks,
      Dennis

        Dennis,
        I disable model customization in all my deployed apps, so that won't work.
        You mention that SecuritySystem does not handle UI, but that's not true. You only need to look as far as ObjectAccessPermission and the Navigate permission specifically. Beyond that, creating an action that calls myObject.Delete() does not enforce if the logged in user has the ability to delete or not, that's only handled on the UI.
        While I maintain that I think this fits in well to your current model, I respect your decision in that regard. That said, I really need a push in the right direction to get this working in a way that makes sense for my end users, and according to the duplicate issues surrounding this one, other xaf'ers end users :) Am I not correct that you, Dennis, the king of XAF could whip this permission up in a matter of minutes? :P

        Answers

        created 15 years ago (modified 7 years ago)

        Hi Nate,
        Thanks for the feedback.
        >>I disable model customization in all my deployed apps, so that won't work.
        That would work if you allow your application administrators to use the standalone Model Editor (http://documentation.devexpress.com/#Xaf/CustomDocument2582).
        >>
        While I maintain that I think this fits in well to your current model, I respect your decision in that regard. That said, I really need a push in the right direction to get this working in a way that makes sense for my end users, and according to the duplicate issues surrounding this one, other xaf'ers end users :) Am I not correct that you, Dennis, the king of XAF could whip this permission up in a matter of minutes? :P
        <<
        Thanks for your compliments, Nate. I am afraid that this task is not that easy as it seems. Just look at the size of the ObjectAccessPermission.cs source file. Furthermore, we currently don't have free resources to devote them to the implementation of a custom permission. However, we will be glad to create a KB Article about this.
        For now, you have the following options:

        1. Wait for the above mentioned suggestion implementation;
        2. Address your question to the community members (maybe, there are already ready implementations);
        3. Try to implement this task yourself. As I already mentioned above, in order to do this, you will need to:
              a) Research the code of the ObjectAccessPermission.cs source file and implement a custom permission in the manner used when working on the ObjectAccessPermission one;
              b) Implement a controller that will deactivate/disable Actions against current permissions. There is some example code at the end of the Action based Permission issue, showing how to accomplish this.
          Let me know if I can help you further.
          Thanks,
          Dennis
          Comments (1)
          Andrey K (DevExpress Support) 5 years ago

            Hello,

            XAF v20.1 includes a preview of Action Permissions. This new XAF security layer allows developers to prohibit execution of both custom and XAF system Actions within WinForms and ASP.NET applications: Video Overview | Documentation.

            To enable this feature in versions earlier than v20.1.6, set the static SecurityStrategy.EnableSecurityForActions property to True. To add custom Actions or remove system Actions available in the Denied Actions tab, handle the NonSecureActionsInitializing event.

            Note that Action permissions will unconditionally hide Actions: we don't expect to interfere with Conditional AppearanceState MachineTargetObjectsCriteria, or any custom rules that are driven by criteria or object/UI changes within Controllers. If you require dynamic functionality for Actions, use these specific methods and built-in criteria functions such as IsCurrentUserInRole and CurrentUserId. If these solutions do not meet your business needs, please submit a separate ticket and elaborate on your scenario there.

            Thanks,
            Andrey

            Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

            Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.