Microsoft Dynamics 4.0 SDK Check If User Has Privilege
Asked Answered
A

2

0

We were previously using an unsupported dll (Microsoft.Crm.Application.Components.Core) to check if the current user in Dynamics has read privileges on a specific entity:

Microsoft.Crm.Security.User.HasPrivilege(Microsoft.Crm.Security.User.Current,   
 "myentityname, AccessRights.ReadAccess);

I need to do the same thing using only the supported SDK (and the CrmService).

Can someone advise on how to accomplish this using the SDK?

Ahron answered 28/2, 2011 at 21:50 Comment(1)
I have found way how to accomplish this using bare SDK: https://mcmap.net/q/1901827/-how-to-get-current-user-privileges-in-ms-dynamics-crm-on-server-sideNelidanelie
A
1

You can probably design a Fetch or QueryExpression like so:

  1. Retrieve on the entity privilege
  2. Join on entity roleprivilege where privilege.privilegeid = roleprivilege.privilegeid
  3. Join on entity systemuserrole where systemuserrole.roleid = roleprivileges.roleid and systemuserrole.systemuserid = (GUID of the user in question)
  4. Then either iterate through the privileges or look for privilege where privilege.name = "prvReadMyEntityName"

Just be careful on the results, because you may get different privilege depths from different roles, but if you don't care about the depth then I think that'll do it.

Aeonian answered 28/2, 2011 at 23:28 Comment(1)
Thanks...I have no idea how to do this though. Can you point me in the right direction?Ahron
F
2

Try with this:

<fetch mapping="logical" count="1000" version="1.0">
    <entity name="privilege">
        <attribute name="name" />
        <filter>
            <condition attribute="name" operator="eq" value="prvCreateINSERTYOURENTITYHERE" />
        </filter>
        <link-entity name="roleprivileges" from="privilegeid" to="privilegeid">
            <link-entity name="role" from="roleid" to="roleid">
                <link-entity name="systemuserroles" from="roleid" to="roleid">
                    <link-entity name="systemuser" from="systemuserid" to="systemuserid">
                        <filter>
                            <condition attribute="fullname" operator="eq" value="INSERT NAME HERE" />
                        </filter>
                    </link-entity>
                </link-entity>
            </link-entity>
        </link-entity>
    </entity>
</fetch>
Firsthand answered 3/8, 2011 at 11:23 Comment(2)
Searching by FullName is not good idea, it's better to use GUID instead.Nelidanelie
...but otherwise a neat, quick solution. Thanks Alberto.Essay
A
1

You can probably design a Fetch or QueryExpression like so:

  1. Retrieve on the entity privilege
  2. Join on entity roleprivilege where privilege.privilegeid = roleprivilege.privilegeid
  3. Join on entity systemuserrole where systemuserrole.roleid = roleprivileges.roleid and systemuserrole.systemuserid = (GUID of the user in question)
  4. Then either iterate through the privileges or look for privilege where privilege.name = "prvReadMyEntityName"

Just be careful on the results, because you may get different privilege depths from different roles, but if you don't care about the depth then I think that'll do it.

Aeonian answered 28/2, 2011 at 23:28 Comment(1)
Thanks...I have no idea how to do this though. Can you point me in the right direction?Ahron

© 2022 - 2024 — McMap. All rights reserved.