/** * @param string $accessRight * * @return bool * @throws \Exception */ public function check($accessRight) { if (!$this->sessionManager->isLoggedIn()) { return false; } $accessRightRequester = $this->sessionManager->getCurrentUser(); if (!$accessRightRequester instanceof IAccessRightRequester) { throw new CurrentLoggedUserNotImplementAccessRightRequesterException(self::USER_IS_NOT_A_CORRECT_ACCESS_RIGHT_REQUESTER); } $userRoles = $accessRightRequester->getRoles(); foreach ($userRoles as $roleName) { $roles = $this->rolesConfig->getRoles(); if ($roles == null || !array_key_exists($roleName, $roles)) { return false; } $role = $roles[$roleName]; $roleAccessRights = $role->getAccessRights(); if (in_array(self::All_ACCESS_RIGHTS, $roleAccessRights) || in_array($accessRight, $role->getAccessRights())) { return true; } } return false; }
/** * @expectedException \Exception * @expectedExceptionMessage Sessions are disabled! */ function testGetCurrentUserThrowsExceptionWhenDisabledSessions() { $this->session->expects($this->any())->method('getStatus')->willReturn(PHP_SESSION_DISABLED); $this->sessionManager->getCurrentUser(); }