001: /*
002: * $Id: SecurityPolicyContainer.java,v 1.4 2007/01/08 09:29:00 ashutoshshahi Exp $
003: */
004:
005: /*
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
025: */
026:
027: package com.sun.xml.wss.impl.policy;
028:
029: import java.util.HashMap;
030: import java.util.Iterator;
031: import java.util.ArrayList;
032:
033: import com.sun.xml.wss.impl.PolicyTypeUtil;
034:
035: /**
036: * Represents a container for a static collection of SecurityPolicies.
037: * It Associates a StaticPolicyContext with a SecurityPolicy.
038: */
039: public class SecurityPolicyContainer implements SecurityPolicy {
040:
041: protected HashMap _ctx2PolicyMap = new HashMap();
042:
043: public SecurityPolicyContainer() {
044: }
045:
046: /**
047: * Associate more than one SecurityPolicy with a StaticPolicyContext
048: * @param ctx StaticPolicyContext
049: * @param policy SecurityPolicy
050: */
051: public void setSecurityPolicy(StaticPolicyContext ctx,
052: SecurityPolicy policy) {
053: ArrayList al = (ArrayList) _ctx2PolicyMap.get(ctx);
054:
055: if (al != null)
056: al.add(policy);
057: else {
058: al = new ArrayList();
059: al.add(policy);
060: _ctx2PolicyMap.put(ctx, al);
061: }
062: }
063:
064: /**
065: * Return an immutable collection of SecurityPolicies,
066: * association between policies are free to inference
067: *
068: * @param ctx StaticPolicyContext
069: * @return Iterator of security policies associated with the StaticPolicyContext <code>ctx</code>
070: */
071: public Iterator getSecurityPolicies(StaticPolicyContext ctx) {
072: ArrayList list = (ArrayList) _ctx2PolicyMap.get(ctx);
073:
074: if (list != null)
075: return list.iterator();
076: return null;
077: }
078:
079: /**
080: * Returns all keys (StaticPolicyContext)
081: * @return Iterator on Key Set
082: */
083: public Iterator getAllContexts() {
084: return _ctx2PolicyMap.keySet().iterator();
085: }
086:
087: /*
088: * Composite SecurityPolicy instances are evaluated at runtime,
089: * Throws PolicyGenerationException if evaluation is unsuccessful
090: *
091: * @param sCtx StaticPolicyContext
092: * dCtx DynamicPolicyContext
093: * @return Iterator of SecurityPolicies
094: * @exception PolicyGenerationException
095: */
096: public Iterator getSecurityPolicies(StaticPolicyContext sCtx,
097: DynamicPolicyContext dCtx) throws PolicyGenerationException {
098: ArrayList hs0 = (ArrayList) _ctx2PolicyMap.get(sCtx);
099:
100: ArrayList hs1 = new ArrayList();
101:
102: Iterator i = hs0.iterator();
103: while (i.hasNext()) {
104: Object obj = i.next();
105:
106: /*if (obj instanceof PolicyComposer) {
107: PolicyComposer pc = (PolicyComposer)obj;
108: try {
109: SecurityPolicy sp = pc.evaluateSecurityPolicy(dCtx);
110: hs1.add(sp);
111: } catch (UnsupportedOperationException uoe) {
112: try {
113: Collection s = pc.evaluate(dCtx);
114: hs1.addAll(s);
115: } catch (UnsupportedOperationException eou) {
116: throw new PolicyGenerationException(eou);
117: }
118: }
119: } else*/
120: hs1.add(obj);
121: }
122:
123: return hs1.iterator();
124: }
125:
126: /**
127: * @return the type of the policy
128: */
129: public String getType() {
130: return PolicyTypeUtil.SEC_POLICY_CONTAINER_TYPE;
131: }
132:
133: }
|