Coverage Report - org.openpermis.policy.AccessDecision
 
Classes in this File Line Coverage Branch Coverage Complexity
AccessDecision
91%
11/12
50%
1/2
1.5
 
 1  
 /*
 2  
  * Copyright (c) 2009, Swiss Federal Department of Defence Civil Protection and Sport
 3  
  *                     (http://www.vbs.admin.ch)
 4  
  * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch)
 5  
  * All rights reserved.
 6  
  *
 7  
  * Licensed under the Open Permis License which accompanies this distribution,
 8  
  * and is available at http://www.openpermis.org/BSDlicenceKent.txt
 9  
  */
 10  
 package org.openpermis.policy;
 11  
 
 12  
 import java.util.Collections;
 13  
 import java.util.List;
 14  
 import java.util.Set;
 15  
 
 16  
 
 17  
 /**
 18  
  * The result of an access request.
 19  
  * <p>An access includes a boolean decision and may contain a list of obligation sets.
 20  
  * @since 0.1.0
 21  
  */
 22  
 public final class AccessDecision {
 23  
 
 24  
         //---- Static
 25  
 
 26  
         //---- State
 27  
 
 28  
         private boolean decision;
 29  
 
 30  
         private List<Set<String>> obligations;
 31  
         
 32  
         //---- Constructors
 33  
         
 34  
         /**
 35  
          * Creates a new authorization decision.
 36  
          * @param decision of this authorization.
 37  
          * @since 0.1.0
 38  
          */
 39  16
         public AccessDecision (boolean decision) {
 40  16
                 this.decision = decision;
 41  16
                 this.obligations = Collections.emptyList();
 42  16
         }
 43  
         
 44  
         /**
 45  
          * Creates a new conditionally authorization decision. Obligations must not be 
 46  
          * <code>null</code>.
 47  
          * @param decision of this authorization.
 48  
          * @param obligations a list of obligation sets.
 49  
          * @since 0.3.0
 50  
          */
 51  10
         public AccessDecision (boolean decision, List<Set<String>> obligations) {
 52  10
                 if (obligations == null) {
 53  0
                         throw new IllegalArgumentException("Obligations is null.");
 54  
                 }
 55  10
                 this.decision = decision;
 56  10
                 this.obligations = obligations;
 57  10
         }
 58  
         
 59  
         //---- Methods
 60  
         
 61  
         /**
 62  
          * Returns true if access is granted.
 63  
          * @return <code>true</code> if access is granted.
 64  
          * @since 0.1.0
 65  
          */
 66  
         public boolean isAccessGranted () {
 67  19
                 return this.decision;
 68  
         }
 69  
         
 70  
         /**
 71  
          * Returns a list of obligation sets for this authorization decision. The list is never 
 72  
          * <code>null</code>and contains at least one empty set, indicating an unconditionally decision 
 73  
          * (meaning no obligations).
 74  
          * @return a list of obligation sets for this access decision.
 75  
          * @since 0.3.0
 76  
          */
 77  
         public List<Set<String>> getObligations () {
 78  6
                 return this.obligations;
 79  
         }
 80  
 
 81  
 
 82  
 }