Solution: How to provide for Intranet IP Based Authentication

Table of contents:

This is compatible with eZ Publish 3.

About

It is _not_ recommended to change the kernel, because upgrades will be much harder. But if you really want to do it, this is how.

Special Thanks to participants: Andy Masiar, Bjorn Dieding, Mark Marsiglio, Kristian Hole

References:Intranet IP Based Authentication

Dated: 2005/10/30 18:26

Question

Is it possible to authenticate users based on their IP?

Answer

There is a patch for login based on IP.

This is made for only one user, but you get the idea of how to do it.

This patch gets the IP address and the corresponding user from the site.ini.append.php file. (Patch is for 3.5.1)

--- ezpublish_releases/ezpublish-3.5.1/pre_check.php     2005-02-24 12:05:54.000000000 +0100
+++ precheck_fixedfor351.php    2005-03-09 09:26:30.999605632 +0100
@@ -89,6 +89,19 @@
 //     $uri =& $GLOBALS['eZRequestedURI'];
     $check = array( "module" => "user",
                     "function" => "login" );
+
+       //---LoginOnIP-HACK
+    if ( $ini->hasVariable( 'LoginOnIP', 'IPAddress' ) && $ini->hasVariable( 'LoginOnIP', 'UserID' )
+         && $_SERVER['REMOTE_ADDR'] == $ini->variable( 'LoginOnIP', 'IPAddress' ) )
+    {
+        include_once( 'kernel/classes/datatypes/ezuser/ezuser.php' );
+
+        $userID = ( int ) $ini->variable( 'LoginOnIP', 'UserID' );
+        $user = eZUser::fetch( $userID );
+        eZUser::setCurrentlyLoggedInUser( $user, $userID );
+    }
+       //---LoginOnIP-HACK
+
     if ( $http->hasSessionVariable( "eZUserLoggedInID" ) and
          $http->sessionVariable( "eZUserLoggedInID" ) != '' and
          $http->sessionVariable( "eZUserLoggedInID" ) != $ini->variable( 'UserSettings', 'AnonymousUserID' ) )
@@ -173,4 +186,4 @@
 }

References

  • N/A