# LDAP redirect not working

**URL:** <https://community.f5.com/t/ldap-redirect-not-working/6276>\
**Category:** Technical Forums\
**Tags:** irules, dev, devops, application-delivery\
**Created:** [March 6, 2006, 9:51pm UTC](https://community.f5.com/t/ldap-redirect-not-working/6276 "2006-03-06T21:51:15Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Decker\_2](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@Robert\_Decker\_2](https://community.f5.com/u/Robert_Decker_2)\
**Post date:** [March 6, 2006, 9:51pm UTC](https://community.f5.com/t/ldap-redirect-not-working/6276/1 "2006-03-06T21:51:15Z")

</div>

How do you redirect \_sys\_auth\_ldap? I’ve tried the following(x.x.x.x is the IP address of the web page I created):

replace HTTP::respond 401 with HTTP::respond “[http://x.x.x.x](http://x.x.x.x)”

under the AUTH\_Failure section

or keep HTTP::respond 401 and add the following to the rule:

when HTTP\_RESPONSE {

if { [HTTP::status] contains “401”} {

HTTP::redirect “[http://x.x.x.x](http://x.x.x.x)”

}

}

I cannot redirect the page either way. The page becomes blank after I’ve failed three logins.

Thank you for your help,

Rob

---

<div class="post-metadata">

**Author:** ![Colin\_Walker\_12](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@Colin\_Walker\_12](https://community.f5.com/u/Colin_Walker_12)\
**Post date:** [March 7, 2006, 4:32pm UTC](https://community.f5.com/t/ldap-redirect-not-working/6276/2 "2006-03-07T16:32:10Z")

</div>

I’d recommend taking a look at the complete HTTP::respond syntax. You can see that in the iRules Wiki, here: [Click here](http://devcentral.f5.com/wiki/default.aspx/iRules/HTTP__respond.html)

I think what you’re looking for is a 3xx redirect response, along with the response you want to send to the client.

Something like:

```tcl
HTTP::respond 302 Location "http://new.location.net/app"

```

Check out the info and see if that helps.

As an fyi, there’s also a pretty good list of the HTTP status codes and their definitions over at [w3c.org](http://w3c.org): [Click here](http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)

HTH,

-Colin

---

<div class="post-metadata">

**Author:** ![Robert\_Decker\_2](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@Robert\_Decker\_2](https://community.f5.com/u/Robert_Decker_2)\
**Post date:** [March 8, 2006, 4:49pm UTC](https://community.f5.com/t/ldap-redirect-not-working/6276/3 "2006-03-08T16:49:16Z")

</div>

Thank you for the help Colin! I have been able to use your suggestion, however I am now having problems trying to place it in the Irule. I believe that I need to replace “HTTP::respond 401” with "HTTP::respond 302 Location “[http://x.x.x.x](http://x.x.x.x)”, but have not been able to do it successfully. The only place where it fires is when I replace the last “HTTP::respond 401” under “when AUTH\_WANTCREDENTIAL”. The Irule then redirects right away without prompting for username/password. Could you/anyone tell me where this is best suited?

when AUTH\_SUCCESS {

if {$tmm\_auth\_http\_sids(ldap) eq [AUTH::last\_event\_session\_id]} {

incr tmm\_auth\_http\_successes

if {[info exists tmm\_auth\_http\_sufficient\_successes]} {

if {$tmm\_auth\_http\_successes \>=

$tmm\_auth\_http\_sufficient\_successes} {

foreach {type sid} [array get tmm\_auth\_http\_sids] {

if {$type ne “ldap” && $sid ne -1} {

AUTH::abort $sid

array set tmm\_auth\_http\_sids [list $type -1]

}

}

set tmm\_auth\_http\_collect\_count 0

HTTP::release

} else {

incr tmm\_auth\_http\_collect\_count -1

if {$tmm\_auth\_http\_collect\_count == 0} {

HTTP::respond 401

}

}

} else {

incr tmm\_auth\_http\_collect\_count -1

if {$tmm\_auth\_http\_collect\_count == 0} {

HTTP::release

}

}

}

}

when AUTH\_FAILURE {

if {$tmm\_auth\_http\_sids(ldap) eq [AUTH::last\_event\_session\_id]} {

if {[llength [array names tmm\_auth\_http\_sids]] \> 1} {

if {[info exists tmm\_auth\_http\_sufficient\_successes]} {

incr tmm\_auth\_http\_collect\_count -1

if {$tmm\_auth\_http\_collect\_count == 0} {

HTTP::respond 401

}

} else {

foreach {type sid} [array get tmm\_auth\_http\_sids] {

if {$type ne “ldap” && $sid ne -1} {

AUTH::abort $sid

array set tmm\_auth\_http\_sids [list $type -1]

}

}

set tmm\_auth\_http\_collect\_count 0

HTTP::respond 401

}

} else {

set tmm\_auth\_http\_collect\_count 0

HTTP::respond 401

}

}

}

when AUTH\_WANTCREDENTIAL {

if {$tmm\_auth\_http\_sids(ldap) eq [AUTH::last\_event\_session\_id]} {

if {[llength [array names tmm\_auth\_http\_sids]] \> 1} {

if {[info exists tmm\_auth\_http\_sufficient\_successes]} {

incr tmm\_auth\_http\_collect\_count -1

if {$tmm\_auth\_http\_collect\_count == 0} {

HTTP::respond 401

}

} else {

foreach {type sid} [array get tmm\_auth\_http\_sids] {

if {$type ne “ldap” && $sid ne -1} {

AUTH::abort $sid

array set tmm\_auth\_http\_sids [list $type -1]

}

}

set tmm\_auth\_http\_collect\_count 0

HTTP::respond 401

}

} else {

set tmm\_auth\_http\_collect\_count 0

HTTP::respond 401

}

}

}

when AUTH\_ERROR {

if {$tmm\_auth\_http\_sids(ldap) eq [AUTH::last\_event\_session\_id]} {

if {[llength [array names tmm\_auth\_http\_sids]] \> 1} {

if {[info exists tmm\_auth\_http\_sufficient\_successes]} {

incr tmm\_auth\_http\_collect\_count -1

if {$tmm\_auth\_http\_collect\_count == 0} {

HTTP::respond 401

}

} else {

foreach {type sid} [array get tmm\_auth\_http\_sids] {

if {$type ne “ldap” && $sid ne -1} {

AUTH::abort $sid

array set tmm\_auth\_http\_sids [list $type -1]

}

}

set tmm\_auth\_http\_collect\_count 0

HTTP::respond 401

}

} else {

set tmm\_auth\_http\_collect\_count 0

HTTP::respond 401

}

}

}

Thank you for your help,

Rob

---

<div class="post-metadata">

**Author:** ![Colin\_Walker\_12](https://avatars.discourse-cdn.com/v4/letter/c/a88e4f/32.png) [@Colin\_Walker\_12](https://community.f5.com/u/Colin_Walker_12)\
**Post date:** [March 9, 2006, 6:28pm UTC](https://community.f5.com/t/ldap-redirect-not-working/6276/4 "2006-03-09T18:28:39Z")

</div>

Didn’t you want to change this under the AUTH\_FAILURE section? Did you try that already and I misunderstood your posting?

-Colin

---

<div class="post-metadata">

**Author:** ![Robert\_Decker\_2](https://avatars.discourse-cdn.com/v4/letter/r/df788c/32.png) [@Robert\_Decker\_2](https://community.f5.com/u/Robert_Decker_2)\
**Post date:** [March 9, 2006, 6:44pm UTC](https://community.f5.com/t/ldap-redirect-not-working/6276/5 "2006-03-09T18:44:37Z")

</div>

I’ve added the redirect line in place of the last HTTP::respond line in Auth Failure. This seems to be working now (had other issues I’m troubleshooting). Was this the correct placing? The rule seems to work as long as a username and password is present. I was trying to trigger the rule by adding a username and leaving the password area blank (this never worked). Does PAM require both to be a valid attempt? What happens when a blank password is entered 3 times(the page becomes blank)?

when AUTH\_SUCCESS {

if {$tmm\_auth\_http\_sids(ldap) eq [AUTH::last\_event\_session\_id]} {

incr tmm\_auth\_http\_successes

if {[info exists tmm\_auth\_http\_sufficient\_successes]} {

if {$tmm\_auth\_http\_successes \>=

$tmm\_auth\_http\_sufficient\_successes} {

foreach {type sid} [array get tmm\_auth\_http\_sids] {

if {$type ne “ldap” && $sid ne -1} {

AUTH::abort $sid

array set tmm\_auth\_http\_sids [list $type -1]

}

}

set tmm\_auth\_http\_collect\_count 0

HTTP::release

} else {

incr tmm\_auth\_http\_collect\_count -1

if {$tmm\_auth\_http\_collect\_count == 0} {

HTTP::respond 401

}

}

} else {

incr tmm\_auth\_http\_collect\_count -1

if {$tmm\_auth\_http\_collect\_count == 0} {

HTTP::release

}

}

}

}

when AUTH\_FAILURE {

if {$tmm\_auth\_http\_sids(ldap) eq [AUTH::last\_event\_session\_id]} {

if {[llength [array names tmm\_auth\_http\_sids]] \> 1} {

if {[info exists tmm\_auth\_http\_sufficient\_successes]} {

incr tmm\_auth\_http\_collect\_count -1

if {$tmm\_auth\_http\_collect\_count == 0} {

HTTP::respond 401

}

} else {

foreach {type sid} [array get tmm\_auth\_http\_sids] {

if {$type ne “ldap” && $sid ne -1} {

AUTH::abort $sid

array set tmm\_auth\_http\_sids [list $type -1]

}

}

set tmm\_auth\_http\_collect\_count 0

HTTP::respond 401

}

} else {

set tmm\_auth\_http\_collect\_count 0

HTTP::respond 302 Location “[http://x.x.x.x](http://x.x.x.x)”

}

}

}

when AUTH\_WANTCREDENTIAL {

if {$tmm\_auth\_http\_sids(ldap) eq [AUTH::last\_event\_session\_id]} {

if {[llength [array names tmm\_auth\_http\_sids]] \> 1} {

if {[info exists tmm\_auth\_http\_sufficient\_successes]} {

incr tmm\_auth\_http\_collect\_count -1

if {$tmm\_auth\_http\_collect\_count == 0} {

HTTP::respond 401

}

} else {

foreach {type sid} [array get tmm\_auth\_http\_sids] {

if {$type ne “ldap” && $sid ne -1} {

AUTH::abort $sid

array set tmm\_auth\_http\_sids [list $type -1]

}

}

set tmm\_auth\_http\_collect\_count 0

HTTP::respond 401

}

} else {

set tmm\_auth\_http\_collect\_count 0

HTTP::respond 401

}

}

}

when AUTH\_ERROR {

if {$tmm\_auth\_http\_sids(ldap) eq [AUTH::last\_event\_session\_id]} {

if {[llength [array names tmm\_auth\_http\_sids]] \> 1} {

if {[info exists tmm\_auth\_http\_sufficient\_successes]} {

incr tmm\_auth\_http\_collect\_count -1

if {$tmm\_auth\_http\_collect\_count == 0} {

HTTP::respond 401

}

} else {

foreach {type sid} [array get tmm\_auth\_http\_sids] {

if {$type ne “ldap” && $sid ne -1} {

AUTH::abort $sid

array set tmm\_auth\_http\_sids [list $type -1]

}

}

set tmm\_auth\_http\_collect\_count 0

HTTP::respond 401

}

} else {

set tmm\_auth\_http\_collect\_count 0

HTTP::respond 401

}

}

}

Thank you for your help,

Rob
