001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common Development
008: * and Distribution License("CDDL") (collectively, the "License"). You
009: * may not use this file except in compliance with the License. You can obtain
010: * a copy of the License at https://glassfish.dev.java.net/public/CDDL+GPL.html
011: * or glassfish/bootstrap/legal/LICENSE.txt. See the License for the specific
012: * language governing permissions and limitations under the License.
013: *
014: * When distributing the software, include this License Header Notice in each
015: * file and include the License file at glassfish/bootstrap/legal/LICENSE.txt.
016: * Sun designates this particular file as subject to the "Classpath" exception
017: * as provided by Sun in the GPL Version 2 section of the License file that
018: * accompanied this code. If applicable, add the following below the License
019: * Header, with the fields enclosed by brackets [] replaced by your own
020: * identifying information: "Portions Copyrighted [year]
021: * [name of copyright owner]"
022: *
023: * Contributor(s):
024: *
025: * If you wish your version of this file to be governed by only the CDDL or
026: * only the GPL Version 2, indicate your decision by adding "[Contributor]
027: * elects to include this software in this distribution under the [CDDL or GPL
028: * Version 2] license." If you don't indicate a single choice of license, a
029: * recipient has the option to distribute your version of this file under
030: * either the CDDL, the GPL Version 2 or to extend the choice of license to
031: * its licensees as provided above. However, if you add GPL Version 2 code
032: * and therefore, elected the GPL Version 2 license, then the option applies
033: * only if the new code is made subject to such option by the copyright
034: * holder.
035: */
036:
037: package com.sun.xml.ws.security.impl.policyconv;
038:
039: import com.sun.xml.ws.api.model.wsdl.WSDLFault;
040: import com.sun.xml.ws.policy.PolicyAssertion;
041: import com.sun.xml.ws.security.policy.AlgorithmSuite;
042: import com.sun.xml.wss.impl.policy.mls.MessagePolicy;
043: import java.util.ArrayList;
044: import java.util.Collections;
045: import java.util.HashMap;
046: import java.util.HashSet;
047: import java.util.List;
048: import java.util.Set;
049:
050: /**
051: * Cache XWSS Policy i,e MessagePolicy for each message and cache all the
052: * Issued and SecureConversation Tokens for quick lookup.
053: *
054: * @author K.Venugopal@sun.com
055: */
056: public class SecurityPolicyHolder {
057:
058: private MessagePolicy mp = null;
059: private List<PolicyAssertion> scList = null;
060: private List<PolicyAssertion> issuedTokenList = null;
061: private static final List<PolicyAssertion> EMPTY_LIST = Collections
062: .emptyList();
063: private AlgorithmSuite suite = null;
064: private HashMap<WSDLFault, SecurityPolicyHolder> faultFPMap = null;
065: private HashMap<String, Set<PolicyAssertion>> configAssertions;
066:
067: /**
068: * Creates a new instance of SecurityPolicyHolder
069: */
070: public SecurityPolicyHolder() {
071: }
072:
073: public void setMessagePolicy(MessagePolicy mp) {
074: this .mp = mp;
075: }
076:
077: public MessagePolicy getMessagePolicy() {
078: return this .mp;
079: }
080:
081: public void addSecureConversationToken(PolicyAssertion pa) {
082: if (scList == null) {
083: scList = new ArrayList<PolicyAssertion>();
084: }
085: scList.add(pa);
086: }
087:
088: public List<PolicyAssertion> getSecureConversationTokens() {
089: return ((scList == null) ? EMPTY_LIST : scList);
090: }
091:
092: public void addIssuedToken(PolicyAssertion pa) {
093: if (issuedTokenList == null) {
094: issuedTokenList = new ArrayList<PolicyAssertion>();
095: }
096: issuedTokenList.add(pa);
097: }
098:
099: public void addIssuedTokens(List<PolicyAssertion> list) {
100: if (issuedTokenList == null) {
101: issuedTokenList = list;
102: } else {
103: issuedTokenList.addAll(list);
104: }
105: }
106:
107: public List<PolicyAssertion> getIssuedTokens() {
108: return ((issuedTokenList == null) ? EMPTY_LIST
109: : issuedTokenList);
110: }
111:
112: public AlgorithmSuite getBindingLevelAlgSuite() {
113: return suite;
114: }
115:
116: public void setBindingLevelAlgSuite(AlgorithmSuite suite) {
117: this .suite = suite;
118: }
119:
120: public void addFaultPolicy(WSDLFault fault,
121: SecurityPolicyHolder policy) {
122: if (faultFPMap == null) {
123: faultFPMap = new HashMap<WSDLFault, SecurityPolicyHolder>();
124: }
125: faultFPMap.put(fault, policy);
126: }
127:
128: public SecurityPolicyHolder getFaultPolicy(WSDLFault fault) {
129: if (faultFPMap == null) {
130: return null;
131: }
132: return faultFPMap.get(fault);
133: }
134:
135: public void addConfigAssertions(PolicyAssertion assertion) {
136: if (configAssertions == null) {
137: configAssertions = new HashMap<String, Set<PolicyAssertion>>();
138: }
139: Set<PolicyAssertion> assertions = configAssertions
140: .get(assertion.getName().getNamespaceURI());
141: if (assertions == null) {
142: assertions = new HashSet<com.sun.xml.ws.policy.PolicyAssertion>();
143: configAssertions.put(assertion.getName().getNamespaceURI(),
144: assertions);
145: }
146: assertions.add(assertion);
147: }
148:
149: public Set getConfigAssertions(String namespaceuri) {
150: if (configAssertions == null) {
151: return null;
152: }
153: return configAssertions.get(namespaceuri);
154: }
155: }
|