Commit e5dade06114ecdb4b5238c12b657230dda58c889
1 parent
823a7f4b
Exists in
master
and in
1 other branch
[Fix] Adicionando validação de módulo ativo e compatibilidade de versão do SEI.
Showing
2 changed files
with
63 additions
and
4 deletions
Show diff stats
MdWsSeiRest.php
... | ... | @@ -8,6 +8,7 @@ |
8 | 8 | */ |
9 | 9 | class MdWsSeiRest extends SeiIntegracao |
10 | 10 | { |
11 | + const NOME_MODULO = "MdWsSeiRest"; | |
11 | 12 | |
12 | 13 | /** |
13 | 14 | * Converte os dados para UTF8 para ser compativel com json_encode |
... | ... | @@ -92,6 +93,34 @@ class MdWsSeiRest extends SeiIntegracao |
92 | 93 | { |
93 | 94 | } |
94 | 95 | |
96 | + /** | |
97 | + * Método que verifica se o módulo esta ativo nas configurações do SEI | |
98 | + */ | |
99 | + public static function moduloAtivo() | |
100 | + { | |
101 | + global $SEI_MODULOS; | |
102 | + $ativo = false; | |
103 | + foreach($SEI_MODULOS as $modulo){ | |
104 | + if($modulo instanceof self){ | |
105 | + $ativo = true; | |
106 | + break; | |
107 | + } | |
108 | + } | |
109 | + return $ativo; | |
110 | + } | |
111 | + | |
112 | + /** | |
113 | + * Retorna se é compativel com a versão atual do SEI instalado | |
114 | + * @param $strVersaoSEI | |
115 | + * @return bool | |
116 | + */ | |
117 | + public function verificaCompatibilidade($strVersaoSEI){ | |
118 | + if (substr($strVersaoSEI, 0, 2) != '3.') { | |
119 | + return false; | |
120 | + } | |
121 | + return true; | |
122 | + } | |
123 | + | |
95 | 124 | public function getNome() |
96 | 125 | { |
97 | 126 | return 'Módulo de provisionamento de serviços REST do SEI'; |
... | ... | @@ -99,7 +128,7 @@ class MdWsSeiRest extends SeiIntegracao |
99 | 128 | |
100 | 129 | public function getVersao() |
101 | 130 | { |
102 | - return '1.0.0'; | |
131 | + return '0.2.2'; | |
103 | 132 | } |
104 | 133 | |
105 | 134 | public function getInstituicao() |
... | ... | @@ -109,7 +138,7 @@ class MdWsSeiRest extends SeiIntegracao |
109 | 138 | |
110 | 139 | public function inicializar($strVersaoSEI) |
111 | 140 | { |
112 | - if (substr($strVersaoSEI, 0, 2) != '3.') { | |
141 | + if (!$this->verificaCompatibilidade($strVersaoSEI)) { | |
113 | 142 | die('Módulo "' . $this->getNome() . '" (' . $this->getVersao() . ') não e compatível com esta versão do SEI (' . $strVersaoSEI . ').'); |
114 | 143 | } |
115 | 144 | } | ... | ... |
controlador_ws.php
... | ... | @@ -6,7 +6,7 @@ |
6 | 6 | require_once dirname(__FILE__).'/../../SEI.php'; |
7 | 7 | require_once dirname(__FILE__).'/vendor/autoload.php'; |
8 | 8 | |
9 | -class TokenValidationMiddleware{ | |
9 | +class TokenValidationMiddleware { | |
10 | 10 | public function __invoke($request, $response, $next) |
11 | 11 | { |
12 | 12 | /** @var $request Slim\Http\Request */ |
... | ... | @@ -35,6 +35,36 @@ class TokenValidationMiddleware{ |
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
38 | +class ModuleVerificationMiddleware { | |
39 | + public function __invoke($request, $response, $next) | |
40 | + { | |
41 | + if(!class_exists('MdWsSeiRest', false) || !MdWsSeiRest::moduloAtivo()) { | |
42 | + return $response->withJson( | |
43 | + array( | |
44 | + "sucesso" => false, | |
45 | + "mensagem" => utf8_encode("Módulo inativo."), | |
46 | + "exception" => null | |
47 | + ), | |
48 | + 401 | |
49 | + ); | |
50 | + } | |
51 | + | |
52 | + if(!MdWsSeiRest::verificaCompatibilidade(SEI_VERSAO)){ | |
53 | + return $response->withJson( | |
54 | + array( | |
55 | + "sucesso" => false, | |
56 | + "mensagem" => utf8_encode("Módulo incompatível com a versão ".SEI_VERSAO." do SEI."), | |
57 | + "exception" => null | |
58 | + ), | |
59 | + 401 | |
60 | + ); | |
61 | + } | |
62 | + | |
63 | + $response = $next($request, $response); | |
64 | + return $response; | |
65 | + } | |
66 | +} | |
67 | + | |
38 | 68 | |
39 | 69 | $config = array( |
40 | 70 | 'settings' => array( |
... | ... | @@ -592,5 +622,5 @@ $app->group('/api/v1',function(){ |
592 | 622 | }); |
593 | 623 | |
594 | 624 | })->add( new TokenValidationMiddleware()); |
595 | -}); | |
625 | +})->add( new ModuleVerificationMiddleware()); | |
596 | 626 | $app->run(); | ... | ... |