AuthorizationConfig.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.authorization;

  21. import java.util.ArrayList;
  22. import java.util.Enumeration;
  23. import java.util.List;
  24. import java.util.Properties;

  25. import org.openspcoop2.utils.UtilsException;

  26. /**
  27.  * AuthorizationConfig
  28.  *
  29.  * @author Andrea Poli (apoli@link.it)
  30.  * @author $Author$
  31.  * @version $Rev$, $Date$
  32.  */
  33. public class AuthorizationConfig {

  34.     private List<AuthorizationConfigACL> aclList = new ArrayList<>();

  35.     public AuthorizationConfig() {
  36.     }
  37.     public AuthorizationConfig(Properties p) throws UtilsException {
  38.        
  39.         List<String> aclNames = new ArrayList<>();
  40.         Enumeration<?> keys = p.keys();
  41.         while (keys.hasMoreElements()) {
  42.             Object object = (Object) keys.nextElement();
  43.             if(object instanceof String) {
  44.                 String key = (String) object;
  45.                 if(key.startsWith(AuthorizationConfigACL.PREFIX) && key.endsWith(AuthorizationConfigACL.SUFFIX_METHOD)){
  46.                     String aclName = key.substring(AuthorizationConfigACL.PREFIX.length());
  47.                     aclName = aclName.substring(0, (aclName.length()-AuthorizationConfigACL.SUFFIX_METHOD.length()));
  48.                     aclNames.add(aclName);
  49.                 }
  50.             }
  51.         }
  52.        
  53.         if(aclNames.size()>0) {
  54.             for (String aclName : aclNames) {
  55.                 this.aclList.add(new AuthorizationConfigACL(aclName, p));
  56.             }
  57.         }
  58.        
  59.     }
  60.    
  61.    
  62.     public void addAcl(AuthorizationConfigACL acl) {
  63.         this.aclList.add(acl);
  64.     }
  65.     public List<AuthorizationConfigACL> getAclList() {
  66.         return this.aclList;
  67.     }
  68.    
  69. }