Coverage Report - org.openpermis.policy.AuthorizedRoles
 
Classes in this File Line Coverage Branch Coverage Complexity
AuthorizedRoles
84%
11/13
66%
4/6
2.25
 
 1  
 /*
 2  
  * Copyright (c) 2009, Ergon Informatik AG (http://www.ergon.ch)
 3  
  * All rights reserved.
 4  
  * 
 5  
  * Licensed under the Open Permis License which accompanies this distribution, 
 6  
  * and is available at http://www.openpermis.org/BSDlicenceKent.txt
 7  
  */
 8  
 package org.openpermis.policy;
 9  
 
 10  
 import java.util.HashSet;
 11  
 import java.util.Set;
 12  
 
 13  
 
 14  
 /**
 15  
  * All roles that are needed for requested access and the according obligations that must be 
 16  
  * fulfilled.
 17  
  * @since 0.3.0
 18  
  */
 19  
 public final class AuthorizedRoles {
 20  
 
 21  
         //---- State
 22  
         
 23  
         /**
 24  
          * @since 0.3.0
 25  
          */
 26  
         private final Set<Role> roles;
 27  
         
 28  
         /**
 29  
          * @since 0.3.0
 30  
          */
 31  
         private final ObligationCollection obligations;
 32  
         
 33  
         //---- Constructors
 34  
         
 35  
         /**
 36  
          * Creates a new authorized roles.
 37  
          * @param roles a {@link Set} of {@link Role}s.
 38  
          * @param obligations an {@link ObligationCollection}.
 39  
          * @since 0.3.0
 40  
          */
 41  13
         public AuthorizedRoles (Set<Role> roles, ObligationCollection obligations) {
 42  13
                 if (roles == null) {
 43  0
                         throw new IllegalArgumentException("Roles is null.");
 44  
                 }
 45  13
                 if (obligations == null) {
 46  0
                         throw new IllegalArgumentException("Obligations is null");
 47  
                 }
 48  
                 
 49  13
                 this.roles = new HashSet<Role>();
 50  13
                 for (Role role : roles) {
 51  18
                         this.roles.add(role);
 52  
                 }
 53  
                 
 54  13
                 this.obligations = obligations;
 55  13
         }
 56  
         
 57  
         //---- Methods
 58  
         
 59  
         /**
 60  
          * Check if verified roles specified contain all roles of this authorized roles object. 
 61  
          * @param verifiedRoles the verified roles to match.
 62  
          * @return {@code true} if the verified roles contain all roles of this object,
 63  
          * {@code false} otherwise.
 64  
          * @since 0.4.0
 65  
          */
 66  
         public boolean match (Set<Role> verifiedRoles) {
 67  11
                 return verifiedRoles.containsAll(getRoles());
 68  
         }
 69  
         
 70  
         /**
 71  
          * Returns the authorized roles.
 72  
          * @return the authorized roles.
 73  
          * @since 0.3.0
 74  
          */
 75  
         public Set<Role> getRoles () {
 76  24
                 return this.roles;
 77  
         }
 78  
         
 79  
         /**
 80  
          * Returns the set of obligations for this authorized roles.
 81  
          * @return the set of obligations for this authorized roles.
 82  
          * @since 0.3.0
 83  
          */
 84  
         public Set<String> getObligations () {
 85  8
                 return this.obligations.getObligationStrings();
 86  
         }
 87  
 
 88  
 }