diff --git a/Auth/ReverseProxyLdapAuth.php b/Auth/ReverseProxyLdapAuth.php index 466f761..387a2d5 100644 --- a/Auth/ReverseProxyLdapAuth.php +++ b/Auth/ReverseProxyLdapAuth.php @@ -63,4 +63,19 @@ public function authenticate() return false; } + + /** + * Check if the user session is valid + * + * @access public + * @return boolean + */ + public function isValidSession() + { + if (LDAP_USERNAME_CASE_SENSITIVE) { + return $this->request->getRemoteUser() === $this->userSession->getUsername(); + } + + return strtolower($this->request->getRemoteUser()) === strtolower($this->userSession->getUsername()); + } } diff --git a/Plugin.php b/Plugin.php index c440e92..27dde1c 100644 --- a/Plugin.php +++ b/Plugin.php @@ -30,7 +30,7 @@ public function getPluginAuthor() public function getPluginVersion() { - return '1.0.0'; + return '1.0.1'; } public function getPluginHomepage() diff --git a/Test/ReverseProxyLdapAuthTest.php b/Test/ReverseProxyLdapAuthTest.php new file mode 100644 index 0000000..c858055 --- /dev/null +++ b/Test/ReverseProxyLdapAuthTest.php @@ -0,0 +1,36 @@ +container['request'] = $this + ->getMockBuilder('\Kanboard\Core\Http\Request') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('getRemoteUser')) + ->getMock(); + + $this->container['userSession'] = $this + ->getMockBuilder('\Kanboard\Core\User\UserSession') + ->setConstructorArgs(array($this->container)) + ->setMethods(array('getUsername')) + ->getMock(); + + $this->container['request'] + ->expects($this->once()) + ->method('getRemoteUser') + ->will($this->returnValue('MyUser')); + + $this->container['userSession'] + ->expects($this->once()) + ->method('getUsername') + ->will($this->returnValue('myuser')); + + $provider = new ReverseProxyLdapAuth($this->container); + $this->assertTrue($provider->isValidSession()); + } +}