Coverage Report - org.openpermis.basic.ExpirablePolicyDecisionPoint
 
Classes in this File Line Coverage Branch Coverage Complexity
ExpirablePolicyDecisionPoint
88%
8/9
66%
4/6
3.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.basic;
 11  
 
 12  
 import java.net.URI;
 13  
 import java.util.List;
 14  
 
 15  
 import org.openpermis.PolicyDecisionException;
 16  
 import org.openpermis.PolicyDecisionPoint;
 17  
 import org.openpermis.Subject;
 18  
 import org.openpermis.policy.AccessDecision;
 19  
 import org.openpermis.policy.TimeStamp;
 20  
 
 21  
 
 22  
 /**
 23  
  * A {@link PolicyDecisionPoint} that may expire.
 24  
  * @since 0.3.0
 25  
  */
 26  
 public class ExpirablePolicyDecisionPoint implements PolicyDecisionPoint {
 27  
 
 28  
         //---- Static
 29  
         
 30  
         private static final long serialVersionUID = -6004982641311679046L;
 31  
 
 32  
         //---- State
 33  
         
 34  
         private final PolicyDecisionPoint pdp;
 35  
         
 36  
         private final TimePeriod validity;
 37  
         
 38  
         //---- Constructors
 39  
         
 40  
         /**
 41  
          * Create an expirable policy decision point. 
 42  
          * @param pdp a {@link PolicyDecisionPoint}.
 43  
          * @param validity an expirable {@link TimePeriod}.
 44  
          * @since 0.3.0
 45  
          */
 46  2
         public ExpirablePolicyDecisionPoint (PolicyDecisionPoint pdp, TimePeriod validity) {
 47  2
                 if (pdp == null || validity == null) {
 48  0
                         throw new IllegalArgumentException("Pdp or validity is null.");
 49  
                 }
 50  2
                 this.pdp = pdp;
 51  2
                 this.validity = validity;
 52  2
         }
 53  
         
 54  
         //---- PolicyDecisionPoint
 55  
         
 56  
         /**
 57  
          * @since 0.3.0
 58  
          */
 59  
         public AccessDecision getAccessDecision (
 60  
                 Subject subject, URI resourceUri, String actionName, List<?> arguments, TimeStamp timeStamp
 61  
         ) 
 62  
                 throws PolicyDecisionException 
 63  
         {
 64  
                 // Fail: Policy decision point is expired.
 65  3
                 if (!this.validity.contains(timeStamp)) {
 66  1
                         return new AccessDecision(false);
 67  
                 }
 68  
                 // Delegate decision to policy decision point.
 69  2
                 return this.pdp.getAccessDecision(
 70  
                         subject, resourceUri, actionName, arguments, timeStamp
 71  
                 );
 72  
         }
 73  
 
 74  
 }