← Архив: Common Lisp

Hunchentoot: authorization clean

Author: · 20.09.2012 10:24
· original author: lisomort
Создал декоратор по примеру:
(defclass http-auth-route (routes:proxy-route) ())
(defmethod routes:route-check-conditions ((route http-auth-route) bindings)
  (and (call-next-method)
       (multiple-value-bind (user password) (hunchentoot:authorization)
         (or (and (string= user "hello")
                  (string= password "world")
)

             (hunchentoot:require-authorization)
)
)
)
)

(defun @http-auth-require (route)
  (make-instance 'http-auth-route :target route)
)

Возник вопрос. Я захожу на страницу, которая требует авторизации и авторизируюсь. Как очистить это значение? не закрывая браузера. Полистал мануал по hunchentoot`у - ничего не нашел
· original author: Monk
Вообще-то его запоминает броузер. http://stackoverflow.com/questions/449788/http-authentication-logout-via-php. Штатных методов заставить забыть нет.
Нештатные: 
1. AJAX запрос с левым именем на путь в том же сервере и успешным ответом.
2. Можно попытаться выдавать новый realm (в hunchentoot:require-authorization).
3. Команда "очистки" на сервере запоминает имя пользователя и один раз выдаёт, что неверный пароль
(defvar *logout*)
(defun logout (user)
   (setf *logout* user))
(defmethod routes:route-check-conditions ((route http-auth-route) bindings)
  (and (call-next-method)
       (multiple-value-bind (user password) (hunchentoot:authorization)
         (or (and (not (string= *logout* user)
                  (string= user "hello")
                  (string= password "world"))
             (setf *logout* nil)
             (hunchentoot:require-authorization)))))