1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.jetspeed.security;
18
19 import java.security.Policy;
20 import java.util.ArrayList;
21 import java.util.List;
22
23 /***
24 * <p>
25 * This class is used to hold the security that will be used when applying security policies. It
26 * uses a singleton pattern to maintain state of the policies configured in the consuming engine.
27 * </p>
28 *
29 * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
30 */
31 public class SecurityPolicies
32 {
33 /*** The singleton instance. */
34 private static SecurityPolicies instance = null;
35
36 /*** The list of wrapped policies. */
37 private List wrappedPolicies = new ArrayList();
38
39 /*** The list of policies. */
40 private List policies = new ArrayList();
41
42 /*** The list of used policies. */
43 private List usedPolicies = new ArrayList();
44
45 /***
46 * Default contructor. Private to force singleton.
47 */
48 private SecurityPolicies()
49 {
50 }
51
52 /***
53 * <p>
54 * Returns the singleton instance for SecurityPolicies.
55 * </p>
56 *
57 * @return The instance of SecurityPolicies
58 */
59 public static SecurityPolicies getInstance()
60 {
61 if (instance == null)
62 {
63 instance = new SecurityPolicies();
64 }
65 return instance;
66 }
67
68 /***
69 * <p>
70 * Adds a policy to the list of policies to enforces.
71 * </p>
72 *
73 * @param wrappedPolicy The {@link PolicyWrapper} to add.
74 */
75 public void addPolicy(PolicyWrapper wrappedPolicy)
76 {
77 if (null != wrappedPolicy)
78 {
79 wrappedPolicies.add(wrappedPolicy);
80 policies.add(wrappedPolicy.getPolicy());
81 if (wrappedPolicy.isUseAsPolicy())
82 {
83 usedPolicies.add(wrappedPolicy.getPolicy());
84 }
85 }
86
87 }
88
89 /***
90 * <p>
91 * Returns the security policies to enforce as list of {@link Policy}.
92 * </p>
93 *
94 * @return The policies.
95 */
96 public List getPolicies()
97 {
98 return policies;
99 }
100
101 /***
102 * <p>
103 * Returns the security policies to be enforced as list of {@link Policy}.
104 * </p>
105 *
106 * @return The used policies.
107 */
108 public List getUsedPolicies()
109 {
110 return usedPolicies;
111 }
112
113 /***
114 * <p>
115 * Returns the security policies to enforce as list of {@link PolicyWrapper}.
116 * </p>
117 *
118 * @return The policies.
119 */
120 public List getWrappedPolicies()
121 {
122 return wrappedPolicies;
123 }
124
125 /***
126 * <p>
127 * Removes a policy from the list of policies to enforces.
128 * </p>
129 *
130 * @param policy The {@link Policy} to add.
131 */
132 public void removePolicy(PolicyWrapper policy)
133 {
134 wrappedPolicies.remove(policy);
135 }
136 }