Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
AuthorizedRoles |
|
| 2.6666666666666665;2.667 |
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 | //---- Static | |
22 | ||
23 | //---- State | |
24 | ||
25 | private Set<Role> roles; | |
26 | ||
27 | private ObligationCollection obligations; | |
28 | ||
29 | //---- Constructors | |
30 | ||
31 | /** | |
32 | * Creates a new authorized roles. | |
33 | * @param roles a {@link Set} of {@link Role}s. | |
34 | * @param obligations an {@link ObligationCollection}. | |
35 | */ | |
36 | 13 | public AuthorizedRoles (Set<Role> roles, ObligationCollection obligations) { |
37 | 13 | if (roles == null) { |
38 | 0 | throw new IllegalArgumentException("Roles is null."); |
39 | } | |
40 | 13 | if (obligations == null) { |
41 | 0 | throw new IllegalArgumentException("Obligations is null"); |
42 | } | |
43 | ||
44 | 13 | this.roles = new HashSet<Role>(); |
45 | 13 | for (Role role : roles) { |
46 | 18 | this.roles.add(role); |
47 | } | |
48 | ||
49 | 13 | this.obligations = obligations; |
50 | 13 | } |
51 | ||
52 | //---- Methods | |
53 | ||
54 | /** | |
55 | * Returns the authorized roles. | |
56 | * @return the authorized roles. | |
57 | * @since 0.3.0 | |
58 | */ | |
59 | public Set<Role> getRoles () { | |
60 | 24 | return this.roles; |
61 | } | |
62 | ||
63 | /** | |
64 | * Returns the set of obligations for this authorized roles. | |
65 | * @return the set of obligations for this authorized roles. | |
66 | * @since 0.3.0 | |
67 | */ | |
68 | public Set<String> getObligations () { | |
69 | 8 | return this.obligations.getObligationStrings(); |
70 | } | |
71 | ||
72 | } |