[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qexo-general] HTTP Authentification with Qexo
From: |
Terje Pedersen |
Subject: |
[Qexo-general] HTTP Authentification with Qexo |
Date: |
Fri, 1 Aug 2003 22:51:45 +0200 |
User-agent: |
KMail/1.5.1 |
There is just really one missing function to make use of Http Authentification
in Qexo, that is a function getting the username and password pair delivered
from the authentification popup window.
Below I have presented three solutions getting the username and password pair
of data. Which one would you prefer?
-- 1 -- just Base64 decode the string
request-userpass() (: get the username:password string :)
substring-before(request-userpass(),':') (: get username :)
substring-after(request-userpass(),':') (: get password :)
if ( request-userpass()='' ) then () else ()
-- 2 -- return as Values (sequence)
request-userpass-seq() (: get the username as ("username","password")
item-at(request-userpass-seq(),1) (: get username :)
item-at(request-userpass-seq(),2) (: get password :)
if ( empty(request-userpass-seq()) ) then () else ()
-- 3 -- separate functions for username and password
request-auth-user() (: get username :)
request-auth-pass() (: get password :)
if ( request-auth-user()='' and request-auth-pass()='' ) then () else ()
I tried to implement solution number one before I thought about the other
solutions:
HTTP.scm:
(define (request-userpass) :: <String>
(invoke-static <gnu.kawa.servlet.ServletCallContext> 'getUserPass))
ServletCallContext.java:
public static String getUserPass()
{
HttpServletRequest request = getRequest();
String header = request.getHeader("Authorization");
if (header == null || !header.toUpperCase().startsWith("BASIC")) return
"";
String userpass = Base64.decode(header.substring(6));
if(userpass.length()<2) return "";
return userpass;
}
Here is a simple Qexo test program using the first method poping up the
authentification window until you type something and writes out what you
typed.
let $up := request-userpass()
return
if($up='') then
(
response-header('WWW-Authenticate', 'Basic realm="Test"'),
response-status(401,"")
)
else
(
<html><head><title>HTTP Authentification test</title></head>
<body>
Userpass={$up}<br/>
Username={substring-before($up,':')}<br/>
Password={substring-after($up,':')}<br/>
</body>
</html>
)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Qexo-general] HTTP Authentification with Qexo,
Terje Pedersen <=