19 include_once (
'WHAT/Lib.Common.php');
20 include_once (
'WHAT/Class.Authenticator.php');
21 include_once (
'WHAT/Class.Session.php');
22 include_once (
'WHAT/Class.User.php');
23 include_once (
'WHAT/Class.Log.php');
45 public static function checkAccess($authtype = null, $noask =
false)
50 $status = self::checkAuthentication($authtype, $noask);
54 if ($providerErrno != 0) {
55 self::$provider_errno = $providerErrno;
56 switch ($providerErrno) {
59 $error = self::AccessBug;
63 $remote_addr = isset(
$_SERVER[
"REMOTE_ADDR"]) ?
$_SERVER[
"REMOTE_ADDR"] :
"";
64 $auth_user = isset($_REQUEST[
"auth_user"]) ? $_REQUEST[
"auth_user"] :
"";
65 $http_user_agent = isset(
$_SERVER[
"HTTP_USER_AGENT"]) ?
$_SERVER[
"HTTP_USER_AGENT"] :
"";
66 self::secureLog(
"failure",
"invalid credential",
self::$auth->provider->parms[
'type'] .
"/" .
self::$auth->provider->parms[
'provider'], $remote_addr, $auth_user, $http_user_agent);
68 if (
getParam(
"AUTHENT_FAILURECOUNT") > 0) {
70 if ($wu->SetLoginName(
self::$auth->getAuthUser())) {
72 include_once (
"FDL/freedom_util.php");
78 $du->disableEditControl();
79 $du->increaseLoginFailure();
80 $du->enableEditControl();
92 $ret = self::checkAuthorization();
93 if (
$ret !== self::AccessOk) {
101 if (method_exists(
self::$auth,
'getAuthSession')) {
106 if (self::$session->read(
'username') ==
"") {
107 self::secureLog(
"failure",
"username should exists in session", $authprovider =
"",
$_SERVER[
"REMOTE_ADDR"],
$login,
$_SERVER[
"HTTP_USER_AGENT"]);
113 return self::AccessOk;
118 self::$provider_errno = 0;
123 foreach ($authProviderList as $authProvider) {
124 self::$auth = static::getAuthenticatorClass($authtype, $authProvider);
128 return self::NeedAsk;
147 if (!preg_match(
'/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $authtype)) {
148 throw new \Dcp\Exception(sprintf(
"Invalid authtype '%s'", $authtype));
151 $authClass = strtolower($authtype) .
"Authenticator";
152 if (!\Dcp\Autoloader::classExists($authClass)) {
153 throw new \Dcp\Exception(sprintf(
"Cannot find authenticator '%s'", $authtype));
155 return new $authClass($authtype, $provider);
164 if ($freedom_authprovider ==
"") {
165 $freedom_authprovider =
"html";
168 return trim($freedom_authprovider);
180 if (array_key_exists(
'authtype',
$_GET)) {
181 if (
$_GET[
'authtype'] ===
"apache") {
182 throw new \Dcp\Exception(sprintf(
"apache authtype not allowed.\n"));
184 return $_GET[
'authtype'];
186 if (!empty(
$_GET[OpenAuthenticator::openGetId])) {
190 $scheme = self::getAuthorizationScheme();
193 case OpenAuthenticator::openAuthorizationScheme:
195 case \basicAuthenticator::basicAuthorizationScheme:
198 throw new Exception(sprintf(
"Invalid authorization method \"%s\"", $scheme));
204 if ($freedom_authtype ==
"") {
205 $freedom_authtype =
"html";
208 return trim($freedom_authtype);
213 if (php_sapi_name() !==
'cli') {
214 $headers = apache_request_headers();
215 if (!empty($headers[
"Authorization"])) {
216 $hAuthorization = $headers[
"Authorization"];
217 } elseif (!empty($headers[
"authorization"])) {
218 $hAuthorization = $headers[
"authorization"];
220 if (!empty($hAuthorization)) {
221 if (preg_match(
"/^([a-z0-9]+)\\s+(.*)$/i", $hAuthorization, $reg)) {
222 return trim($reg[1]);
237 self::secureLog(
"close",
"see you tomorrow");
243 header(
'HTTP/1.0 500 Internal Error');
255 header(
'WWW-Authenticate: Basic realm="' .
getParam(
"CORE_REALM",
"Dynacase Platform connection") .
'"');
256 header(
'HTTP/1.0 401 Unauthorized');
257 echo _(
"Vous devez entrer un nom d'utilisateur valide et un mot de passe correct pour acceder a cette ressource");
261 public static function secureLog(
$status =
"", $additionalMessage =
"", $provider =
"", $clientIp =
"",
$account =
"", $userAgent =
"")
264 $log =
new Log(
"",
"Session",
"Authentication");
265 $facility = constant(
getParam(
"AUTHENT_LOGFACILITY",
"LOG_AUTH"));
266 $log->wlog(
"S", sprintf(
"[%s] [%s] [%s] [%s] [%s] [%s]",
$status, $additionalMessage, $provider, $clientIp,
$account, $userAgent) , NULL, $facility);
292 if (!isset($provider->PROTOCOL_VERSION)) {
295 return $provider->PROTOCOL_VERSION;
308 if ($wu->SetLoginName(
$login)) {
317 $protoVersion = self::_getProviderProtocolVersion(
self::$auth->provider);
318 if (!is_integer($protoVersion)) {
319 throw new \Dcp\Exception(sprintf(
"Invalid provider protocol version '%s' for provider '%s'.", $protoVersion, get_class(
self::$auth->provider)));
322 switch ($protoVersion) {
324 return self::protocol_0_authorization(array(
330 throw new \Dcp\Exception(sprintf(
"Unsupported provider protocol version '%s' for provider '%s'.", $protoVersion, get_class(
self::$auth->provider)));
338 private static function protocol_0_authorization($opt)
340 $authz = self::checkProviderAuthorization($opt);
341 if ($authz !== self::AccessOk) {
344 return self::checkDynacaseAuthorization($opt);
352 private static function checkProviderAuthorization($opt)
355 if ($authz ===
true) {
356 return self::AccessOk;
358 return self::AccessNotAuthorized;
367 private static function checkDynacaseAuthorization($opt)
369 $login = $opt[
'username'];
370 $wu = $opt[
'dcp_account'];
373 include_once (
"FDL/freedom_util.php");
379 if (!$du->isAccountActive()) {
385 if ($du->accountHasExpired()) {
391 $maxfail =
getParam(
"AUTHENT_FAILURECOUNT");
392 if ($maxfail > 0 && $du->getRawValue(
"us_loginfailure", 0) >= $maxfail) {
398 $du->disableEditControl();
399 $du->resetLoginFailure();
400 $du->enableEditControl();
static checkAuthentication($authtype=null, $noask=false)
static checkAuthorization()
static secureLog($status="", $additionalMessage="", $provider="", $clientIp="", $account="", $userAgent="")
getDbAccessValue($varName)
if(ActionRouter::inMaintenance()) $auth
static getAuthenticatorClass($authtype=null, $provider=Authenticator::nullProvider)
getAuthProvider($freedomctx="")
const AccessHasNoLocalAccount
static getAuthProviderList()
static getAuthorizationScheme()
getParam($name, $def="")
must be in core or global type
getAuthType($freedomctx="")
static _getProviderProtocolVersion(Provider $provider)
const AccessMaxLoginFailure
const AccessNotAuthorized
new_Doc($dbaccess, $id= '', $latest=false)
const AccessAccountHasExpired
const AccessAccountIsNotActive
getAuthProviderList($freedomctx="")