001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.jetspeed.security;
018:
019: import java.security.Policy;
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: /**
024: * <p>
025: * This class is used to hold the security that will be used when applying security policies. It
026: * uses a singleton pattern to maintain state of the policies configured in the consuming engine.
027: * </p>
028: *
029: * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
030: */
031: public class SecurityPolicies {
032: /** The singleton instance. */
033: private static SecurityPolicies instance = null;
034:
035: /** The list of wrapped policies. */
036: private List wrappedPolicies = new ArrayList();
037:
038: /** The list of policies. */
039: private List policies = new ArrayList();
040:
041: /** The list of used policies. */
042: private List usedPolicies = new ArrayList();
043:
044: /**
045: * Default contructor. Private to force singleton.
046: */
047: private SecurityPolicies() {
048: }
049:
050: /**
051: * <p>
052: * Returns the singleton instance for SecurityPolicies.
053: * </p>
054: *
055: * @return The instance of SecurityPolicies
056: */
057: public static SecurityPolicies getInstance() {
058: if (instance == null) {
059: instance = new SecurityPolicies();
060: }
061: return instance;
062: }
063:
064: /**
065: * <p>
066: * Adds a policy to the list of policies to enforces.
067: * </p>
068: *
069: * @param wrappedPolicy The {@link PolicyWrapper} to add.
070: */
071: public void addPolicy(PolicyWrapper wrappedPolicy) {
072: if (null != wrappedPolicy) {
073: wrappedPolicies.add(wrappedPolicy);
074: policies.add(wrappedPolicy.getPolicy());
075: if (wrappedPolicy.isUseAsPolicy()) {
076: usedPolicies.add(wrappedPolicy.getPolicy());
077: }
078: }
079:
080: }
081:
082: /**
083: * <p>
084: * Returns the security policies to enforce as list of {@link Policy}.
085: * </p>
086: *
087: * @return The policies.
088: */
089: public List getPolicies() {
090: return policies;
091: }
092:
093: /**
094: * <p>
095: * Returns the security policies to be enforced as list of {@link Policy}.
096: * </p>
097: *
098: * @return The used policies.
099: */
100: public List getUsedPolicies() {
101: return usedPolicies;
102: }
103:
104: /**
105: * <p>
106: * Returns the security policies to enforce as list of {@link PolicyWrapper}.
107: * </p>
108: *
109: * @return The policies.
110: */
111: public List getWrappedPolicies() {
112: return wrappedPolicies;
113: }
114:
115: /**
116: * <p>
117: * Removes a policy from the list of policies to enforces.
118: * </p>
119: *
120: * @param policy The {@link Policy} to add.
121: */
122: public void removePolicy(PolicyWrapper policy) {
123: wrappedPolicies.remove(policy);
124: }
125: }
|