001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one
003: * or more contributor license agreements. See the NOTICE file
004: * distributed with this work for additional information
005: * regarding copyright ownership. The ASF licenses this file
006: * to you under the Apache License, Version 2.0 (the
007: * "License"); you may not use this file except in compliance
008: * with the License. You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing,
013: * software distributed under the License is distributed on an
014: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015: * KIND, either express or implied. See the License for the
016: * specific language governing permissions and limitations
017: * under the License.
018: */package org.apache.cxf.ws.policy;
019:
020: import java.util.logging.Logger;
021:
022: import org.apache.cxf.common.logging.LogUtils;
023: import org.apache.cxf.endpoint.Endpoint;
024: import org.apache.cxf.message.Exchange;
025: import org.apache.cxf.message.Message;
026: import org.apache.cxf.message.MessageUtils;
027: import org.apache.cxf.phase.Phase;
028: import org.apache.cxf.service.model.BindingOperationInfo;
029: import org.apache.cxf.service.model.EndpointInfo;
030:
031: /**
032: *
033: */
034: public class PolicyVerificationInInterceptor extends
035: AbstractPolicyInterceptor {
036:
037: private static final Logger LOG = LogUtils
038: .getL7dLogger(PolicyVerificationInInterceptor.class);
039:
040: public PolicyVerificationInInterceptor() {
041: super (Phase.PRE_INVOKE);
042: }
043:
044: /**
045: * Determines the effective policy, and checks if one of its alternatives
046: * is supported.
047: *
048: * @param message
049: * @throws PolicyException if none of the alternatives is supported
050: */
051: protected void handle(Message message) {
052: Exchange exchange = message.getExchange();
053: assert null != exchange;
054:
055: BindingOperationInfo boi = exchange
056: .get(BindingOperationInfo.class);
057: if (null == boi) {
058: LOG.fine("No binding operation info.");
059: return;
060: }
061:
062: Endpoint e = exchange.get(Endpoint.class);
063: if (null == e) {
064: LOG.fine("No endpoint.");
065: return;
066: }
067: EndpointInfo ei = e.getEndpointInfo();
068:
069: PolicyEngine pe = bus.getExtension(PolicyEngine.class);
070: if (null == pe) {
071: return;
072: }
073:
074: AssertionInfoMap aim = message.get(AssertionInfoMap.class);
075: if (null == aim) {
076: return;
077: }
078:
079: if (MessageUtils.isPartialResponse(message)) {
080: LOG
081: .fine("Not verifying policies on inbound partial response.");
082: return;
083: }
084:
085: getTransportAssertions(message);
086:
087: EffectivePolicy effectivePolicy = null;
088: if (MessageUtils.isRequestor(message)) {
089: effectivePolicy = pe.getEffectiveClientResponsePolicy(ei,
090: boi);
091: } else {
092: effectivePolicy = pe.getEffectiveServerRequestPolicy(ei,
093: boi);
094: }
095:
096: aim.checkEffectivePolicy(effectivePolicy.getPolicy());
097: LOG.fine("Verified policies for inbound message.");
098: }
099:
100: }
|