vADC Docs

HowTo: Query an external datasource using HTTP

by on ‎02-24-2013 06:49 AM - edited on ‎06-11-2015 01:08 PM by PaulWallace (1,858 Views)

A TrafficScript rule can ask Stingray to query an external datasource using a variety of methods - HTTP, an authentication protocol such as LDAP, via a Java Extension or using a simple TCP socket.

 

Querying a datasource using HTTP

 

For example, Stingray may wish to validate a request's credentials by querying an external database via a web gateway. In this sample rule, Stingray extracts and decodes the username and password given in a Basic authentication header. Stingray then sends the username and password to a script on a nearby websserver which contains all the logic to check the credentials. The webserver returns an 'OK' message if the credentials check out.

 

# This returns the header value 'Basic 3AD35sd5oPkS4nHha2'   
$auth = http.getHeader( "Authorization" );   
  
# Extract and decode the encoded username and password   
$enc = string.skip( $h, 6 );   
$userpasswd = string.base64decode( $enc );   
  
# Parse the usernameSmiley Tongueassword string   
string.regexmatch( $userpassword, "([^:]*)Smiley Sad.*)" );   
$user = $1; $password = $2;   
  
# Query the 'auth.cgi' script on http://192.168.1.4/   
$body = http.request.get( "http://192.168.1.4/auth.cgi?username=".$user."&password=".$password );   
if( string.contains( $body, "OK" ) ) {     
    # the credentials check out OK      
    ...   
} else {  
   # the credentials are bogus!  
   ...   
}  

 

A more complete implementation of this would have to send the '401 Authenticate' response and 'WWW-Authenticate' header, and MAY use 'data.set()' and 'data.get()' to cache the responses from the remote authentication server to improve performance.

 

Read more

 

Contributors