Coverage Report - org.openpermis.policy.AccessDecision
 
Classes in this File Line Coverage Branch Coverage Complexity
AccessDecision
93%
14/15
75%
3/4
1.8
 
 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  
         //---- State
 25  
 
 26  
         /**
 27  
          * @since 0.1.0
 28  
          */
 29  
         private final boolean decision;
 30  
 
 31  
         /**
 32  
          * @since 0.3.0
 33  
          */
 34  
         private final List<Set<String>> obligations;
 35  
         
 36  
         //---- Constructors
 37  
         
 38  
         /**
 39  
          * Creates a new authorization decision.
 40  
          * @param decision of this authorization.
 41  
          * @since 0.1.0
 42  
          */
 43  16
         public AccessDecision (boolean decision) {
 44  16
                 this.decision = decision;
 45  16
                 this.obligations = Collections.emptyList();
 46  16
         }
 47  
         
 48  
         /**
 49  
          * Creates a new conditionally authorization decision. Obligations must not be 
 50  
          * <code>null</code>.
 51  
          * @param decision of this authorization.
 52  
          * @param obligations a list of obligation sets.
 53  
          * @since 0.3.0
 54  
          */
 55  10
         public AccessDecision (boolean decision, List<Set<String>> obligations) {
 56  10
                 if (obligations == null) {
 57  0
                         throw new IllegalArgumentException("Obligations is null.");
 58  
                 }
 59  10
                 this.decision = decision;
 60  10
                 this.obligations = obligations;
 61  10
         }
 62  
         
 63  
         //---- Methods
 64  
         
 65  
         /**
 66  
          * Returns true if access is granted.
 67  
          * @return <code>true</code> if access is granted.
 68  
          * @since 0.1.0
 69  
          */
 70  
         public boolean isAccessGranted () {
 71  30
                 return this.decision;
 72  
         }
 73  
         
 74  
         /**
 75  
          * Returns a list of obligation sets for this authorization decision. The list is never 
 76  
          * <code>null</code>and contains at least one empty set, indicating an unconditionally decision 
 77  
          * (meaning no obligations).
 78  
          * @return a list of obligation sets for this access decision.
 79  
          * @since 0.3.0
 80  
          */
 81  
         public List<Set<String>> getObligations () {
 82  14
                 return this.obligations;
 83  
         }
 84  
 
 85  
         //---- Object
 86  
         
 87  
         /**
 88  
          * Returns a short description of this access decision consisting of the result and
 89  
          * any obligations if applicable.
 90  
          * @return the description requested.
 91  
          * @since 0.4.0
 92  
          */
 93  
         @Override
 94  
         public String toString () {
 95  11
                 if (isAccessGranted()) {
 96  8
                         return "granted [obligations=" + getObligations() + "]";
 97  
                 }
 98  3
                 return "denied";
 99  
         }
 100  
 
 101  
 }