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.policy.jaxws;
038:
039: import com.sun.xml.ws.policy.AssertionValidationProcessor;
040: import com.sun.xml.ws.policy.PolicyAssertion;
041: import javax.xml.namespace.QName;
042: import javax.xml.stream.FactoryConfigurationError;
043: import javax.xml.ws.WebServiceException;
044: import com.sun.xml.ws.api.model.wsdl.WSDLExtension;
045: import com.sun.xml.ws.api.model.wsdl.WSDLModel;
046: import com.sun.xml.ws.policy.AssertionSet;
047: import com.sun.xml.ws.policy.PolicyMapExtender;
048: import com.sun.xml.ws.policy.PolicyMapKey;
049: import com.sun.xml.ws.policy.PolicySubject;
050: import com.sun.xml.ws.policy.EffectiveAlternativeSelector;
051: import com.sun.xml.ws.policy.EffectivePolicyModifier;
052: import com.sun.xml.ws.policy.Policy;
053: import com.sun.xml.ws.policy.PolicyException;
054: import com.sun.xml.ws.policy.PolicyMap;
055: import com.sun.xml.ws.policy.jaxws.privateutil.LocalizationMessages;
056: import com.sun.xml.ws.policy.privateutil.PolicyLogger;
057: import com.sun.xml.ws.policy.jaxws.spi.ModelConfiguratorProvider;
058: import com.sun.xml.ws.policy.privateutil.PolicyUtils;
059: import com.sun.xml.ws.policy.spi.PolicyAssertionValidator;
060:
061: /**
062: * TODO: write doc
063: *
064: * @author Jakub Podlesak (jakub.podlesak at sun.com)
065: */
066: public class WSDLPolicyMapWrapper implements WSDLExtension {
067: private static final PolicyLogger LOGGER = PolicyLogger
068: .getLogger(WSDLPolicyMapWrapper.class);
069: private static final QName NAME = new QName(null,
070: "WSDLPolicyMapWrapper");
071:
072: private static ModelConfiguratorProvider[] configurators = PolicyUtils.ServiceProvider
073: .load(ModelConfiguratorProvider.class);
074:
075: private PolicyMap policyMap;
076: private EffectivePolicyModifier mapModifier;
077: private PolicyMapExtender mapExtender;
078:
079: protected WSDLPolicyMapWrapper(PolicyMap policyMap) {
080: if (policyMap == null) {
081: throw new IllegalArgumentException(LocalizationMessages
082: .WSP_1016_POLICY_MAP_CAN_NOT_BE_NULL());
083: }
084:
085: this .policyMap = policyMap;
086: }
087:
088: public WSDLPolicyMapWrapper(PolicyMap policyMap,
089: EffectivePolicyModifier modifier, PolicyMapExtender extender) {
090: this (policyMap);
091: this .mapModifier = modifier;
092: this .mapExtender = extender;
093: }
094:
095: public PolicyMap getPolicyMap() {
096: return policyMap;
097: }
098:
099: void addClientConfigToMap(final Object clientWsitConfigId,
100: final PolicyMap clientPolicyMap) throws PolicyException {
101: LOGGER.entering();
102:
103: try {
104: for (PolicyMapKey key : clientPolicyMap
105: .getAllServiceScopeKeys()) {
106: final Policy policy = clientPolicyMap
107: .getServiceEffectivePolicy(key);
108: // setting subject to provided URL of client WSIT config
109: mapExtender.putServiceSubject(key, new PolicySubject(
110: clientWsitConfigId, policy));
111: }
112:
113: for (PolicyMapKey key : clientPolicyMap
114: .getAllEndpointScopeKeys()) {
115: final Policy policy = clientPolicyMap
116: .getEndpointEffectivePolicy(key);
117: // setting subject to provided URL of client WSIT config
118: mapExtender.putEndpointSubject(key, new PolicySubject(
119: clientWsitConfigId, policy));
120: }
121:
122: for (PolicyMapKey key : clientPolicyMap
123: .getAllOperationScopeKeys()) {
124: final Policy policy = clientPolicyMap
125: .getOperationEffectivePolicy(key);
126: // setting subject to provided URL of client WSIT config
127: mapExtender.putOperationSubject(key, new PolicySubject(
128: clientWsitConfigId, policy));
129: }
130:
131: for (PolicyMapKey key : clientPolicyMap
132: .getAllInputMessageScopeKeys()) {
133: final Policy policy = clientPolicyMap
134: .getInputMessageEffectivePolicy(key);
135: // setting subject to provided URL of client WSIT config
136: mapExtender.putInputMessageSubject(key,
137: new PolicySubject(clientWsitConfigId, policy));
138: }
139:
140: for (PolicyMapKey key : clientPolicyMap
141: .getAllOutputMessageScopeKeys()) {
142: final Policy policy = clientPolicyMap
143: .getOutputMessageEffectivePolicy(key);
144: // setting subject to provided URL of client WSIT config
145: mapExtender.putOutputMessageSubject(key,
146: new PolicySubject(clientWsitConfigId, policy));
147: }
148:
149: for (PolicyMapKey key : clientPolicyMap
150: .getAllFaultMessageScopeKeys()) {
151: final Policy policy = clientPolicyMap
152: .getFaultMessageEffectivePolicy(key);
153: // setting subject to provided URL of client WSIT config
154: mapExtender.putFaultMessageSubject(key,
155: new PolicySubject(clientWsitConfigId, policy));
156: }
157: LOGGER
158: .fine(LocalizationMessages
159: .WSP_1041_CLIENT_CFG_POLICIES_TRANSFERED_INTO_FINAL_POLICY_MAP(policyMap));
160: } catch (FactoryConfigurationError ex) {
161: throw LOGGER.logSevereException(new PolicyException(ex));
162: }
163:
164: LOGGER.exiting();
165: }
166:
167: public void doAlternativeSelection() throws PolicyException {
168: EffectiveAlternativeSelector.doSelection(mapModifier);
169: }
170:
171: void validateServerSidePolicies() throws PolicyException {
172: final AssertionValidationProcessor validationProcessor = AssertionValidationProcessor
173: .getInstance();
174: for (Policy policy : policyMap) {
175:
176: // TODO: here is a good place to check if the actual policy has only one alternative...
177:
178: for (AssertionSet assertionSet : policy) {
179: for (PolicyAssertion assertion : assertionSet) {
180: PolicyAssertionValidator.Fitness validationResult = validationProcessor
181: .validateServerSide(assertion);
182: if (validationResult != PolicyAssertionValidator.Fitness.SUPPORTED) {
183: throw LOGGER
184: .logSevereException(new PolicyException(
185: LocalizationMessages
186: .WSP_1046_SERVER_SIDE_ASSERTION_VALIDATION_FAILED(
187: assertion
188: .getName(),
189: validationResult)));
190: }
191: }
192: }
193: }
194: }
195:
196: void configureModel(final WSDLModel model) {
197: try {
198: for (ModelConfiguratorProvider configurator : configurators) {
199: configurator.configure(model, policyMap);
200: }
201: } catch (PolicyException e) {
202: throw LOGGER
203: .logSevereException(new WebServiceException(
204: LocalizationMessages
205: .WSP_1032_FAILED_CONFIGURE_WSDL_MODEL(),
206: e));
207: }
208: }
209:
210: void putEndpointSubject(final PolicyMapKey key,
211: final PolicySubject subject) {
212: if (null != this .mapExtender) {
213: this .mapExtender.putEndpointSubject(key, subject);
214: }
215: }
216:
217: void putServiceSubject(final PolicyMapKey key,
218: final PolicySubject subject) {
219: if (null != this .mapExtender) {
220: this .mapExtender.putServiceSubject(key, subject);
221: }
222: }
223:
224: void putOperationSubject(final PolicyMapKey key,
225: final PolicySubject subject) {
226: if (null != this .mapExtender) {
227: this .mapExtender.putOperationSubject(key, subject);
228: }
229: }
230:
231: void putInputMessageSubject(final PolicyMapKey key,
232: final PolicySubject subject) {
233: if (null != this .mapExtender) {
234: this .mapExtender.putInputMessageSubject(key, subject);
235: }
236: }
237:
238: void putOutputMessageSubject(final PolicyMapKey key,
239: final PolicySubject subject) {
240: if (null != this .mapExtender) {
241: this .mapExtender.putOutputMessageSubject(key, subject);
242: }
243: }
244:
245: void putFaultMessageSubject(final PolicyMapKey key,
246: final PolicySubject subject) {
247: if (null != this .mapExtender) {
248: this .mapExtender.putFaultMessageSubject(key, subject);
249: }
250: }
251:
252: public QName getName() {
253: return NAME;
254: }
255: }
|