This commit is contained in:
21
api/app/Http/Middleware/Authenticate.php
Normal file
21
api/app/Http/Middleware/Authenticate.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Auth\Middleware\Authenticate as Middleware;
|
||||
|
||||
class Authenticate extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the path the user should be redirected to when they are not authenticated.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return string|null
|
||||
*/
|
||||
protected function redirectTo($request)
|
||||
{
|
||||
if (! $request->expectsJson()) {
|
||||
return route('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
28
api/app/Http/Middleware/Customer.php
Normal file
28
api/app/Http/Middleware/Customer.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class Customer
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$customer = $request->header('customer');
|
||||
|
||||
if (is_null($customer)) {
|
||||
return response()->json(['error' => 'O cliente deve ser informado.'], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
17
api/app/Http/Middleware/EncryptCookies.php
Normal file
17
api/app/Http/Middleware/EncryptCookies.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Cookie\Middleware\EncryptCookies as Middleware;
|
||||
|
||||
class EncryptCookies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the cookies that should not be encrypted.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
46
api/app/Http/Middleware/Gate.php
Normal file
46
api/app/Http/Middleware/Gate.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Models\Administracao\Permissao;
|
||||
use App\Models\Cadastro\SujeitoAtencao\Lotacao;
|
||||
use Closure;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Gate as BaseGate;
|
||||
|
||||
class Gate
|
||||
{
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
try {
|
||||
DB::table('administracao_endpoint_acao')
|
||||
->select(
|
||||
'administracao_permissao.id',
|
||||
'administracao_modulo.identificador as modulo_identificador',
|
||||
'administracao_funcionalidade.identificador as funcionalidade_identificador',
|
||||
'administracao_endpoint_acao.nome as acao_nome',
|
||||
)
|
||||
->join('administracao_permissao', 'administracao_permissao.id', 'administracao_endpoint_acao.permissao_id')
|
||||
->join('administracao_funcionalidade', 'administracao_funcionalidade.id', 'administracao_permissao.funcionalidade_id')
|
||||
->join('administracao_modulo', 'administracao_modulo.id', 'administracao_funcionalidade.modulo_id')
|
||||
->get()
|
||||
->each(function($permissao) {
|
||||
$gateName = "{$permissao->acao_nome}-{$permissao->modulo_identificador}-{$permissao->funcionalidade_identificador}";
|
||||
|
||||
BaseGate::define($gateName, function () use ($permissao) {
|
||||
|
||||
$lotacao = Lotacao::find(auth()->payload()->get('lotacao_id'));
|
||||
|
||||
return $lotacao->hasPermissao(Permissao::find($permissao->id));
|
||||
});
|
||||
});
|
||||
}
|
||||
catch (Exception $error) {
|
||||
// TODO: Verificar qual exception é lançada e fazer o tratamento dos erros.
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
29
api/app/Http/Middleware/Guard.php
Normal file
29
api/app/Http/Middleware/Guard.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class Guard
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, $guard = null)
|
||||
{
|
||||
if (!is_null($guard)) {
|
||||
|
||||
config(['auth.defaults.guard' => $guard]);
|
||||
config(['jwt.secret' => config("jwt.keys.{$guard}")]);
|
||||
|
||||
app('tymon.jwt.provider.jwt')->setSecret(config('jwt.secret'));
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
17
api/app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
17
api/app/Http/Middleware/PreventRequestsDuringMaintenance.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance as Middleware;
|
||||
|
||||
class PreventRequestsDuringMaintenance extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be reachable while maintenance mode is enabled.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
//
|
||||
];
|
||||
}
|
||||
32
api/app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
32
api/app/Http/Middleware/RedirectIfAuthenticated.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use App\Providers\RouteServiceProvider;
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class RedirectIfAuthenticated
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @param string|null ...$guards
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next, ...$guards)
|
||||
{
|
||||
$guards = empty($guards) ? [null] : $guards;
|
||||
|
||||
foreach ($guards as $guard) {
|
||||
if (Auth::guard($guard)->check()) {
|
||||
return redirect(RouteServiceProvider::HOME);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
40
api/app/Http/Middleware/SetClienteDatabase.php
Normal file
40
api/app/Http/Middleware/SetClienteDatabase.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Config;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use App\Models\Intranet\Cliente;
|
||||
use App\Enums\Intranet\Sistema;
|
||||
|
||||
class SetClienteDatabase
|
||||
{
|
||||
public function handle(Request $request, Closure $next): Response
|
||||
{
|
||||
$link = $request->customer ?? $request->header('X-Cliente');
|
||||
|
||||
if (!$link) {
|
||||
return response()->json(['message' => 'Cliente não informado.'], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$cliente = Cliente::where('sistema_id', Sistema::CONECTASUS)
|
||||
->where('link', $link)
|
||||
->first();
|
||||
|
||||
if (!$cliente) {
|
||||
return response()->json(['message' => 'Cliente não encontrado.'], Response::HTTP_NOT_FOUND);
|
||||
}
|
||||
|
||||
if ($cliente->ativo === false) {
|
||||
return response()->json(['message' => 'O cliente está com o status inativo.'], Response::HTTP_UNAUTHORIZED);
|
||||
}
|
||||
|
||||
Config::set('database.default', $cliente->link);
|
||||
|
||||
$request->attributes->set('cliente', $cliente);
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
18
api/app/Http/Middleware/TrimStrings.php
Normal file
18
api/app/Http/Middleware/TrimStrings.php
Normal file
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\TrimStrings as Middleware;
|
||||
|
||||
class TrimStrings extends Middleware
|
||||
{
|
||||
/**
|
||||
* The names of the attributes that should not be trimmed.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
'password',
|
||||
'password_confirmation',
|
||||
];
|
||||
}
|
||||
20
api/app/Http/Middleware/TrustHosts.php
Normal file
20
api/app/Http/Middleware/TrustHosts.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Http\Middleware\TrustHosts as Middleware;
|
||||
|
||||
class TrustHosts extends Middleware
|
||||
{
|
||||
/**
|
||||
* Get the host patterns that should be trusted.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function hosts()
|
||||
{
|
||||
return [
|
||||
$this->allSubdomainsOfApplicationUrl(),
|
||||
];
|
||||
}
|
||||
}
|
||||
23
api/app/Http/Middleware/TrustProxies.php
Normal file
23
api/app/Http/Middleware/TrustProxies.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Fideloper\Proxy\TrustProxies as Middleware;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TrustProxies extends Middleware
|
||||
{
|
||||
/**
|
||||
* The trusted proxies for this application.
|
||||
*
|
||||
* @var array|string|null
|
||||
*/
|
||||
protected $proxies;
|
||||
|
||||
/**
|
||||
* The headers that should be used to detect proxies.
|
||||
*
|
||||
* @var int
|
||||
*/
|
||||
protected $headers = Request::HEADER_X_FORWARDED_ALL;
|
||||
}
|
||||
68
api/app/Http/Middleware/VerifyCsrfToken.php
Normal file
68
api/app/Http/Middleware/VerifyCsrfToken.php
Normal file
@@ -0,0 +1,68 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as Middleware;
|
||||
|
||||
class VerifyCsrfToken extends Middleware
|
||||
{
|
||||
/**
|
||||
* The URIs that should be excluded from CSRF verification.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $except = [
|
||||
// Impressão.
|
||||
'/impressao/administracao/relatorio-papel-lotacao',
|
||||
'/impressao/administracao/relatorio-permissao-lotacao',
|
||||
'/impressao/administracao/relatorio-permissao-papel',
|
||||
'/impressao/almoxarifado/*',
|
||||
'/impressao/ambulatorio/encaminhamento/*',
|
||||
'/impressao/ambulatorio/encaminhamento-hospitalar/*',
|
||||
'/impressao/ambulatorio/ficha-requisicao-servico-auxiliar-diagnose-terapia/*',
|
||||
'/impressao/ambulatorio/geral/*',
|
||||
'/impressao/ambulatorio/laudo-solicitacao-autorizacao-procedimento-ambulatorial/*',
|
||||
'/impressao/ambulatorio/receita-medica-comum/*',
|
||||
'/impressao/ambulatorio/receita-medica-especial-amarela/*',
|
||||
'/impressao/ambulatorio/receita-medica-especial-azul/*',
|
||||
'/impressao/ambulatorio/receita-medica-especial/*',
|
||||
'/impressao/ambulatorio/laudo-medicamento/*',
|
||||
'/impressao/ambulatorio/receita-medica-nao-padronizada-comum/*',
|
||||
'/impressao/ambulatorio/receita-medica-nao-padronizada-especial/*',
|
||||
'/impressao/ambulatorio/relatorio-quantitativo-atendimento',
|
||||
'/impressao/ambulatorio/listagem-consulta-agendada-realizada',
|
||||
'/impressao/ambulatorio/servico-analise-diagnostico-terapia-solicitacao-exame/*',
|
||||
'/impressao/atencao-basica/relatorio-estatistico-paciente-cadastrado',
|
||||
'/impressao/exame-imagem/relatorio-exame-status',
|
||||
'/impressao/exame-imagem/relatorio-exame-status',
|
||||
'/impressao/exame-laboratorial/relatorio-coleta-agendada',
|
||||
'/impressao/exame-laboratorial/relatorio-financeiro-paciente',
|
||||
'/impressao/integracao/*',
|
||||
'/impressao/pronto-atendimento/relatorio-atendimento',
|
||||
'/impressao/regulacao/relatorio-solicitacao',
|
||||
'/impressao/exame-imagem/relatorio-exame-status',
|
||||
'/impressao/almoxarifado/*',
|
||||
'/impressao/atencao-basica/relatorio-cuidado-desenvolvimento-infantil',
|
||||
'/impressao/atencao-basica/relatorio-visita-domiciliar',
|
||||
'/impressao/regulacao/fila',
|
||||
'/impressao/atencao-basica/relatorio-atividade-coletiva',
|
||||
|
||||
// Exportação.
|
||||
'/exportacao/administracao/relatorio-papel-lotacao',
|
||||
'/exportacao/administracao/relatorio-permissao-lotacao',
|
||||
'/exportacao/administracao/relatorio-permissao-papel',
|
||||
'/exportacao/ambulatorio/relatorio-quantitativo-atendimento',
|
||||
'/exportacao/atencao-basica/relatorio-estatistico-paciente-cadastrado',
|
||||
'/exportacao/exame-imagem/export-exame-status',
|
||||
'/exportacao/exame-laboratorial/relatorio-financeiro-paciente',
|
||||
'/exportacao/integracao/*',
|
||||
'/exportacao/pronto-atendimento/export-atendimento',
|
||||
'/exportacao/regulacao/relatorio-solicitacao',
|
||||
'/exportacao/atencao-basica/relatorio-cuidado-desenvolvimento-infantil',
|
||||
'/exportacao/atencao-basica/relatorio-visita-domiciliar',
|
||||
'/exportacao/regulacao/fila',
|
||||
'/exportacao/atencao-basica/relatorio-atividade-coletiva',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
29
api/app/Http/Middleware/VerifyTokenParameters.php
Normal file
29
api/app/Http/Middleware/VerifyTokenParameters.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Middleware;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class VerifyTokenParameters
|
||||
{
|
||||
/**
|
||||
* Handle an incoming request.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \Closure $next
|
||||
* @return mixed
|
||||
*/
|
||||
public function handle(Request $request, Closure $next)
|
||||
{
|
||||
$requestCustomer = $request->header('customer');
|
||||
$tokenCustomer = auth()->payload()->get('customer');
|
||||
|
||||
if ($requestCustomer !== $tokenCustomer) {
|
||||
return response()->json(['error' => 'O token informado é inválido.'], Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user