如何判断用户是否属于Active Directory中的角色 - 使用ColdFusion

Jer*_*emy 2 coldfusion ldap active-directory

如果我在IIS中使用集成身份验证,如何使用ColdFusion确定当前用户是否属于特定活动目录角色.

这类似于在.net中使用User对象的IsInRole()方法 - 如何在ColdFusion中完成

rip*_*747 6

唯一的方法是使用cflap并查询活动目录服务器以获取组列表.在您获得列表后,您将需要解析它以查看该用户是否属于相关组.下面是我写的一些代码,为工作中的人们写了一些评论.价值观已经改变,以保护无辜者.

<!--- getting the user login id --->
<cfset variables.thisuser = ListLast(cgi.AUTH_USER, "\")>
<!--- this is the group they must be a memberof --->
<cfset variables.groupname = "CN=<the group to search for>">
<!--- list of all groups that the user belongs to, will be populated later --->
<cfset variables.grouplist = "">

<cftry>
    <cfldap action="query"
        name="myldap"
        attributes="memberOf"
        start="OU=<your ou>,DC=<your dc>,DC=<your dc>"
        scope="subtree"
        filter="(sAMAccountName=#variables.thisuser#)"
        server="<your AD server ip>"
        port="<your AD server port>"
        username="<network login if required>"
        password="<network password if required>">

    <cfset variables.grouplist = myldap.memberOf>

<cfcatch>
    </cfcatch>
</cftry>

<cfif FindNoCase(variables.groupname, variables.grouplist)>

    <cfcookie name="SecurityCookieName" value="">

</cfif>
Run Code Online (Sandbox Code Playgroud)