Laravel AUTH过滤器生产服务器上失败 [英] Laravel auth filter fails on production server

查看:162
本文介绍了Laravel AUTH过滤器生产服务器上失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Laravel 4框架与标准的内置验证支持。在当地的环境一切正常尼斯(MAMP,OSX),但我的生产服务器(数字海洋标准图像与Ubuntu,Apache的,PHP 5.5.9)上将auth过滤器发生故障,并允许无需验证访问。

routes.php文件:

 路线::组(['之前'=>'权威性'],函数(){
    路线::获得(管理员,阵列('用途'=>'AdminController @家'));
    路线::获得(管理/仪表盘,函数(){
        返回重定向到::('管理员');
    });    路线::后('支付/ OK,阵列('使用'=>'PaymentController @ OK'));
    路线::后(付款/不合格,阵列('使用'=>'PaymentController @失败'));
    路线::获得(管理/ makeDMS /(编号),阵列('使用'=>'PaymentController @ makeDMStransaction'));
    路线::获得(管理/产品',阵列('用途'=>'AdminController @产品'));
    路线::获得(管理/产品/ {ID},阵​​列('使用'=>'AdminController @产品'));
    路线::获得(管理/订单',阵列('用途'=>'AdminController @订单'));
    路线::获得(管理/顺序/(编号),阵列('使用'=>'AdminController @为了'));
    路线::后(管理/ setOrderStatus',阵列('用途'=>'AdminController @ setOrderStatus'));
    路线::后(管理/ UpdateProduct中',阵列('用途'=>'AdminController @的UpdateProduct'));
    路线::获得(管理/交易,阵列('用途'=>'AdminController @交易'));
});

filters.php:

 路线::过滤器('权威性',函数()
{
    如果(AUTH ::客())
    {
        如果(支持::阿贾克斯())
        {
            返回响应::使(未授权,401);
        }
        其他
        {
            返回重定向::客('登录');
        }
    }
});
路线::过滤器('auth.basic',函数()
{
    返回验证::基本的();
});路线::过滤器('客人',函数()
{
    如果(AUTH ::检查())返回重定向到::('/');
});

我试图保护所需的线路都与路线::组,并在控制器的构造函数,但输出是一样的:具有良好的凭据登录工作,用户凭据不好无法登录,但路线组应该要保护可用于未经授权的用户。

我发现PHP的快速CGI模式可能会产生这样的行为,但这里是我的须藤apachectl中-M 输出:

 加载模块:
 core_module(静态)
 so_module(静态)
 watchdog_module(静态)
 http_module(静态)
 log_config_module(静态)
 logio_module(静态)
 version_module(静态)
 unixd_module(静态)
 access_compat_module(共享)
 alias_module(共享)
 auth_basic_module(共享)
 authn_core_module(共享)
 authn_file_module(共享)
 authz_core_module(共享)
 authz_host_module(共享)
 authz_user_module(共享)
 autoindex_module(共享)
 deflate_module(共享)
 dir_module(共享)
 env_module(共享)
 filter_module(共享)
 mime_module(共享)
 mpm_ prefork_module(共享)
 negotiation_module(共享)
 php5_module(共享)
 rewrite_module(共享)
 setenvif_module(共享)
 status_module(共享)


解决方案

好吧,我找到了解决办法。与往常一样,RTFM ...

我的环境被设置为测试,这是保留的单元测试,并手动很好地说:


  

请注意:路由过滤器是在测试环境中时被禁止。至
  启用它们,添加路由:: enableFilters()来测试。


我改为生产,现在一切的伟大工程的环境变量。

I'm using Laravel 4 framework with standard built-in Auth support. In local environment everything works nice (MAMP, OSx), but on my production server (Digital Ocean standard image with Ubuntu, Apache, Php 5.5.9) auth filter fails and allows access without authentication.

routes.php:

Route::group(['before'=>'auth'], function(){
    Route::get('admin', array('uses' => 'AdminController@home'));
    Route::get('admin/dashboard', function(){
        return Redirect::to('admin');
    });

    Route::post('payment/ok', array('uses' => 'PaymentController@ok'));
    Route::post('payment/fail', array('uses' => 'PaymentController@fail'));
    Route::get('admin/makeDMS/{id}', array('uses' => 'PaymentController@makeDMStransaction'));
    Route::get('admin/products', array('uses' => 'AdminController@products'));
    Route::get('admin/product/{id}', array('uses' => 'AdminController@product'));
    Route::get('admin/orders', array('uses' => 'AdminController@orders'));
    Route::get('admin/order/{id}', array('uses' => 'AdminController@order'));
    Route::post('admin/setOrderStatus', array('uses' => 'AdminController@setOrderStatus'));
    Route::post('admin/updateProduct', array('uses' => 'AdminController@updateProduct'));
    Route::get('admin/transactions', array('uses' => 'AdminController@transactions'));  
});

filters.php:

Route::filter('auth', function()
{
    if (Auth::guest())
    {
        if (Request::ajax())
        {
            return Response::make('Unauthorized', 401);
        }
        else
        {
            return Redirect::guest('login');
        }
    }
});


Route::filter('auth.basic', function()
{
    return Auth::basic();
});

Route::filter('guest', function()
{
    if (Auth::check()) return Redirect::to('/');
});

I tried to protect desired routes both with Route::group and in controller constructor, but the output is the same: login with good credentials works, users with bad credentials can't login, but routes group which should be protected are available for unauthenticated users.

I found that php in fast CGI mode could produce such behavior, but here is my sudo apachectl -M output:

Loaded Modules:
 core_module (static)
 so_module (static)
 watchdog_module (static)
 http_module (static)
 log_config_module (static)
 logio_module (static)
 version_module (static)
 unixd_module (static)
 access_compat_module (shared)
 alias_module (shared)
 auth_basic_module (shared)
 authn_core_module (shared)
 authn_file_module (shared)
 authz_core_module (shared)
 authz_host_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 deflate_module (shared)
 dir_module (shared)
 env_module (shared)
 filter_module (shared)
 mime_module (shared)
 mpm_prefork_module (shared)
 negotiation_module (shared)
 php5_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 status_module (shared)

解决方案

Ok, I found the solution. As always, RTFM...

My environment was set as "testing" which is reserved for Unit Testing, and the manual nicely says:

Note: Route filters are disabled when in the testing environment. To enable them, add Route::enableFilters() to your test.

I changed the environment variable to "production" and now everything works great.

这篇关于Laravel AUTH过滤器生产服务器上失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆