Skip to content

Commit

Permalink
Merge branch '3.5.x' of github.com:link-it/govpay into 3.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
atatarelli committed Mar 10, 2022
2 parents fe9c762 + 475067a commit d519862
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
Feature: Pagamento avviso precaricato

Background:

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



Scenario: Acquisizione del profilo autenticato spid

* def userBaseurl = getGovPayApiBaseUrl({api: 'user', versione: 'v1', autenticazione: 'spid'})
* def backofficeBaseurl = getGovPayApiBaseUrl({api: 'backoffice', versione: 'v1', autenticazione: 'basic'})
* def backofficeFormBaseurl = getGovPayApiBaseUrl({api: 'backoffice', versione: 'v1', autenticazione: 'form'})
* def backofficeSessionBaseurl = getGovPayApiBaseUrl({api: 'backoffice', versione: 'v1', autenticazione: 'session'})
* def spidHeaders = {'X-SPID-FISCALNUMBER': 'RSSMRA30A01H501I','X-SPID-NAME': 'Mario','X-SPID-FAMILYNAME': 'Rossi','X-SPID-EMAIL': 'mrossi@mailserver.host.it'}

* configure cookies = null
* configure followRedirects = false

Given url userBaseurl
And path '/login', 'SPID_PROFILO'
And headers spidHeaders
When method get
Then status 303

* def profiloLocation = responseHeaders['Location'][0]

Given url profiloLocation
When method get
Then status 200

Given url backofficeFormBaseurl
And path '/profilo'
When method get
Then status 403

Given url backofficeBaseurl
And path '/profilo'
When method get
Then status 401
2 changes: 1 addition & 1 deletion integration-test/src/test/java/utils/common-utils.feature
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Scenario:
* def getGovPayApiBaseUrl =
"""
function(param) {
if (param.api == 'pagamento')
if (param.api == 'pagamento' || param.api == 'user')
return govpay_url + '/govpay/frontend/api/' + param.api + '/rs/' + param.autenticazione + '/' + param.versione;
else
return govpay_url + '/govpay/backend/api/' + param.api + '/rs/' + param.autenticazione + '/' + param.versione;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,25 @@ public static NotAuthorizedException toNotAuthorizedExceptionNessunTipoVersament
sb.append(details.getMessaggioUtenzaNonAutorizzata()).append(" per nessun Tipo Pendenza.");
return new NotAuthorizedException(sb.toString());
}

public static boolean isAuthorized(Authentication authentication, List<TIPO_UTENZA> tipoUtenza) {
GovpayLdapUserDetails details = AutorizzazioneUtils.getAuthenticationDetails(authentication);
return isAuthorized(details.getUtenza(), tipoUtenza);
}

public static boolean isAuthorized(Utenza utenza, List<TIPO_UTENZA> tipoUtenza) {

// controllo che l'utenza sia di tipo consentito
if(!tipoUtenza.contains(utenza.getTipoUtenza()))
return false;

// controllo abilitazione
if(!utenza.isAbilitato())
return false;

return true;
}


public static boolean isAuthorized(Authentication authentication, List<TIPO_UTENZA> tipoUtenza, List<Servizio> servizi, List<Diritti> listaDiritti) {
GovpayLdapUserDetails details = AutorizzazioneUtils.getAuthenticationDetails(authentication);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static String getPrincipal(Authentication authentication) {
}

public static GovpayLdapUserDetails getUserDetailFromUtenzaRegistrata(String username, boolean checkPassword, boolean checkSubject,
Collection<? extends GrantedAuthority> authFromPreauth, Map<String, List<String>> headerValues, BDConfigWrapper configWrapper) throws UsernameNotFoundException , ServiceException {
Collection<? extends GrantedAuthority> authFromPreauth, Map<String, List<String>> headerValues, BDConfigWrapper configWrapper, String apiName, String authType) throws UsernameNotFoundException , ServiceException {

Utenza utenza = null;
Applicazione applicazione = null;
Expand Down Expand Up @@ -104,6 +104,9 @@ public static GovpayLdapUserDetails getUserDetailFromUtenzaRegistrata(String use

utenza.setCheckSubject(checkSubject);

utenza.setAutenticazione(authType);
utenza.setApiName(apiName);

String password = StringUtils.isNotBlank(utenza.getPassword()) ? utenza.getPassword() : PASSWORD_DEFAULT_VALUE;

GovpayLdapUserDetails userDetails = getUserDetail(username, password, username, authorities);
Expand All @@ -116,7 +119,7 @@ public static GovpayLdapUserDetails getUserDetailFromUtenzaRegistrata(String use
}

public static GovpayLdapUserDetails getUserDetailFromUtenzaRegistrataInSessione(String username, boolean checkPassword, boolean checkSubject,
Collection<? extends GrantedAuthority> authFromPreauth, Map<String, Object> attributeValues, GovpayLdapUserDetails userDetailFromSession, BDConfigWrapper configWrapper) throws UsernameNotFoundException , ServiceException {
Collection<? extends GrantedAuthority> authFromPreauth, Map<String, Object> attributeValues, GovpayLdapUserDetails userDetailFromSession, BDConfigWrapper configWrapper, String apiName, String authType) throws UsernameNotFoundException , ServiceException {

List<Acl> aclsRuolo = new ArrayList<>();
List<GrantedAuthority> authorities = new ArrayList<>();
Expand Down Expand Up @@ -155,6 +158,9 @@ public static GovpayLdapUserDetails getUserDetailFromUtenzaRegistrataInSessione(
throw new UsernameNotFoundException("Utenza non trovata.",ex);
}
}

utenza.setAutenticazione(authType);
utenza.setApiName(apiName);

GovpayLdapUserDetails userDetails = getUserDetail(userDetailFromSession, authorities);
userDetails.setApplicazione(applicazione);
Expand Down Expand Up @@ -202,7 +208,7 @@ public static GovpayLdapUserDetails getUserDetail(GovpayLdapUserDetails base, Li
}

public static GovpayLdapUserDetails getUserDetailFromUtenzaCittadino(String username, boolean checkPassword, boolean checkSubject,
Collection<? extends GrantedAuthority> authFromPreauth,Map<String, List<String>> headerValues, BDConfigWrapper configWrapper) throws UsernameNotFoundException , ServiceException {
Collection<? extends GrantedAuthority> authFromPreauth,Map<String, List<String>> headerValues, BDConfigWrapper configWrapper, String apiName, String authType) throws UsernameNotFoundException , ServiceException {

TIPO_UTENZA tipoUtenza = TIPO_UTENZA.CITTADINO;
List<Acl> aclsRuolo = new ArrayList<>();
Expand Down Expand Up @@ -234,6 +240,8 @@ public static GovpayLdapUserDetails getUserDetailFromUtenzaCittadino(String user
utenza.setPrincipalOriginale(username);
utenza.setPrincipal(username);
utenza.setCheckSubject(checkSubject);
utenza.setAutenticazione(authType);
utenza.setApiName(apiName);

GovpayLdapUserDetails userDetails = getUserDetail(username, PASSWORD_DEFAULT_VALUE, username, authorities);
userDetails.setUtenza(utenza);
Expand All @@ -244,7 +252,7 @@ public static GovpayLdapUserDetails getUserDetailFromUtenzaCittadino(String user
}

public static GovpayLdapUserDetails getUserDetailFromUtenzaInSessione(String username, boolean checkPassword, boolean checkSubject,
Collection<? extends GrantedAuthority> authFromPreauth, Map<String, Object> attributeValues, GovpayLdapUserDetails userDetailFromSession, BDConfigWrapper configWrapper) throws UsernameNotFoundException , ServiceException {
Collection<? extends GrantedAuthority> authFromPreauth, Map<String, Object> attributeValues, GovpayLdapUserDetails userDetailFromSession, BDConfigWrapper configWrapper, String apiName, String authType) throws UsernameNotFoundException , ServiceException {

List<Acl> aclsRuolo = new ArrayList<>();
List<GrantedAuthority> authorities = new ArrayList<>();
Expand Down Expand Up @@ -274,7 +282,7 @@ public static GovpayLdapUserDetails getUserDetailFromUtenzaInSessione(String use
// }

public static GovpayLdapUserDetails getUserDetailFromUtenzaAnonima(String username, boolean checkPassword, boolean checkSubject,
Collection<? extends GrantedAuthority> authFromPreauth, BDConfigWrapper configWrapper) throws UsernameNotFoundException , ServiceException {
Collection<? extends GrantedAuthority> authFromPreauth, BDConfigWrapper configWrapper, String apiName, String authType) throws UsernameNotFoundException , ServiceException {

TIPO_UTENZA tipoUtenza = TIPO_UTENZA.ANONIMO;
List<Acl> aclsRuolo = new ArrayList<>();
Expand Down Expand Up @@ -307,6 +315,8 @@ public static GovpayLdapUserDetails getUserDetailFromUtenzaAnonima(String userna
utenza.setPrincipalOriginale(username);
utenza.setPrincipal(username);
utenza.setCheckSubject(checkSubject);
utenza.setAutenticazione(authType);
utenza.setApiName(apiName);

GovpayLdapUserDetails userDetails = getUserDetail(username, PASSWORD_DEFAULT_VALUE, username, authorities);
userDetails.setUtenza(utenza);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public UserDetails loadUserDetails(String username, Collection<? extends Granted
String transactionId = UUID.randomUUID().toString();
BDConfigWrapper configWrapper = new BDConfigWrapper(transactionId, this.useCacheData);
this.debug(transactionId, "Caricamento informazioni dell'utenza ["+username+"] in corso...");
GovpayLdapUserDetails userDetailFromUtenzaAnonima = AutorizzazioneUtils.getUserDetailFromUtenzaAnonima(username, this.isCheckPassword(), this.isCheckSubject(), authFromPreauth, configWrapper);
GovpayLdapUserDetails userDetailFromUtenzaAnonima = AutorizzazioneUtils.getUserDetailFromUtenzaAnonima(username, this.isCheckPassword(), this.isCheckSubject(), authFromPreauth, configWrapper, this.getApiName(), this.getAuthType());
userDetailFromUtenzaAnonima.setIdTransazioneAutenticazione(transactionId);
this.debug(transactionId, "Caricamento informazioni dell'utenza ["+username+"] completato.");
return userDetailFromUtenzaAnonima;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private UserDetails _loadUserDetails(String username, Collection<? extends Grant
String transactionId = UUID.randomUUID().toString();
BDConfigWrapper configWrapper = new BDConfigWrapper(transactionId, this.useCacheData);
this.debug(transactionId,"Caricamento informazioni del cittadino ["+username+"] in corso...");
GovpayLdapUserDetails userDetailFromUtenzaCittadino = AutorizzazioneUtils.getUserDetailFromUtenzaCittadino(username, this.isCheckPassword(), this.isCheckSubject(), authFromPreauth,headerValues, configWrapper);
GovpayLdapUserDetails userDetailFromUtenzaCittadino = AutorizzazioneUtils.getUserDetailFromUtenzaCittadino(username, this.isCheckPassword(), this.isCheckSubject(), authFromPreauth,headerValues, configWrapper, this.getApiName(), this.getAuthType());
userDetailFromUtenzaCittadino.setIdTransazioneAutenticazione(transactionId);
this.debug(transactionId,"Caricamento informazioni del cittadino ["+username+"] completato.");
return userDetailFromUtenzaCittadino;
Expand All @@ -89,7 +89,7 @@ private UserDetails _loadUserDetailsFromSession(String username, Collection<? ex
String transactionId = UUID.randomUUID().toString();
BDConfigWrapper configWrapper = new BDConfigWrapper(transactionId, this.useCacheData);
this.debug(transactionId,"Caricamento informazioni del cittadino ["+username+"] in corso...");
GovpayLdapUserDetails userDetailFromUtenzaCittadino = AutorizzazioneUtils.getUserDetailFromUtenzaInSessione(username, this.isCheckPassword(), this.isCheckSubject(), authFromPreauth, attributeValues, userDetailFromSession, configWrapper);
GovpayLdapUserDetails userDetailFromUtenzaCittadino = AutorizzazioneUtils.getUserDetailFromUtenzaInSessione(username, this.isCheckPassword(), this.isCheckSubject(), authFromPreauth, attributeValues, userDetailFromSession, configWrapper, this.getApiName(), this.getAuthType());
userDetailFromUtenzaCittadino.setIdTransazioneAutenticazione(transactionId);
this.debug(transactionId,"Caricamento informazioni del cittadino ["+username+"] completato.");
return userDetailFromUtenzaCittadino;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private UserDetails _loadUserDetails(String username, Collection<? extends Grant
}

this.debug(transactionId,"Utenza ["+username+"] trovata, lettura del dettaglio in corso...");
GovpayLdapUserDetails userDetails = AutorizzazioneUtils.getUserDetailFromUtenzaRegistrata(username, this.isCheckPassword(), this.isCheckSubject(), authFromPreauth, headerValues, configWrapper);
GovpayLdapUserDetails userDetails = AutorizzazioneUtils.getUserDetailFromUtenzaRegistrata(username, this.isCheckPassword(), this.isCheckSubject(), authFromPreauth, headerValues, configWrapper, this.getApiName(), this.getAuthType());
userDetails.setIdTransazioneAutenticazione(transactionId);
this.debug(transactionId,"Utenza ["+username+"] trovata, lettura del dettaglio completata.");
return userDetails;
Expand Down Expand Up @@ -113,7 +113,7 @@ private UserDetails _loadUserDetailsFromSession(String username, Collection<? ex
throw new NotFoundException("Utenza "+username+" non trovata.");

this.debug(transactionId,"Utenza ["+username+"] trovata, lettura del dettaglio in corso...");
GovpayLdapUserDetails userDetailFromUtenzaCittadino = AutorizzazioneUtils.getUserDetailFromUtenzaRegistrataInSessione(username, this.isCheckPassword(), this.isCheckSubject(), authFromPreauth, attributeValues, userDetailFromSession, configWrapper);
GovpayLdapUserDetails userDetailFromUtenzaCittadino = AutorizzazioneUtils.getUserDetailFromUtenzaRegistrataInSessione(username, this.isCheckPassword(), this.isCheckSubject(), authFromPreauth, attributeValues, userDetailFromSession, configWrapper, this.getApiName(), this.getAuthType());
userDetailFromUtenzaCittadino.setIdTransazioneAutenticazione(transactionId);
this.debug(transactionId,"Utenza ["+username+"] trovata, lettura del dettaglio completata.");
return userDetailFromUtenzaCittadino;
Expand Down
15 changes: 15 additions & 0 deletions jars/orm/src/main/java/it/govpay/bd/model/Utenza.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public class Utenza extends it.govpay.model.Utenza {
protected transient List<Acl> aclRuoliUtenza;
protected transient Map<String,List<Acl>> ruoliUtenza;
protected transient Map<String, List<String>> headers;

private String autenticazione;
private String apiName;

public TIPO_UTENZA getTipoUtenza() {
return TIPO_UTENZA.ANONIMO;
Expand Down Expand Up @@ -261,4 +264,16 @@ public Map<String, List<String>> getHeaders() {
public void setHeaders(Map<String, List<String>> headers) {
this.headers = headers;
}
public String getAutenticazione() {
return autenticazione;
}
public void setAutenticazione(String autenticazione) {
this.autenticazione = autenticazione;
}
public String getApiName() {
return apiName;
}
public void setApiName(String apiName) {
this.apiName = apiName;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"domini",
"tipiPendenza",
"acl",
"autenticazione",
})
public class Profilo extends JSONSerializable {

Expand All @@ -29,6 +30,9 @@ public class Profilo extends JSONSerializable {
@JsonProperty("acl")
private List<AclPost> acl = new ArrayList<>();

@JsonProperty("autenticazione")
private String autenticazione = null;

/**
* Nome dell'utenza
**/
Expand Down Expand Up @@ -92,6 +96,22 @@ public void setAcl(List<AclPost> acl) {
this.acl = acl;
}

/**
* tipo autenticazione utilizzata per loggarsi nel sistema
**/
public Profilo autenticazione(String autenticazione) {
this.autenticazione = autenticazione;
return this;
}

@JsonProperty("autenticazione")
public String getAutenticazione() {
return autenticazione;
}
public void setAutenticazione(String autenticazione) {
this.autenticazione = autenticazione;
}

@Override
public boolean equals(java.lang.Object o) {
if (this == o) {
Expand All @@ -104,12 +124,13 @@ public boolean equals(java.lang.Object o) {
return Objects.equals(nome, profilo.nome) &&
Objects.equals(domini, profilo.domini) &&
Objects.equals(tipiPendenza, profilo.tipiPendenza) &&
Objects.equals(acl, profilo.acl);
Objects.equals(acl, profilo.acl) &&
Objects.equals(autenticazione, profilo.autenticazione);
}

@Override
public int hashCode() {
return Objects.hash(nome, domini, tipiPendenza, acl);
return Objects.hash(nome, domini, tipiPendenza, acl, autenticazione);
}

public static Profilo parse(String json) throws org.openspcoop2.generic_project.exception.ServiceException, ValidationException {
Expand All @@ -130,6 +151,7 @@ public String toString() {
sb.append(" domini: ").append(toIndentedString(domini)).append("\n");
sb.append(" tipiPendenza: ").append(toIndentedString(tipiPendenza)).append("\n");
sb.append(" acl: ").append(toIndentedString(acl)).append("\n");
sb.append(" autenticazione: ").append(toIndentedString(autenticazione)).append("\n");
sb.append("}");
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public static Profilo getProfilo(LeggiProfiloDTOResponse leggiProfilo) throws Se
break;
}

profilo.setAutenticazione(user.getAutenticazione());

if(user.isAutorizzazioneDominiStar()) {
List<DominioProfiloIndex> dominiLst = new ArrayList<>();
DominioProfiloIndex dominioStar = new DominioProfiloIndex();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,12 @@ protected void log(IContext ctx) {
}
}

protected void isAuthorized(Authentication authentication, List<TIPO_UTENZA> tipoUtenza) throws NotAuthorizedException {
if(!AuthorizationManager.isAuthorized(authentication, tipoUtenza)) {
throw AuthorizationManager.toNotAuthorizedException(authentication);
}
}

protected void isAuthorized(Authentication authentication, List<TIPO_UTENZA> tipoUtenza, List<Servizio> servizi, List<Diritti> listaDiritti) throws NotAuthorizedException {
if(!AuthorizationManager.isAuthorized(authentication, tipoUtenza, servizi, listaDiritti)) {
throw AuthorizationManager.toNotAuthorizedException(authentication);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.ByteArrayOutputStream;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.ws.rs.core.HttpHeaders;
Expand All @@ -18,14 +19,15 @@
import org.springframework.security.core.Authentication;

import it.govpay.backoffice.v1.beans.PatchOp;
import it.govpay.backoffice.v1.beans.Profilo;
import it.govpay.backoffice.v1.beans.PatchOp.OpEnum;
import it.govpay.backoffice.v1.beans.Profilo;
import it.govpay.backoffice.v1.beans.converter.PatchOpConverter;
import it.govpay.backoffice.v1.beans.converter.ProfiloConverter;
import it.govpay.core.beans.JSONSerializable;
import it.govpay.core.dao.anagrafica.UtentiDAO;
import it.govpay.core.dao.anagrafica.dto.LeggiProfiloDTOResponse;
import it.govpay.core.dao.pagamenti.dto.ProfiloPatchDTO;
import it.govpay.model.Utenza.TIPO_UTENZA;

public class ProfiloController extends BaseController {

Expand All @@ -38,6 +40,9 @@ public Response getProfilo(Authentication user, UriInfo uriInfo, HttpHeaders htt
String transactionId = ContextThreadLocal.get().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));

UtentiDAO utentiDAO = new UtentiDAO();

LeggiProfiloDTOResponse leggiProfilo = utentiDAO.getProfilo(user);
Expand All @@ -64,6 +69,9 @@ public Response updateProfilo(Authentication user, UriInfo uriInfo, HttpHeaders
// salvo il json ricevuto
IOUtils.copy(is, baos);

// autorizzazione sulla API
this.isAuthorized(user, Arrays.asList(TIPO_UTENZA.OPERATORE, TIPO_UTENZA.APPLICAZIONE));

// autorizzazione sulla API
// this.isAuthorized(user, Arrays.asList(TIPO_UTENZA.OPERATORE), Arrays.asList(Servizio.ANAGRAFICA_RUOLI), Arrays.asList(Diritti.SCRITTURA));
String jsonRequest = baos.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8581,6 +8581,9 @@ components:
type: array
items:
$ref: '#/components/schemas/aclPost'
autenticazione:
type: string
description: tipo autenticazione utilizzata per loggarsi nel sistema
esitoOperazione:
type: object
required:
Expand Down

0 comments on commit d519862

Please sign in to comment.