AbstractRoleRetriever.java

  1. /*
  2.  * GovWay - A customizable API Gateway
  3.  * https://govway.org
  4.  *
  5.  * Copyright (c) 2005-2025 Link.it srl (https://link.it).
  6.  *
  7.  * This program is free software: you can redistribute it and/or modify
  8.  * it under the terms of the GNU General Public License version 3, as published by
  9.  * the Free Software Foundation.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  18.  *
  19.  */
  20. package org.openspcoop2.utils.service.authentication.preauth.role;

  21. import java.util.Set;

  22. import org.springframework.beans.factory.InitializingBean;
  23. import org.springframework.context.ResourceLoaderAware;
  24. import org.springframework.core.io.ResourceLoader;
  25. import org.springframework.security.core.authority.mapping.MappableAttributesRetriever;

  26. /**
  27.  * AbstractRoleRetriever
  28.  *
  29.  * Classe prototipo per la gestione di un elenco di ruoli custom da utilizzare come input
  30.  * per i check tramite la funzione: public boolean isUserInRole(String role); dell'interfaccia HttpServletRequest.
  31.  * La classe default utilizzata da spring security effettua la lettura dei ruoli previsti dal web.xml,
  32.  * nel caso in cui i ruoli siano definiti come generici '*' prova a invocare il metodo  isUserInRole con parametro '*' facendo fallire l'autenticazione.
  33.  * definire la funzione 'getElencoRuoliCustomAbilitati' restituendo l'elenco dei ruoli abilitati per l'applicazione.
  34.  *
  35.  * @author Giuliano Pintori (pintori@link.it)
  36.  * @author $Author$
  37.  * @version $Rev$, $Date$
  38.  */
  39. public abstract class AbstractRoleRetriever implements ResourceLoaderAware, MappableAttributesRetriever, InitializingBean {
  40.    
  41.     @Override
  42.     public void afterPropertiesSet() throws Exception {
  43.     }

  44.     @Override
  45.     public Set<String> getMappableAttributes() {
  46.         return getElencoRuoliCustomAbilitati();
  47.     }

  48.     @Override
  49.     public void setResourceLoader(ResourceLoader arg0) {
  50.     }

  51.     protected abstract Set<String> getElencoRuoliCustomAbilitati();
  52. }