1/*2* Licensed to the Apache Software Foundation (ASF) under one or more3* contributor license agreements. See the NOTICE file distributed with4* this work for additional information regarding copyright ownership.5* The ASF licenses this file to You under the Apache License, Version 2.06* (the "License"); you may not use this file except in compliance with7* the License. You may obtain a copy of the License at8*9* http://www.apache.org/licenses/LICENSE-2.010*11* Unless required by applicable law or agreed to in writing, software12* distributed under the License is distributed on an "AS IS" BASIS,13* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14* See the License for the specific language governing permissions and15* limitations under the License.16*/17packageorg.apache.jetspeed.security;
1819import java.security.Policy;
20import java.util.ArrayList;
21import java.util.List;
2223/***24 * <p>25 * This class is used to hold the security that will be used when applying security policies. It26 * 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 */31publicclassSecurityPolicies32 {
33/*** The singleton instance. */34privatestaticSecurityPolicies instance = null;
3536/*** The list of wrapped policies. */37private List wrappedPolicies = new ArrayList();
3839/*** The list of policies. */40private List policies = new ArrayList();
4142/*** The list of used policies. */43private List usedPolicies = new ArrayList();
4445/***46 * Default contructor. Private to force singleton.47 */48privateSecurityPolicies()
49 {
50 }
5152/***53 * <p>54 * Returns the singleton instance for SecurityPolicies.55 * </p>56 * 57 * @return The instance of SecurityPolicies58 */59publicstaticSecurityPolicies getInstance()
60 {
61if (instance == null)
62 {
63 instance = newSecurityPolicies();
64 }
65return instance;
66 }
6768/***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 */75publicvoid addPolicy(PolicyWrapper wrappedPolicy)
76 {
77if (null != wrappedPolicy)
78 {
79 wrappedPolicies.add(wrappedPolicy);
80 policies.add(wrappedPolicy.getPolicy());
81if (wrappedPolicy.isUseAsPolicy())
82 {
83 usedPolicies.add(wrappedPolicy.getPolicy());
84 }
85 }
8687 }
8889/***90 * <p>91 * Returns the security policies to enforce as list of {@link Policy}.92 * </p>93 * 94 * @return The policies.95 */96public List getPolicies()
97 {
98return policies;
99 }
100101/***102 * <p>103 * Returns the security policies to be enforced as list of {@link Policy}.104 * </p>105 * 106 * @return The used policies.107 */108public List getUsedPolicies()
109 {
110return usedPolicies;
111 }
112113/***114 * <p>115 * Returns the security policies to enforce as list of {@link PolicyWrapper}.116 * </p>117 * 118 * @return The policies.119 */120public List getWrappedPolicies()
121 {
122return wrappedPolicies;
123 }
124125/***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 */132publicvoid removePolicy(PolicyWrapper policy)
133 {
134 wrappedPolicies.remove(policy);
135 }
136 }