Forum Discussion
redirection require wth forward to pool
Hi All
i have a requirement , base on the below irule , it will forward users forward to the test_pool after users authentication successful.
Due to i require another action from irule which is if user key in the "URL equal www.test.com\user" , it will redirect to https://www.test.com/user/resources.html
I am try to change the rule multiple time but at last it failed to achieve the requirement.
Can someone advice and your response is much appreaciate
when RULE_INIT {
set static::auth_debug 1 }
when HTTP_REQUEST {
Grab username and password from authorization header and compare
if { [HTTP::username] eq "" or [HTTP::password] eq "" } {
if { $static::auth_debug } { log local0. "No username and password in Authorization header or Auth header missing." } } else {
Grab the authorization header and convert to username and password
if { $static::auth_debug } { log local0. "Username = [HTTP::username] password = [HTTP::password]" }
Next look in the datagroup called LocalUsers for the user. The value is a hex MD5password.Compare the value in the datagroup to the value of HTTP::password to determine if this is valid.
set password [class lookup "[HTTP::username]" LocalUsers] if { $password eq "" } {
if { $static::auth_debug ==1 } { log local0. "Auth failed for user [HTTP::username] \ and the value in the datagroup was [class lookup [HTTP::username] LocalUsers] "} } else {
how have action with when user key in www/test/com/user redirect it to https://www.test.com/user/resources.html before it forward to test_pool ?
binary scan [ md5 [HTTP::password]] H* hexhash if { $static::auth_debug } { log local0. "password MD5 = $hexhash" } if { $password eq $hexhash } { pool test_pool
if { $static::auth_debug } { log local0. "Auth succeeded for user [HTTP::username] and the value in the datagroup was [class lookup [HTTP::username] LocalUsers] "}
Exit this event for this iRule to prevent sending a 401 below
return } } }
If we are still in the iRule the auth attempt failed
HTTP::respond 401 content "Authorization FailureError:Authentication Failure" WWW-Authenticate "Basic realm=\"local.loc\""
}
1 Reply
- Kevin_Stewart
Employee
Try this:
when RULE_INIT { set static::auth_debug 1 } when HTTP_REQUEST { if { $static::auth_debug } { log local0. "Request URI = [HTTP::uri]." } if { [string tolower [HTTP::uri]] equals "/user" } { HTTP::redirect "http://[HTTP::host]/user/resources.php" return } elseif { [HTTP::username] eq "" or [HTTP::password] eq "" } { Grab username and password from authorization header and compare if { $static::auth_debug } { log local0. "No username and password in Authorization header or Auth header missing." } } else { Grab the authorization header and convert to username and password if { $static::auth_debug } { log local0. "Username = [HTTP::username] password = [HTTP::password]" } Next look in the datagroup called LocalUsers for the user. The value is a hex MD5password.Compare the value in the datagroup to the value of HTTP::password to determine if this is valid. set password [class lookup "[HTTP::username]" LocalUsers] if { $password eq "" } { if { $static::auth_debug ==1 } { log local0. "Auth failed for user [HTTP::username] \ and the value in the datagroup was [class lookup [HTTP::username] LocalUsers] "} } else { how have action with when user key in www/test/com/user redirect it to https://www.test.com/user/resources.html before it forward to test_pool ? binary scan [ md5 [HTTP::password]] H* hexhash if { $static::auth_debug } { log local0. "password MD5 = $hexhash" } if { $password eq $hexhash } { pool test_pool if { $static::auth_debug } { log local0. "Auth succeeded for user [HTTP::username] and the value in the datagroup was [class lookup [HTTP::username] LocalUsers] "} Exit this event for this iRule to prevent sending a 401 below return } } } If we are still in the iRule the auth attempt failed HTTP::respond 401 content "Error:Authentication Failure" WWW-Authenticate "Basic realm=\"local.loc\"" }
Help guide the future of your DevCentral Community!
What tools do you use to collaborate? (1min - anonymous)Recent Discussions
Related Content
* Getting Started on DevCentral
* Community Guidelines
* Community Terms of Use / EULA
* Community Ranking Explained
* Community Resources
* Contact the DevCentral Team
* Update MFA on account.f5.com