Skip to content

Commit

Permalink
Merge branch '3.4.x' into 3.5.x
Browse files Browse the repository at this point in the history
  • Loading branch information
pintorig committed Jun 11, 2021
2 parents 9a4ed82 + e19c1db commit 069cb45
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ear/src/main/application/properties/avvisi.properties
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,5 @@ de.descrizione=Beschreibung
de.tipo=Kerl
de.codice_cbill=CBILL Interbankencode
de.codice_avviso=Zahlungskodex
de.codice_fiscale_ente=St.-Nr. der k\u00F6rperschaft
de.codice_fiscale_ente=St. Nr. der K\u00F6rperschaft

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.openspcoop2.generic_project.exception.NotFoundException;
import org.openspcoop2.utils.UtilsException;
import org.openspcoop2.utils.certificate.CertificateUtils;
import org.openspcoop2.utils.certificate.PrincipalType;
Expand Down Expand Up @@ -34,37 +33,44 @@ public class AuthorizationManager {
public static final String CODICE_FISCALE_CITTADINO = "cf_cittadino";
public static final String UTENZA_ANONIMA = "utenzaAnonima";

public static boolean checkPrincipal(Authentication authentication, String principalToCheck) throws NotAuthorizedException {
return checkPrincipal(authentication, principalToCheck, true);
}

public static boolean checkPrincipal(Authentication authentication, String principalToCheck) throws Exception {
public static boolean checkPrincipal(Authentication authentication, String principalToCheck, boolean throwsException) throws NotAuthorizedException {
GovpayLdapUserDetails details = AutorizzazioneUtils.getAuthenticationDetails(authentication);
Utenza user = details.getUtenza();

if(details == null && throwsException) {
throw new NotAuthorizedException("Utenza non autorizzata: impossibile leggere il principal.");
}

boolean authOk = false;
Utenza user = details.getUtenza();

if(user.isCheckSubject()) {
// check tra subject
authOk = AuthorizationManager.checkSubject(principalToCheck, user.getPrincipal());
} else {
authOk = user.getPrincipal().equals(principalToCheck);
}

return authOk;
}

public static boolean checkSubject(String principalToCheck, String principalFromRequest) throws Exception{
public static boolean checkSubject(String principalToCheck, String principalFromRequest) throws NotAuthorizedException{
boolean ok = true;

Hashtable<String,List<String>> hashSubject = null;
try {
principalToCheck = CertificateUtils.formatPrincipal(principalToCheck,PrincipalType.subject);
}catch(UtilsException e) {
throw new NotFoundException("L'utenza registrata non e' un subject valido");
throw new NotAuthorizedException("L'utenza registrata non e' un subject valido");
}
try {
principalFromRequest = CertificateUtils.formatPrincipal(principalFromRequest,PrincipalType.subject);
hashSubject = CertificateUtils.getPrincipalIntoHashtable(principalFromRequest,PrincipalType.subject);
}catch(UtilsException e) {
throw new NotFoundException("Utenza" + principalFromRequest + "non autorizzata");
throw new NotAuthorizedException("Utenza" + principalFromRequest + "non autorizzata");
}
Enumeration<String> keys = hashSubject.keys();
while(keys.hasMoreElements()){
Expand Down

0 comments on commit 069cb45

Please sign in to comment.