Skip to main content
Known Participant
October 7, 2009
Answered

CFLDAP Error Handling

  • October 7, 2009
  • 2 replies
  • 3150 views

I'm trying to make a login application that checks against AD using LDAP. I've been able to query LDAP using entered information in forms. As of now, it will forward users to a desired page once correct login information is entered into the form. The problem I'm having is that when users enter incorrect information, instead of forcing them to a desired URL, it's showing a CF error page stating "

Authentication failed:[LDAP: error code 49 - 80090308: LdapErr: DSID-0C090334, comment: AcceptSecurityContext error, data 52e, vece ]

So of course I don't want to show that. Here's the code I'm using in the form handler page.

<cfldap action="query"

           server="10.0.0.0"

           name="Results"

           start="DC=domain,DC=org"

           filter="(&(objectclass=user)(SamAccountName=#form.username#))"

           username="domainname\#form.username#"

           password="#form.password#"

           attributes = "cn,o,l,st,sn,c,mail,telephonenumber, givenname,homephone, streetaddress, postalcode, SamAccountname, physicalDeliveryOfficeName, department">

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Untitled Document</title>

</head>

<body><cfif Results.RecordCount GT 0>

<cflocation url="http://www.yahoo.com">

<cfelseif Results.RecordCount EQ 0>

<cflocation url="http://www.espn.com">

</cfif>

</body>

</html>

Any ideas or what I may be doing wrong? This is my first attempt at using CF and LDAP together. I wasn't able to get the Login Wizard to work either.

    This topic has been closed for replies.
    Correct answer NettlesD

    I wrap mine in a <cftry> tag.

    Like this:

    <cftry>

    <cfldap action="query"

               server="10.0.0.0"

               name="Results"

               start="DC=domain,DC=org"

               filter="(&(objectclass=user)(SamAccountName=#form.username#))"

               username="domainname\#form.username#"

               password="#form.password#"

               attributes = "cn,o,l,st,sn,c,mail,telephonenumber, givenname,homephone, streetaddress, postalcode, SamAccountname, physicalDeliveryOfficeName, department">

    <cfcatch type="any">

      <cfset session.messages[1] = "Authentication failed.  Please try again.">

      <cflocation url="whatever template  you choose to display your message" addtoken="no">
      <cfabort>
    </cfcatch>

    </cftry>

    2 replies

    Inspiring
    October 12, 2009

    Also note that <cfcatch> supports other values for the "type=" parameter.  If you only want to catch a particular exception-type, you can do so.

    If the exception cannot be handled by a particular <cftry>..<cfcatch> block, ColdFusion will step out to any surrounding blocks (all the way up to the Application level) looking for one that will accept an exception of this type.

    NettlesDCorrect answer
    Inspiring
    October 8, 2009

    I wrap mine in a <cftry> tag.

    Like this:

    <cftry>

    <cfldap action="query"

               server="10.0.0.0"

               name="Results"

               start="DC=domain,DC=org"

               filter="(&(objectclass=user)(SamAccountName=#form.username#))"

               username="domainname\#form.username#"

               password="#form.password#"

               attributes = "cn,o,l,st,sn,c,mail,telephonenumber, givenname,homephone, streetaddress, postalcode, SamAccountname, physicalDeliveryOfficeName, department">

    <cfcatch type="any">

      <cfset session.messages[1] = "Authentication failed.  Please try again.">

      <cflocation url="whatever template  you choose to display your message" addtoken="no">
      <cfabort>
    </cfcatch>

    </cftry>

    J_TremainAuthor
    Known Participant
    October 8, 2009

    Thanks a bunch, that worked perfectly.