ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
class.ilAuthApache.php
Go to the documentation of this file.
1 <?php
2 /*
3  +-----------------------------------------------------------------------------+
4  | ILIAS open source |
5  +-----------------------------------------------------------------------------+
6  | Copyright (c) 1998-2001 ILIAS open source, University of Cologne |
7  | |
8  | This program is free software; you can redistribute it and/or |
9  | modify it under the terms of the GNU General Public License |
10  | as published by the Free Software Foundation; either version 2 |
11  | of the License, or (at your option) any later version. |
12  | |
13  | This program is distributed in the hope that it will be useful, |
14  | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15  | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16  | GNU General Public License for more details. |
17  | |
18  | You should have received a copy of the GNU General Public License |
19  | along with this program; if not, write to the Free Software |
20  | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
21  +-----------------------------------------------------------------------------+
22 */
23 
24 define ('APACHE_AUTH_TYPE_DIRECT_MAPPING', 1);
25 define ('APACHE_AUTH_TYPE_EXTENDED_MAPPING', 2);
26 define ('APACHE_AUTH_TYPE_BY_FUNCTION', 3);
27 
35 class ilAuthApache extends Auth
36 {
38 
44  public function supportsRedirects()
45  {
46  return true;
47  }
48 
55  public function __construct($a_container,$a_addition_options = array())
56  {
57  global $lng;
58 
59  parent::__construct($a_container,$a_addition_options,'',false);
60  $this->setSessionName("_authhttp".md5(CLIENT_ID));
61 
62  $this->apache_settings = new ilSetting('apache_auth');
63 
64  if (defined('IL_CERT_SSO') && IL_CERT_SSO) {
65  // DO NOT DELETE!!!
66  // faking post values is REQUIRED to avoid canceling of the
67  // startup routines
68  // $_POST['username'] = 'xxx';
69  $_POST['password'] = 'yyy';
70  $_POST['sendLogin'] = '1';
71  $_POST['auth_mode'] = AUTH_APACHE;
72  $_POST['cmd[butSubmit]'] = 'Submit';
73 
74  if ($_POST['username'] != 'anonymous') {
75 
76  switch($this->apache_settings->get('apache_auth_username_config_type'))
77  {
79  $_POST['username'] = $_SERVER[$this->apache_settings->get('apache_auth_username_direct_mapping_fieldname')];
80  break;
82  throw new ilException("APACHE_AUTH_TYPE_EXTENDED_MAPPING not yet implemented");
84  include_once 'Services/AuthApache/classes/custom_username_func.php';
85  $_POST['username'] = ApacheCustom::getUsername();
86  break;
87  }
88 
89  }
90  }
91 
92  if (defined('IL_CERT_SSO') && IL_CERT_SSO && !$_POST['username']) {
93  $_POST['username'] = '§invalid';
94  $_POST['password'] = 'anonymous';
95  $_SESSION['username_invalid'] = true;
96  }
97 
98  $this->initAuth();
99  }
100 
101 
102  public function login() {
103  $skipClasses = array('ilpasswordassistancegui', 'ilaccountregistrationgui');
104  $skipFiles = array('pwassist.php');
105  if(in_array(strtolower($_REQUEST['cmdClass']), $skipClasses))
106  {
107  return;
108  }
109  else
110  {
111  $script = pathinfo($_SERVER['PHP_SELF'], PATHINFO_BASENAME);
112  if(in_array(strtolower($script), $skipFiles))
113  return;
114  }
115  if(
116  !$this->apache_settings->get('apache_auth_authenticate_on_login_page') &&
117  (
118  preg_match('/.*login\.php$/', $_SERVER['SCRIPT_NAME']) ||
119  ((in_array($_REQUEST['cmd'], array('showLogin', 'showTermsOfService')) || isset($_POST['change_lang_to'])) && strtolower($_REQUEST['cmdClass']) == 'ilstartupgui')
120  )
121  )
122  {
123  return;
124  }
125 
126  if(!$this->apache_settings->get('apache_auth_authenticate_on_login_page') && preg_match('/.*login\.php$/', $_SERVER['SCRIPT_NAME']))
127  {
128  return;
129  }
130 
131  if (ilContext::supportsRedirects() && !isset($_GET['passed_sso']) && (!defined('IL_CERT_SSO') || IL_CERT_SSO == false)) {
132 
133  // redirect to sso
134  // this part is executed in default ilias context...
135 
136  $path = $_SERVER['REQUEST_URI'];
137 
138  if ($path{0} == '/') {
139  $path = substr($path, 1);
140  }
141 
142  if (substr($path, 0, 4) != 'http') {
143  $parts = parse_url(ILIAS_HTTP_PATH);
144  $path = $parts['scheme'] . '://' . $parts['host'] . '/' . $path;
145  }
146 
147  $path = urlencode($path);
148  ilUtil::redirect(ilUtil::getHtmlPath('/sso/index.php?force_mode_apache=1&r=' . $path . '&cookie_path='.IL_COOKIE_PATH . '&ilias_path=' . ILIAS_HTTP_PATH));
149  }
150  else {
151  return parent::login();
152  }
153  }
154 }