ResultCombining.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.xacml;

  21. import java.util.List;

  22. import org.herasaf.xacml.core.context.impl.DecisionType;
  23. import org.herasaf.xacml.core.context.impl.ResultType;


  24. /**
  25.  * ResultCombining
  26.  *
  27.  * @author Bussu Giovanni (bussu@link.it)
  28.  * @author $Author$
  29.  * @version $Rev$, $Date$
  30.  */
  31. public class ResultCombining {

  32.     public static DecisionType combinePermitOverrides(List<ResultType> resultType) {
  33.         boolean isDeny = false;
  34.         for(ResultType result : resultType) {
  35.             if(result.getDecision().equals(DecisionType.PERMIT)) {
  36.                 return DecisionType.PERMIT;
  37.             } else if(result.getDecision().equals(DecisionType.DENY)) {
  38.                 isDeny = true;
  39.             } else if(result.getDecision().equals(DecisionType.INDETERMINATE)) {
  40.                 return DecisionType.INDETERMINATE;
  41.             }
  42.         }
  43.        
  44.         if(isDeny) {
  45.             return DecisionType.DENY;
  46.         }
  47.        
  48.         return DecisionType.NOT_APPLICABLE;
  49.     }

  50.     public static DecisionType combineDenyOverrides(List<ResultType> resultType) {
  51.         boolean isPermit = false;
  52.         for(ResultType result : resultType) {
  53.             if(result.getDecision().equals(DecisionType.DENY)) {
  54.                 return DecisionType.DENY;
  55.             } else if(result.getDecision().equals(DecisionType.INDETERMINATE)) {
  56.                 return DecisionType.INDETERMINATE;
  57.             } else if(result.getDecision().equals(DecisionType.PERMIT)) {
  58.                 isPermit = true;
  59.             }
  60.         }
  61.        
  62.         if(isPermit) {
  63.             return DecisionType.PERMIT;
  64.         }
  65.        
  66.         return DecisionType.NOT_APPLICABLE;

  67.     }
  68. }