2 /** External authentication via HTTPD for FusionForge
3 * Copyright 2011, Roland Mas
5 * This file is part of FusionForge. FusionForge is free software;
6 * you can redistribute it and/or modify it under the terms of the
7 * GNU General Public License as published by the Free Software
8 * Foundation; either version 2 of the Licence, or (at your option)
11 * FusionForge is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along
17 * with FusionForge; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 require_once $GLOBALS['gfcommon'].'include/User.class.php';
24 * Authentication manager for FusionForge
27 class AuthHTTPDPlugin extends ForgeAuthPlugin {
28 function AuthHTTPDPlugin () {
30 $this->ForgeAuthPlugin() ;
31 $this->name = "authhttpd";
32 $this->text = "HTTPD authentication";
34 $this->_addHook('display_auth_form');
35 $this->_addHook("check_auth_session");
36 $this->_addHook("fetch_authenticated_user");
37 $this->_addHook("close_auth_session");
39 $this->saved_login = '';
40 $this->saved_user = NULL;
42 $this->declareConfigVars();
45 private static $init = false;
48 * Display a form to input credentials
49 * @param unknown_type $params
52 function displayAuthForm(&$params) {
53 if (!$this->isRequired() && !$this->isSufficient()) {
56 $return_to = $params['return_to'];
61 $result .= _('Cookies must be enabled past this point.');
64 $result .= '<form action="' . util_make_url('/plugins/authhttpd/post-login.php') . '" method="get">
65 <input type="hidden" name="form_key" value="' . form_generate_key() . '"/>
66 <input type="hidden" name="return_to" value="' . htmlspecialchars(stripslashes($return_to)) . '" />
67 <p><input type="submit" name="login" value="' . _('Login via HTTP authentication') . '" />
71 $params['html_snippets'][$this->name] = $result;
73 $params['transparent_redirect_urls'][$this->name] = util_make_url('/plugins/authhttpd/post-login.php?return_to='.htmlspecialchars(stripslashes($return_to)));
77 * Is there a valid session?
78 * @param unknown_type $params
80 function checkAuthSession(&$params) {
81 $this->saved_user = NULL;
84 if (isset($GLOBALS['REMOTE_USER'])) {
85 $username = $GLOBALS['REMOTE_USER'];
91 $user = user_get_object_by_name($username);
94 // TODO : shouldn't this part be factorized as it seems quite common for many plugins ?
96 if ($this->isSufficient()) {
97 $this->saved_user = $user;
98 $params['results'][$this->name] = FORGE_AUTH_AUTHORITATIVE_ACCEPT;
101 $params['results'][$this->name] = FORGE_AUTH_NOT_AUTHORITATIVE;
104 if ($this->isRequired()) {
105 $params['results'][$this->name] = FORGE_AUTH_AUTHORITATIVE_REJECT;
107 $params['results'][$this->name] = FORGE_AUTH_NOT_AUTHORITATIVE;
113 * What GFUser is logged in?
114 * @param unknown_type $params
116 function fetchAuthUser(&$params) {
117 if ($this->saved_user && $this->isSufficient()) {
118 $params['results'] = $this->saved_user;
122 function closeAuthSession($params) {
123 // No way to close an HTTPD session from the server, unfortunately
130 // c-file-style: "bsd"