Commit 53f69354d8e2877bfc546c16a11ef67741d79e9f
1 parent
052781e7
Exists in
master
and in
1 other branch
[FEAT] Alterando toda parte de autenticação e token para implementação de contextos.
Incluido serviços de listagem de orgãos e contextos.
Showing
4 changed files
with
125 additions
and
33 deletions
Show diff stats
controlador_ws.php
@@ -51,10 +51,36 @@ $app->group('/api/v1',function(){ | @@ -51,10 +51,36 @@ $app->group('/api/v1',function(){ | ||
51 | /** @var $response Slim\Http\Response */ | 51 | /** @var $response Slim\Http\Response */ |
52 | $rn = new MdWsSeiUsuarioRN(); | 52 | $rn = new MdWsSeiUsuarioRN(); |
53 | $usuarioDTO = new UsuarioDTO(); | 53 | $usuarioDTO = new UsuarioDTO(); |
54 | + $contextoDTO = new ContextoDTO(); | ||
54 | $usuarioDTO->setStrSigla($request->getParam('usuario')); | 55 | $usuarioDTO->setStrSigla($request->getParam('usuario')); |
55 | $usuarioDTO->setStrSenha($request->getParam('senha')); | 56 | $usuarioDTO->setStrSenha($request->getParam('senha')); |
57 | + $contextoDTO->setNumIdContexto($request->getParam('contexto')); | ||
58 | + $contextoDTO->setNumIdOrgao($request->getParam('orgao')); | ||
56 | 59 | ||
57 | - return $response->withJSON($rn->autenticar($usuarioDTO)); | 60 | + return $response->withJSON($rn->apiAutenticar($usuarioDTO, $contextoDTO)); |
61 | + }); | ||
62 | + /** | ||
63 | + * Grupo de controlador de Órgão <publico> | ||
64 | + */ | ||
65 | + $this->group('/orgao', function(){ | ||
66 | + $this->get('/listar', function($request, $response, $args){ | ||
67 | + /** @var $request Slim\Http\Request */ | ||
68 | + $rn = new MdWsSeiOrgaoRN(); | ||
69 | + $dto = new OrgaoDTO(); | ||
70 | + return $response->withJSON($rn->listarOrgao($dto)); | ||
71 | + }); | ||
72 | + }); | ||
73 | + /** | ||
74 | + * Grupo de controlador de Contexto <publico> | ||
75 | + */ | ||
76 | + $this->group('/contexto', function(){ | ||
77 | + $this->get('/listar/{orgao}', function($request, $response, $args){ | ||
78 | + /** @var $request Slim\Http\Request */ | ||
79 | + $rn = new MdWsSeiContextoRN(); | ||
80 | + $dto = new OrgaoDTO(); | ||
81 | + $dto->setNumIdOrgao($request->getAttribute('route')->getArgument('orgao')); | ||
82 | + return $response->withJSON($rn->listarContexto($dto)); | ||
83 | + }); | ||
58 | }); | 84 | }); |
59 | 85 | ||
60 | /** | 86 | /** |
@@ -0,0 +1,45 @@ | @@ -0,0 +1,45 @@ | ||
1 | +<? | ||
2 | +require_once dirname(__FILE__).'/../../../SEI.php'; | ||
3 | + | ||
4 | +class MdWsSeiContextoRN extends InfraRN { | ||
5 | + | ||
6 | + protected function inicializarObjInfraIBanco(){ | ||
7 | + return BancoSEI::getInstance(); | ||
8 | + } | ||
9 | + | ||
10 | + /** | ||
11 | + * Retorna a lista de contextos por orgao | ||
12 | + * @return array | ||
13 | + */ | ||
14 | + protected function listarContextoConectado(OrgaoDTO $orgaoDTO){ | ||
15 | + try{ | ||
16 | + if(!$orgaoDTO->isSetNumIdOrgao()){ | ||
17 | + throw new Exception('O órgão do contexto deve ser informado!'); | ||
18 | + } | ||
19 | + $result = array(); | ||
20 | + $contextoRN = new ContextoRN(); | ||
21 | + $contextDTOConsulta = new ContextoDTO(); | ||
22 | + $contextDTOConsulta->retNumIdContexto(); | ||
23 | + $contextDTOConsulta->retStrNome(); | ||
24 | + $contextDTOConsulta->retStrDescricao(); | ||
25 | + $contextDTOConsulta->retStrBaseDnLdap(); | ||
26 | + $contextDTOConsulta->setStrSinAtivo('S'); | ||
27 | + $contextDTOConsulta->setNumIdOrgao($orgaoDTO->getNumIdOrgao()); | ||
28 | + $ret = $contextoRN->listar($contextDTOConsulta); | ||
29 | + /** @var ContextoDTO $contextoDTO */ | ||
30 | + foreach($ret as $contextoDTO){ | ||
31 | + $result[] = array( | ||
32 | + 'id' => $contextoDTO->getNumIdContexto(), | ||
33 | + 'nome' => $contextoDTO->getStrNome(), | ||
34 | + 'descricao' => $contextoDTO->getStrDescricao(), | ||
35 | + 'base_dn_ldap' => $contextoDTO->getStrBaseDnLdap(), | ||
36 | + ); | ||
37 | + } | ||
38 | + | ||
39 | + return MdWsSeiRest::formataRetornoSucessoREST(null, $result); | ||
40 | + }catch (Exception $e){ | ||
41 | + return MdWsSeiRest::formataRetornoErroREST($e); | ||
42 | + } | ||
43 | + } | ||
44 | + | ||
45 | +} | ||
0 | \ No newline at end of file | 46 | \ No newline at end of file |
rn/MdWsSeiOrgaoRN.php
@@ -10,28 +10,22 @@ class MdWsSeiOrgaoRN extends InfraRN { | @@ -10,28 +10,22 @@ class MdWsSeiOrgaoRN extends InfraRN { | ||
10 | /** | 10 | /** |
11 | * Retorna todos os orgaos ativos cadastrados | 11 | * Retorna todos os orgaos ativos cadastrados |
12 | * @param OrgaoDTO $orgaoDTO | 12 | * @param OrgaoDTO $orgaoDTO |
13 | - * @info para p�ginacao e necess�rio informar dentro do DTO os parametros abaixo: | ||
14 | - * - setNumMaxRegistrosRetorno | ||
15 | - * - setNumPaginaAtual | ||
16 | * @return array | 13 | * @return array |
17 | */ | 14 | */ |
18 | - protected function listarOrgaoConectado(OrgaoDTO $orgaoDTO){ | 15 | + protected function listarOrgaoConectado(OrgaoDTO $orgaoDTOParam){ |
19 | try{ | 16 | try{ |
20 | $result = array(); | 17 | $result = array(); |
21 | - $orgaoRN = new OrgaoRN(); | ||
22 | - if(!$orgaoDTO->isRetNumIdOrgao()){ | ||
23 | - $orgaoDTO->retNumIdOrgao(); | ||
24 | - } | ||
25 | - if(!$orgaoDTO->isRetStrSigla()){ | ||
26 | - $orgaoDTO->retStrSigla(); | ||
27 | - } | ||
28 | - if(!$orgaoDTO->isRetStrDescricao()){ | ||
29 | - $orgaoDTO->retStrDescricao(); | ||
30 | - } | ||
31 | - if(!$orgaoDTO->isSetStrSinAtivo()){ | ||
32 | - $orgaoDTO->setStrSinAtivo('S'); | ||
33 | - } | ||
34 | - $ret = $orgaoRN->listarRN1353($orgaoDTO); | 18 | + $orgaoDTO = new OrgaoDTO(); |
19 | + $orgaoDTO->retNumIdOrgao(); | ||
20 | + $orgaoDTO->retStrSigla(); | ||
21 | + $orgaoDTO->retStrDescricao(); | ||
22 | + $orgaoDTO->setStrSinAtivo('S'); | ||
23 | + | ||
24 | + //Chamada Direta ao BD devido a ponta ser um serviço público sem autenticação. | ||
25 | + | ||
26 | + $orgaoBD = new OrgaoBD($this->getObjInfraIBanco()); | ||
27 | + $ret = $orgaoBD->listar($orgaoDTO); | ||
28 | + | ||
35 | /** @var OrgaoDTO $orgDTO */ | 29 | /** @var OrgaoDTO $orgDTO */ |
36 | foreach($ret as $orgDTO){ | 30 | foreach($ret as $orgDTO){ |
37 | $result[] = array( | 31 | $result[] = array( |
@@ -41,7 +35,7 @@ class MdWsSeiOrgaoRN extends InfraRN { | @@ -41,7 +35,7 @@ class MdWsSeiOrgaoRN extends InfraRN { | ||
41 | ); | 35 | ); |
42 | } | 36 | } |
43 | 37 | ||
44 | - return MdWsSeiRest::formataRetornoSucessoREST(null, $result, $orgaoDTO->getNumTotalRegistros()); | 38 | + return MdWsSeiRest::formataRetornoSucessoREST(null, $result); |
45 | }catch (Exception $e){ | 39 | }catch (Exception $e){ |
46 | return MdWsSeiRest::formataRetornoErroREST($e); | 40 | return MdWsSeiRest::formataRetornoErroREST($e); |
47 | } | 41 | } |
rn/MdWsSeiUsuarioRN.php
@@ -50,7 +50,7 @@ class MdWsSeiUsuarioRN extends InfraRN { | @@ -50,7 +50,7 @@ class MdWsSeiUsuarioRN extends InfraRN { | ||
50 | $fase2 = str_replace($this->getSecret(), '', $fase1); | 50 | $fase2 = str_replace($this->getSecret(), '', $fase1); |
51 | $fase3 = base64_decode($fase2); | 51 | $fase3 = base64_decode($fase2); |
52 | $tokenData = explode('||', $fase3); | 52 | $tokenData = explode('||', $fase3); |
53 | - if(count($tokenData) != 2){ | 53 | + if(count($tokenData) != 4){ |
54 | return null; | 54 | return null; |
55 | } | 55 | } |
56 | $tokenData[0] = $this->decriptaSenha($tokenData[0]); | 56 | $tokenData[0] = $this->decriptaSenha($tokenData[0]); |
@@ -60,13 +60,23 @@ class MdWsSeiUsuarioRN extends InfraRN { | @@ -60,13 +60,23 @@ class MdWsSeiUsuarioRN extends InfraRN { | ||
60 | } | 60 | } |
61 | 61 | ||
62 | /** | 62 | /** |
63 | - * M?todo que criptografa o token | 63 | + * Método que criptografa o token |
64 | * @param $sigla | 64 | * @param $sigla |
65 | * @param $senha | 65 | * @param $senha |
66 | + * @param null $orgao | ||
67 | + * @param null $contexto | ||
66 | * @return string | 68 | * @return string |
67 | */ | 69 | */ |
68 | - public function tokenEncode($sigla, $senha){ | ||
69 | - $token = base64_encode($this->getSecret().base64_encode($this->encriptaSenha($sigla).'||'.$this->encriptaSenha($senha))); | 70 | + public function tokenEncode($sigla, $senha, $orgao = null, $contexto = null){ |
71 | + $token = base64_encode( | ||
72 | + $this->getSecret() | ||
73 | + .base64_encode( | ||
74 | + $this->encriptaSenha($sigla) | ||
75 | + .'||'.$this->encriptaSenha($senha) | ||
76 | + .'||'.$orgao | ||
77 | + .'||'.$contexto | ||
78 | + ) | ||
79 | + ); | ||
70 | 80 | ||
71 | return $token; | 81 | return $token; |
72 | } | 82 | } |
@@ -106,13 +116,15 @@ class MdWsSeiUsuarioRN extends InfraRN { | @@ -106,13 +116,15 @@ class MdWsSeiUsuarioRN extends InfraRN { | ||
106 | 116 | ||
107 | $tokenData = $this->tokenDecode($token); | 117 | $tokenData = $this->tokenDecode($token); |
108 | if(!$tokenData){ | 118 | if(!$tokenData){ |
109 | - throw new InfraException('Token inv?lido!'); | 119 | + throw new InfraException('Token inválido!'); |
110 | } | 120 | } |
111 | - | ||
112 | $usuarioDTO = new UsuarioDTO(); | 121 | $usuarioDTO = new UsuarioDTO(); |
113 | $usuarioDTO->setStrSigla($tokenData[0]); | 122 | $usuarioDTO->setStrSigla($tokenData[0]); |
114 | $usuarioDTO->setStrSenha($tokenData[1]); | 123 | $usuarioDTO->setStrSenha($tokenData[1]); |
115 | - $result = $this->autenticar($usuarioDTO); | 124 | + $contextoDTO = new ContextoDTO(); |
125 | + $contextoDTO->setNumIdOrgao($tokenData[2]); | ||
126 | + $contextoDTO->setNumIdContexto($tokenData[3]); | ||
127 | + $result = $this->apiAutenticar($usuarioDTO, $contextoDTO); | ||
116 | if(!$result['sucesso']){ | 128 | if(!$result['sucesso']){ |
117 | return $result; | 129 | return $result; |
118 | } | 130 | } |
@@ -131,9 +143,12 @@ class MdWsSeiUsuarioRN extends InfraRN { | @@ -131,9 +143,12 @@ class MdWsSeiUsuarioRN extends InfraRN { | ||
131 | * @param $senha | 143 | * @param $senha |
132 | * @param $IdOrgao | 144 | * @param $IdOrgao |
133 | */ | 145 | */ |
134 | - protected function autenticarConectado(UsuarioDTO $usuarioDTO){ | 146 | + public function apiAutenticar(UsuarioDTO $usuarioDTO, ContextoDTO $contextoDTO){ |
135 | try{ | 147 | try{ |
136 | - if(!$usuarioDTO->isSetNumIdOrgao()){ | 148 | + $contexto = $contextoDTO->getNumIdContexto(); |
149 | + $orgao = $contextoDTO->getNumIdOrgao(); | ||
150 | + $siglaOrgao = null; | ||
151 | + if(!$orgao){ | ||
137 | $orgaoRN = new OrgaoRN(); | 152 | $orgaoRN = new OrgaoRN(); |
138 | $objOrgaoDTO = new OrgaoDTO(); | 153 | $objOrgaoDTO = new OrgaoDTO(); |
139 | $objOrgaoDTO->setBolExclusaoLogica(false); | 154 | $objOrgaoDTO->setBolExclusaoLogica(false); |
@@ -144,16 +159,27 @@ class MdWsSeiUsuarioRN extends InfraRN { | @@ -144,16 +159,27 @@ class MdWsSeiUsuarioRN extends InfraRN { | ||
144 | * Orgao da sessao do sistema | 159 | * Orgao da sessao do sistema |
145 | */ | 160 | */ |
146 | $orgaoCarregdo = $orgaoRN->consultarRN1352($objOrgaoDTO); | 161 | $orgaoCarregdo = $orgaoRN->consultarRN1352($objOrgaoDTO); |
147 | - $usuarioDTO->setNumIdOrgao($orgaoCarregdo->getNumIdOrgao()); | 162 | + $orgao = $orgaoCarregdo->getNumIdOrgao(); |
163 | + $siglaOrgao = ConfiguracaoSEI::getInstance()->getValor('SessaoSEI', 'SiglaOrgaoSistema'); | ||
148 | } | 164 | } |
165 | + if(!$siglaOrgao){ | ||
166 | + $orgaoRN = new OrgaoRN(); | ||
167 | + $objOrgaoDTO = new OrgaoDTO(); | ||
168 | + $objOrgaoDTO->setBolExclusaoLogica(false); | ||
169 | + $objOrgaoDTO->retStrSigla(); | ||
170 | + $objOrgaoDTO->setNumIdOrgao($orgao); | ||
171 | + $objOrgaoDTO = $orgaoRN->consultarRN1352($objOrgaoDTO); | ||
172 | + $siglaOrgao = $objOrgaoDTO->getStrSigla(); | ||
173 | + } | ||
174 | + | ||
149 | $objSipWs = $this->retornaServicoSip(); | 175 | $objSipWs = $this->retornaServicoSip(); |
150 | $ret = $objSipWs->autenticarCompleto( | 176 | $ret = $objSipWs->autenticarCompleto( |
151 | - $usuarioDTO->getNumIdOrgao(), | ||
152 | - null, | 177 | + $orgao, |
178 | + $contexto, | ||
153 | $usuarioDTO->getStrSigla(), | 179 | $usuarioDTO->getStrSigla(), |
154 | $this->encriptaSenha($usuarioDTO->getStrSenha()), | 180 | $this->encriptaSenha($usuarioDTO->getStrSenha()), |
155 | ConfiguracaoSEI::getInstance()->getValor('SessaoSEI', 'SiglaSistema'), | 181 | ConfiguracaoSEI::getInstance()->getValor('SessaoSEI', 'SiglaSistema'), |
156 | - ConfiguracaoSEI::getInstance()->getValor('SessaoSEI', 'SiglaOrgaoSistema') | 182 | + $siglaOrgao |
157 | ); | 183 | ); |
158 | 184 | ||
159 | if(!$ret){ | 185 | if(!$ret){ |
@@ -241,6 +267,7 @@ class MdWsSeiUsuarioRN extends InfraRN { | @@ -241,6 +267,7 @@ class MdWsSeiUsuarioRN extends InfraRN { | ||
241 | false, | 267 | false, |
242 | false | 268 | false |
243 | ); | 269 | ); |
270 | + var_dump($ret);exit; | ||
244 | return MdWsSeiRest::formataRetornoSucessoREST(null, $ret); | 271 | return MdWsSeiRest::formataRetornoSucessoREST(null, $ret); |
245 | }catch (Exception $e){ | 272 | }catch (Exception $e){ |
246 | return MdWsSeiRest::formataRetornoErroREST($e); | 273 | return MdWsSeiRest::formataRetornoErroREST($e); |