Skip to content

Commit

Permalink
Fix #117: Errore di autorizzazione in lettura evento
Browse files Browse the repository at this point in the history
  • Loading branch information
nardil committed Nov 12, 2019
2 parents 343a434 + c8446c1 commit def4ac9
Show file tree
Hide file tree
Showing 2 changed files with 151 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
Feature: Eventi di verifica della pendenza

Background:

* callonce read('classpath:utils/common-utils.feature')
* call read('classpath:configurazione/v1/anagrafica.feature')

Scenario: Autorizzazione alla lettura del dettaglio di un evento

Given url backofficeBaseurl
And path 'ruoli', 'Operatore'
And headers gpAdminBasicAutenticationHeader
And request
"""
{
acl: [ { servizio: 'Pendenze', autorizzazioni: [ 'R', ] } ],
}
"""
When method put
Then assert responseStatus == 200 || responseStatus == 201

Given url backofficeBaseurl
And path 'operatori', 'RSSMRA30A01H501I'
And headers gpAdminBasicAutenticationHeader
And request
"""
{
ragioneSociale: 'Mario Rossi',
domini: ['*'],
tipiPendenza: ['*'],
acl: null,
ruoli: ['Operatore'],
abilitato: true
}
"""
When method put
Then assert responseStatus == 200 || responseStatus == 201

* call read('classpath:configurazione/v1/operazioni-resetCache.feature')

* def idPendenza = getCurrentTimeMillis()
* def pendenzaPut = read('classpath:test/api/pendenza/v1/pendenze/put/msg/pendenza-put_monovoce_riferimento.json')
* def pendenzeBaseurl = getGovPayApiBaseUrl({api: 'backoffice', versione: 'v1', autenticazione: 'basic'})

Given url pendenzeBaseurl
And path '/pendenze', idA2A, idPendenza
And headers gpAdminBasicAutenticationHeader
And request pendenzaPut
When method put
Then status 201

* call sleep(200)

* def backofficeBaseurl = getGovPayApiBaseUrl({api: 'backoffice', versione: 'v1', autenticazione: 'spid'})

Given url backofficeBaseurl
And path '/eventi'
And param idA2A = idA2A
And param idPendenza = idPendenza
And headers operatoreSpidAutenticationHeader
When method get
Then status 200

Given url backofficeBaseurl
And path '/eventi', response.risultati[0].id
And headers operatoreSpidAutenticationHeader
When method get
Then status 200
Original file line number Diff line number Diff line change
Expand Up @@ -267,8 +267,13 @@ public Response getEvento(Authentication user, UriInfo uriInfo, HttpHeaders http
String transactionId = this.context.getTransactionId();
this.log.debug(MessageFormat.format(BaseController.LOG_MSG_ESECUZIONE_METODO_IN_CORSO, methodName));
try{
// autorizzazione sulla API
this.isAuthorized(user, Arrays.asList(TIPO_UTENZA.OPERATORE, TIPO_UTENZA.APPLICAZIONE), Arrays.asList(Servizio.GIORNALE_DEGLI_EVENTI), Arrays.asList(Diritti.LETTURA));
boolean autorizza = false;
try {
// autorizzazione sulla API
this.isAuthorized(user, Arrays.asList(TIPO_UTENZA.OPERATORE, TIPO_UTENZA.APPLICAZIONE), Arrays.asList(Servizio.GIORNALE_DEGLI_EVENTI), Arrays.asList(Diritti.LETTURA));
}catch (NotAuthorizedException e) {
autorizza = true;
}
Long idLong = null;
try {
idLong = Long.parseLong(id);
Expand All @@ -284,6 +289,82 @@ public Response getEvento(Authentication user, UriInfo uriInfo, HttpHeaders http

// CHIAMATA AL DAO
LeggiEventoDTOResponse leggiEventoDTOResponse = eventiDAO.leggiEvento(leggiEventoDTO);

boolean autorizzato = true;
if(autorizza) {
it.govpay.bd.model.Evento evento = leggiEventoDTOResponse.getEvento();
String idA2A = evento.getCodApplicazione();
String idPendenza = evento.getCodVersamentoEnte();
String idDominio = evento.getCodDominio();
String iuv = evento.getCodDominio();
String idPagamento = evento.getIdSessione();

if(idA2A != null && idPendenza != null) {

if(autorizza) {
//check autorizzazione per la pendenza scelta
ListaPendenzeConInformazioniIncassoDTO listaPendenzeDTO = new ListaPendenzeConInformazioniIncassoDTO(user);
listaPendenzeDTO.setIdA2A(idA2A);
listaPendenzeDTO.setIdPendenza(idPendenza);

// Autorizzazione sui domini
List<Long> idDomini = AuthorizationManager.getIdDominiAutorizzati(user);
if(idDomini == null) {
throw AuthorizationManager.toNotAuthorizedExceptionNessunDominioAutorizzato(user);
}
listaPendenzeDTO.setIdDomini(idDomini);
// autorizzazione sui tipi pendenza
List<Long> idTipiVersamento = AuthorizationManager.getIdTipiVersamentoAutorizzati(user);
if(idTipiVersamento == null) {
throw AuthorizationManager.toNotAuthorizedExceptionNessunTipoVersamentoAutorizzato(user);
}
listaPendenzeDTO.setIdTipiVersamento(idTipiVersamento);

PendenzeDAO pendenzeDAO = new PendenzeDAO();

ListaPendenzeDTOResponse listaPendenzeDTOResponse = pendenzeDAO.countPendenze(listaPendenzeDTO);

if(listaPendenzeDTOResponse.getTotalResults() == 0)
autorizzato = false;
}
} else if(idDominio != null && iuv != null) {

if(autorizza) {
ListaRptDTO listaRptDTO = new ListaRptDTO(user);
listaRptDTO.setIdDominio(idDominio);
listaRptDTO.setIuv(iuv);

// Autorizzazione sui domini
List<String> domini = AuthorizationManager.getDominiAutorizzati(user);
if(domini == null) {
throw AuthorizationManager.toNotAuthorizedExceptionNessunDominioAutorizzato(user);
}
listaRptDTO.setCodDomini(domini);

RptDAO rptDAO = new RptDAO();
ListaRptDTOResponse listaRptDTOResponse = rptDAO.countRpt(listaRptDTO);

if(listaRptDTOResponse.getTotalResults() == 0)
autorizzato = false;
}
} else if(idPagamento != null) {

if(autorizza) {

ListaPagamentiPortaleDTO listaPagamentiPortaleDTO = new ListaPagamentiPortaleDTO(user);
listaPagamentiPortaleDTO.setIdSessione(idPagamento);

PagamentiPortaleDAO pagamentiPortaleDAO = new PagamentiPortaleDAO();
ListaPagamentiPortaleDTOResponse pagamentoPortaleDTOResponse = pagamentiPortaleDAO.countPagamentiPortale(listaPagamentiPortaleDTO);

if(pagamentoPortaleDTOResponse.getTotalResults() == 0)
autorizzato = false;
}
}
}

if(!autorizzato)
throw AuthorizationManager.toNotAuthorizedException(user);

Evento response = EventiConverter.toRsModel(leggiEventoDTOResponse.getEvento());
this.log.debug(MessageFormat.format(BaseController.LOG_MSG_ESECUZIONE_METODO_COMPLETATA, methodName));
Expand Down

0 comments on commit def4ac9

Please sign in to comment.