web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

how to know a user whether has a privilege in ax2012?

(0) ShareShare
ReportReport
Posted on by 95

Dear All,

A user can have several roles. A role can have multi-privileges, multi-duties and multi-subroles. A duty has multi-privileges. Subrole also is a role.

So how to know a user whether has a privilege in ax2012? 

 

Thanks a lot

Jacky

 

*This post is locked for comments

I have the same question (0)
  • Bilal Issa Profile Picture
    4,370 on at
    Re: how to know a user whether has a privilege in ax2012?

    Hi Jacky,

    do you mean you want know what roles has access to certain object like table , form.., if yes, you can select the object -> right click -> add-Ins -> security tools ->  view related security roles.

    I hope that helps.

    Bilal

  • jacky xu Profile Picture
    95 on at
    Re: how to know a user whether has a privilege in ax2012?

    Hi, My meaning is In AX2012, the privilege is smallest unit to control permission. If i gave a privilege, how can i know a user whether has this privilege through X++ code?  As previous version, security key is the smallest unit to control permission, we can use X++ code to know a user whether has a security key by API.

    Thanks

    Jacky

  • Bilal Issa Profile Picture
    4,370 on at
    Re: how to know a user whether has a privilege in ax2012?

    Hi

    you still can check the user access Via x++ using the follwoing:

    1. SecurityRights class

    example :

    SecurityRights      sr;
        AccessRight         accessRight = AccessRight::Delete;

        sr = SecurityRights::construct();

        if (_formRun && _formRun.args() && _formRun.args().menuItemName())
        {
            //get menu item access rights
            switch(_formRun.args().menuItemType())
            {
                case MenuItemType::Action:
                    accessRight = sr.menuItemAccessRight(SecurableType::MenuItemAction, _formRun.args().menuItemName());
                    break;
                case MenuItemType::Display:
                    accessRight = sr.menuItemAccessRight(SecurableType::MenuItemDisplay, _formRun.args().menuItemName());
                    break;
                case MenuItemType::Output:
                    accessRight = sr.menuItemAccessRight(SecurableType::MenuItemOutput, _formRun.args().menuItemName());
                    break;
                default:
                    break;
            }
        }

        return accessRight;


    2. AxaptaUserManager


    3. global functions

    example:

     if (Global::hasTableAccess(tablenum(EventInbox)))
    {
       // code
    }


    I hope that helps

  • Zel Profile Picture
    15 on at
    RE: how to know a user whether has a privilege in ax2012?

    Hi Jacky,

    There are a few system tables which relates to security.

    SecurityUserRole               - The Roles uers are assigned to

    SecurityTask                       - The Duties and priviledges which exists

    SecuritySubTask                - The priviledges which is under duties for example

    SecurityRoleTaskGrant    - The Duties and priviledges assigned to roles

    Using these tables, it is quite simple to write a job which allows you to determine whether a certain user has a certain priviledge.

    Just note that these tables are not accessible through the Data Dictionary.

    I hope this answers your question.

    Regards,

    Zel

  • Suggested answer
    Ahmad Zbeeb Profile Picture
    150 on at
    RE: how to know a user whether has a privilege in ax2012?

    This would check if the current user has access to a certain privilege

    Hope this helps!

    static boolean hasAccessToPrivilege(SecurityTaskAotName _privilegeName)

    {

       UserInfo                    userInfo;

       SecurityUserRole            securityUserRole;

       SecurityRoleTaskGrant       srtGrant;

       securityRoleExplodedGraph   securityRoleExplodedGraph;

       securityTaskExplodedGraph   securityTaskExplodedGraph;

       SecurityTask                securityTask;

       select firstOnly securityTask where securityTask.AotName == _privilegeName;

       select RecId from userInfo where userInfo.Enable && userInfo.id == curUserId()

       exists join securityUserRole where securityUserRole.User == userInfo.Id &&

           securityUserRole.AssignmentStatus == RoleAssignmentStatus::Enabled

       join securityRoleExplodedGraph where securityUserRole.SecurityRole == securityRoleExplodedGraph.SecurityRole

       join srtGrant where srtGrant.SecurityRole == securityRoleExplodedGraph.SecuritySubRole

       join securityTaskExplodedGraph where securityTaskExplodedGraph.SecurityTask == srtGrant.SecurityTask &&

           securityTaskExplodedGraph.SecuritySubTask == securityTask.RecId;

       return userInfo.RecId;

    }

  • Community Member Profile Picture
    on at
    RE: how to know a user whether has a privilege in ax2012?

    Assalam u alaikum Ahmad,

    Thank you for your post.  It was extremely helpful.  In my case, I was interested in the print management privileges of the current user.  Hope others find the following code based on your code helpful.

       List                        userRoles;

       ListEnumerator              userRolesEnumerator;

       SecurityRights              securityRights;

       SysUserManagement           userManagement;

       SecurityRole                securityRole;

       SecurityRoleAotName         securityRoleAotName;

       SecurityTask                securityTask, securityTaskSub;

       SecurityTaskExplodedGraph   securityTaskExplodedGraph;

       SecurityRoleAllTasksView    securityRoleAllTasksView;

       Set                         printMgmtPrivileges;

       securityRights              = SecurityRights::construct();

       // User is an administrator.  Do not filter.  Return all results.

       if (securityRights.isSystemAdministrator())

       {

           //return valueAllRows;

       }

       printMgmtPrivileges         = new Set(Types::String);

       userManagement              = new SysUserManagement();

       userRoles                   = userManagement.getRolesForUser(curUserId());

       userRolesEnumerator       = userRoles.getEnumerator();

       // Generate a set of all print management privileges to which the current user has access.

       while (userRolesEnumerator.moveNext())

       {

           securityRoleAotName = userRolesEnumerator.current();

           while select RecId from securityRole

               where securityRole.AotName == securityRoleAotName

           join RecId from securityRoleAllTasksView

               where securityRoleAllTasksView.SecurityRole == securityRole.RecId

           join RecId from securityTask

               where securityTask.RecId == securityRoleAllTasksView.SecurityTask

                   && securityTask.AotName like 'PrintMgmt*'

           join RecId from securityTaskExplodedGraph

               where securityTaskExplodedGraph.SecurityTask == securityTask.RecId

           join RecId, AotName from securityTaskSub

               where securityTaskSub.RecId == securityTaskExplodedGraph.SecuritySubTask

                   && securityTaskSub.Type == SecurityTaskType::Privilege

           {

               printMgmtPrivileges.add(securityTaskSub.AotName);

           }

       }

    - Mohammed Pasha

  • Suggested answer
    Andrew Xu Profile Picture
    3,877 on at
    RE: how to know a user whether has a privilege in ax2012?

    you can use the security development tool to check/add/remove/delete the access ability of privileges, duties and roles. that's a very handy tool for security design. check this out,

    technet.microsoft.com/.../hh859729.aspx

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Pallavi Phade – Community Spotlight

We are honored to recognize Pallavi Phade as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#2
AlissonGodoy Profile Picture

AlissonGodoy 2

#2
Community Member Profile Picture

Community Member 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans