Thu, 31 Aug 2017 15:18:52 +0800
merge
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. Oracle designates this |
aoqi@0 | 8 | * particular file as subject to the "Classpath" exception as provided |
aoqi@0 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
aoqi@0 | 10 | * |
aoqi@0 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 15 | * accompanied this code). |
aoqi@0 | 16 | * |
aoqi@0 | 17 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 20 | * |
aoqi@0 | 21 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 22 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 23 | * questions. |
aoqi@0 | 24 | */ |
aoqi@0 | 25 | |
aoqi@0 | 26 | package com.sun.xml.internal.ws.addressing.policy; |
aoqi@0 | 27 | |
aoqi@0 | 28 | import com.sun.xml.internal.ws.addressing.W3CAddressingMetadataConstants; |
aoqi@0 | 29 | import com.sun.xml.internal.ws.api.WSBinding; |
aoqi@0 | 30 | import com.sun.xml.internal.ws.api.model.SEIModel; |
aoqi@0 | 31 | import com.sun.xml.internal.ws.policy.AssertionSet; |
aoqi@0 | 32 | import com.sun.xml.internal.ws.policy.Policy; |
aoqi@0 | 33 | import com.sun.xml.internal.ws.policy.PolicyAssertion; |
aoqi@0 | 34 | import com.sun.xml.internal.ws.policy.PolicyException; |
aoqi@0 | 35 | import com.sun.xml.internal.ws.policy.PolicyMap; |
aoqi@0 | 36 | import com.sun.xml.internal.ws.policy.PolicySubject; |
aoqi@0 | 37 | import com.sun.xml.internal.ws.policy.jaxws.spi.PolicyMapConfigurator; |
aoqi@0 | 38 | import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger; |
aoqi@0 | 39 | import com.sun.xml.internal.ws.policy.sourcemodel.AssertionData; |
aoqi@0 | 40 | import com.sun.xml.internal.ws.policy.subject.WsdlBindingSubject; |
aoqi@0 | 41 | |
aoqi@0 | 42 | import java.util.ArrayList; |
aoqi@0 | 43 | import java.util.Collection; |
aoqi@0 | 44 | import java.util.Collections; |
aoqi@0 | 45 | import java.util.logging.Level; |
aoqi@0 | 46 | import javax.xml.namespace.QName; |
aoqi@0 | 47 | import javax.xml.ws.soap.AddressingFeature; |
aoqi@0 | 48 | |
aoqi@0 | 49 | /** |
aoqi@0 | 50 | * Generate an addressing policy and updates the PolicyMap if AddressingFeature is enabled. |
aoqi@0 | 51 | * |
aoqi@0 | 52 | * @author Fabian Ritzmann |
aoqi@0 | 53 | * @author Rama Pulavarthi |
aoqi@0 | 54 | */ |
aoqi@0 | 55 | public class AddressingPolicyMapConfigurator implements PolicyMapConfigurator { |
aoqi@0 | 56 | |
aoqi@0 | 57 | private static final PolicyLogger LOGGER = PolicyLogger.getLogger(AddressingPolicyMapConfigurator.class); |
aoqi@0 | 58 | |
aoqi@0 | 59 | private static final class AddressingAssertion extends PolicyAssertion { |
aoqi@0 | 60 | /** |
aoqi@0 | 61 | * Creates an assertion with nested alternatives. |
aoqi@0 | 62 | * |
aoqi@0 | 63 | * @param assertionData |
aoqi@0 | 64 | * @param nestedAlternative |
aoqi@0 | 65 | */ |
aoqi@0 | 66 | AddressingAssertion(AssertionData assertionData, final AssertionSet nestedAlternative) { |
aoqi@0 | 67 | super(assertionData, null, nestedAlternative); |
aoqi@0 | 68 | } |
aoqi@0 | 69 | |
aoqi@0 | 70 | /** |
aoqi@0 | 71 | * Creates an assertion with no nested alternatives. |
aoqi@0 | 72 | * |
aoqi@0 | 73 | * @param assertionData |
aoqi@0 | 74 | */ |
aoqi@0 | 75 | AddressingAssertion(AssertionData assertionData) { |
aoqi@0 | 76 | super(assertionData, null, null); |
aoqi@0 | 77 | } |
aoqi@0 | 78 | } |
aoqi@0 | 79 | |
aoqi@0 | 80 | |
aoqi@0 | 81 | /** |
aoqi@0 | 82 | * Puts an addressing policy into the PolicyMap if the addressing feature was set. |
aoqi@0 | 83 | */ |
aoqi@0 | 84 | public Collection<PolicySubject> update(final PolicyMap policyMap, final SEIModel model, final WSBinding wsBinding) |
aoqi@0 | 85 | throws PolicyException { |
aoqi@0 | 86 | LOGGER.entering(policyMap, model, wsBinding); |
aoqi@0 | 87 | |
aoqi@0 | 88 | Collection<PolicySubject> subjects = new ArrayList<PolicySubject>(); |
aoqi@0 | 89 | if (policyMap != null) { |
aoqi@0 | 90 | final AddressingFeature addressingFeature = wsBinding.getFeature(AddressingFeature.class); |
aoqi@0 | 91 | if (LOGGER.isLoggable(Level.FINEST)) { |
aoqi@0 | 92 | LOGGER.finest("addressingFeature = " + addressingFeature); |
aoqi@0 | 93 | } |
aoqi@0 | 94 | if ((addressingFeature != null) && addressingFeature.isEnabled()) { |
aoqi@0 | 95 | //add wsam:Addrressing assertion if not exists. |
aoqi@0 | 96 | addWsamAddressing(subjects, policyMap, model, addressingFeature); |
aoqi@0 | 97 | } |
aoqi@0 | 98 | } // endif policy map not null |
aoqi@0 | 99 | LOGGER.exiting(subjects); |
aoqi@0 | 100 | return subjects; |
aoqi@0 | 101 | } |
aoqi@0 | 102 | |
aoqi@0 | 103 | private void addWsamAddressing(Collection<PolicySubject> subjects, PolicyMap policyMap, SEIModel model, AddressingFeature addressingFeature) |
aoqi@0 | 104 | throws PolicyException { |
aoqi@0 | 105 | final QName bindingName = model.getBoundPortTypeName(); |
aoqi@0 | 106 | final WsdlBindingSubject wsdlSubject = WsdlBindingSubject.createBindingSubject(bindingName); |
aoqi@0 | 107 | final Policy addressingPolicy = createWsamAddressingPolicy(bindingName, addressingFeature); |
aoqi@0 | 108 | final PolicySubject addressingPolicySubject = new PolicySubject(wsdlSubject, addressingPolicy); |
aoqi@0 | 109 | subjects.add(addressingPolicySubject); |
aoqi@0 | 110 | if (LOGGER.isLoggable(Level.FINE)) { |
aoqi@0 | 111 | LOGGER.fine("Added addressing policy with ID \"" + addressingPolicy.getIdOrName() + "\" to binding element \"" + bindingName + "\""); |
aoqi@0 | 112 | } |
aoqi@0 | 113 | } |
aoqi@0 | 114 | |
aoqi@0 | 115 | /** |
aoqi@0 | 116 | * Create a policy with an WSAM Addressing assertion. |
aoqi@0 | 117 | */ |
aoqi@0 | 118 | private Policy createWsamAddressingPolicy(final QName bindingName, AddressingFeature af) { |
aoqi@0 | 119 | final ArrayList<AssertionSet> assertionSets = new ArrayList<AssertionSet>(1); |
aoqi@0 | 120 | final ArrayList<PolicyAssertion> assertions = new ArrayList<PolicyAssertion>(1); |
aoqi@0 | 121 | final AssertionData addressingData = |
aoqi@0 | 122 | AssertionData.createAssertionData(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION); |
aoqi@0 | 123 | if (!af.isRequired()) { |
aoqi@0 | 124 | addressingData.setOptionalAttribute(true); |
aoqi@0 | 125 | } |
aoqi@0 | 126 | try { |
aoqi@0 | 127 | AddressingFeature.Responses responses = af.getResponses(); |
aoqi@0 | 128 | if (responses == AddressingFeature.Responses.ANONYMOUS) { |
aoqi@0 | 129 | AssertionData nestedAsserData = AssertionData.createAssertionData(W3CAddressingMetadataConstants.WSAM_ANONYMOUS_NESTED_ASSERTION); |
aoqi@0 | 130 | PolicyAssertion nestedAsser = new AddressingAssertion(nestedAsserData, null); |
aoqi@0 | 131 | assertions.add(new AddressingAssertion(addressingData, AssertionSet.createAssertionSet(Collections.singleton(nestedAsser)))); |
aoqi@0 | 132 | } else if (responses == AddressingFeature.Responses.NON_ANONYMOUS) { |
aoqi@0 | 133 | final AssertionData nestedAsserData = AssertionData.createAssertionData(W3CAddressingMetadataConstants.WSAM_NONANONYMOUS_NESTED_ASSERTION); |
aoqi@0 | 134 | PolicyAssertion nestedAsser = new AddressingAssertion(nestedAsserData, null); |
aoqi@0 | 135 | assertions.add(new AddressingAssertion(addressingData, AssertionSet.createAssertionSet(Collections.singleton(nestedAsser)))); |
aoqi@0 | 136 | } else { |
aoqi@0 | 137 | assertions.add(new AddressingAssertion(addressingData, AssertionSet.createAssertionSet(null))); |
aoqi@0 | 138 | } |
aoqi@0 | 139 | } catch (NoSuchMethodError e) { |
aoqi@0 | 140 | //If JAX-WS 2.2 API is really required, it would been reported in @Addressing or wsam:Addressing processing |
aoqi@0 | 141 | //Don't add any nested assertion to mimic the 2.1 behavior |
aoqi@0 | 142 | assertions.add(new AddressingAssertion(addressingData, AssertionSet.createAssertionSet(null))); |
aoqi@0 | 143 | } |
aoqi@0 | 144 | assertionSets.add(AssertionSet.createAssertionSet(assertions)); |
aoqi@0 | 145 | return Policy.createPolicy(null, bindingName.getLocalPart() + "_WSAM_Addressing_Policy", assertionSets); |
aoqi@0 | 146 | } |
aoqi@0 | 147 | } |