Fixed SSL redirect filter

fixed ssl filter and added some config examples

Change-Id: I90ab6d108e13d495dc12fde4fe8a4433b93a0a1f
This commit is contained in:
Sebastian Marcet 2016-02-22 12:14:50 -03:00
parent 5485d902e9
commit 33526e903d
7 changed files with 85 additions and 116 deletions

View File

@ -41,12 +41,15 @@ CORS_USE_PRE_FLIGHT_CACHING=true
CORS_MAX_AGE=3200 CORS_MAX_AGE=3200
CORS_EXPOSED_HEADERS= CORS_EXPOSED_HEADERS=
CURL_TIMEOUT=60 CURL_TIMEOUT=3600
CURL_ALLOWS_REDIRECT=false CURL_ALLOWS_REDIRECT=false
CURL_VERIFY_SSL_CERT=true CURL_VERIFY_SSL_CERT=false
SSL_ENABLED=false
OAUTH2_ENABLED=true
DB_LOG_ENABLED=false
ASSETS_BASE_URL=http://www.openstack.org ASSETS_BASE_URL=http://www.openstack.org
API_RESPONSE_CACHE_LIFETIME=10000 SSL_ENABLED=true
DB_LOG_ENABLED=true
ACCESS_TOKEN_CACHE_LIFETIME=300
API_RESPONSE_CACHE_LIFETIME=600
LOG_EMAIL_TO=smarcet@gmail.com
LOG_EMAIL_FROM=smarcet@gmail.com

View File

@ -1,52 +0,0 @@
APP_ENV=testing
APP_DEBUG=true
APP_KEY=KKzP6APRNHmADURQ8OanDTU5kDpGwo6l
APP_URL=https://local.resource-server.openstack.org
APP_OAUTH_2_0_CLIENT_ID=tM9iYEq2iCP6P5WQL.~Zo2XXLbugpNhu.openstack.client
APP_OAUTH_2_0_CLIENT_SECRET=f70Ydbhq9NernTem4Yow8SEB
APP_OAUTH_2_0_AUTH_SERVER_BASE_URL=https://local.openstackid.openstack.org
DB_HOST=localhost
DB_DATABASE=resource_server_test
DB_USERNAME=root
DB_PASSWORD=Koguryo@1981
SS_DB_HOST=localhost
SS_DATABASE=os_production2
SS_DB_USERNAME=root
SS_DB_PASSWORD=Koguryo@1981
REDIS_HOST=127.0.0.1
REDIS_PORT=6379
REDIS_DB=0
REDIS_PASSWORD=
CACHE_DRIVER=redis
SESSION_DRIVER=redis
SESSION_COOKIE_DOMAIN=
SESSION_COOKIE_SECURE=false
QUEUE_DRIVER=sync
MAIL_DRIVER=smtp
MAIL_HOST=mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
LOG_EMAIL_TO=
LOG_EMAIL_FROM=
CORS_ALLOWED_HEADERS=origin, content-type, accept, authorization, x-requested-with
CORS_ALLOWED_METHODS=GET, POST, OPTIONS, PUT, DELETE
CORS_USE_PRE_FLIGHT_CACHING=false
CORS_MAX_AGE=3200
CORS_EXPOSED_HEADERS=
CURL_TIMEOUT=3600
CURL_ALLOWS_REDIRECT=false
CURL_VERIFY_SSL_CERT=false
DB_LOG_ENABLED=true
ASSETS_BASE_URL=http://www.openstack.org/

View File

@ -31,6 +31,7 @@ class Kernel extends HttpKernel
'rate.limit' => 'App\Http\Middleware\RateLimitMiddleware', 'rate.limit' => 'App\Http\Middleware\RateLimitMiddleware',
'etags' => 'App\Http\Middleware\ETagsMiddleware', 'etags' => 'App\Http\Middleware\ETagsMiddleware',
'cache' => 'App\Http\Middleware\CacheMiddleware', 'cache' => 'App\Http\Middleware\CacheMiddleware',
'ssl' => 'App\Http\Middleware\SSLMiddleware',
]; ];
} }

View File

@ -0,0 +1,36 @@
<?php
/**
* Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/
namespace App\Http\Middleware;
use Closure;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\Request;
use Illuminate\Contracts\Routing\Middleware;
/**
* Class SSLMiddleware
* @package App\Http\Middleware
*/
final class SSLMiddleware implements Middleware
{
public function handle($request, Closure $next)
{
if (!Request::secure() && Config::get("server.ssl_enabled", false)) {
return Redirect::secure(Request::getRequestUri());
}
return $next($request);
}
}

View File

@ -13,12 +13,12 @@
//OAuth2 Protected API //OAuth2 Protected API
Route::group(array( Route::group(array(
'prefix' => 'api/v1', 'prefix' => 'api/v1',
'before' => ['ssl', 'oauth2.enabled'], 'before' => [],
'after' => '', 'after' => [],
'middleware' => ['oauth2.protected', 'rate.limit','etags'] 'middleware' => ['ssl', 'oauth2.protected', 'rate.limit','etags']
), function () { ), function () {
Route::group(array('prefix' => 'marketplace'), function () { Route::group(array('prefix' => 'marketplace'), function () {
Route::group(array('prefix' => 'public-clouds'), function () { Route::group(array('prefix' => 'public-clouds'), function () {
Route::get('', 'OAuth2PublicCloudApiController@getClouds'); Route::get('', 'OAuth2PublicCloudApiController@getClouds');

View File

@ -1,62 +1,44 @@
<?php namespace App\Providers; <?php namespace App\Providers;
use Illuminate\Routing\Router;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route; use Illuminate\Routing\Router;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Request;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\Facades\View;
class RouteServiceProvider extends ServiceProvider { /**
* Class RouteServiceProvider
* @package App\Providers
*/
class RouteServiceProvider extends ServiceProvider
{
/** /**
* This namespace is applied to the controller routes in your routes file. * This namespace is applied to the controller routes in your routes file.
* * In addition, it is set as the URL generator's root namespace.
* In addition, it is set as the URL generator's root namespace. * @var string
* */
* @var string protected $namespace = 'App\Http\Controllers';
*/
protected $namespace = 'App\Http\Controllers';
/** /**
* Define your route model bindings, pattern filters, etc. * Define your route model bindings, pattern filters, etc.
* * @param \Illuminate\Routing\Router $router
* @param \Illuminate\Routing\Router $router * @return void
* @return void */
*/ public function boot(Router $router)
public function boot(Router $router) {
{ parent::boot($router);
parent::boot($router); //filter should be registered here
//filter should be registered here // Route::filter('filter.name',function($route, $request){ .... });
// Route::filter('filter.name',function($route, $request){ .... }); }
Route::filter("ssl", function () { /**
if (!Request::secure() && Config::get("server.ssl_enabled", false)) * Define the routes for the application.
{ * @param \Illuminate\Routing\Router $router
return Redirect::secure(Request::getRequestUri()); * @return void
} */
}); public function map(Router $router)
{
Route::filter("oauth2.enabled", function () { $router->group(['namespace' => $this->namespace], function ($router) {
if (!Config::get("server.oauth2_enabled", true)) require app_path('Http/routes.php');
{ });
return View::make('errors.404'); }
}
});
}
/**
* Define the routes for the application.
*
* @param \Illuminate\Routing\Router $router
* @return void
*/
public function map(Router $router)
{
$router->group(['namespace' => $this->namespace], function ($router) {
require app_path('Http/routes.php');
});
}
} }

View File

@ -15,7 +15,6 @@
return array return array
( (
'ssl_enabled' => env('SSL_ENABLED', false), 'ssl_enabled' => env('SSL_ENABLED', false),
'oauth2_enabled' => env('OAUTH2_ENABLED', true),
'db_log_enabled' => env('DB_LOG_ENABLED', false), 'db_log_enabled' => env('DB_LOG_ENABLED', false),
'access_token_cache_lifetime' => env('ACCESS_TOKEN_CACHE_LIFETIME', 300), 'access_token_cache_lifetime' => env('ACCESS_TOKEN_CACHE_LIFETIME', 300),
'assets_base_url' => env('ASSETS_BASE_URL', null), 'assets_base_url' => env('ASSETS_BASE_URL', null),