src/share/jaxws_classes/com/sun/xml/internal/ws/policy/AssertionValidationProcessor.java

changeset 0
373ffda63c9a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/policy/AssertionValidationProcessor.java	Wed Apr 27 01:27:09 2016 +0800
     1.3 @@ -0,0 +1,135 @@
     1.4 +/*
     1.5 + * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.xml.internal.ws.policy;
    1.30 +
    1.31 +import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
    1.32 +import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
    1.33 +import com.sun.xml.internal.ws.policy.spi.PolicyAssertionValidator;
    1.34 +import static com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages.WSP_0076_NO_SERVICE_PROVIDERS_FOUND;
    1.35 +
    1.36 +import java.util.Collection;
    1.37 +import java.util.LinkedList;
    1.38 +
    1.39 +/**
    1.40 + * Provides methods for assertion validation.
    1.41 + *
    1.42 + * @author Marek Potociar (marek.potociar at sun.com)
    1.43 + * @author Fabian Ritzmann
    1.44 + */
    1.45 +public class AssertionValidationProcessor {
    1.46 +    private static final PolicyLogger LOGGER = PolicyLogger.getLogger(AssertionValidationProcessor.class);
    1.47 +
    1.48 +    private final Collection<PolicyAssertionValidator> validators = new LinkedList<PolicyAssertionValidator>();
    1.49 +
    1.50 +    /**
    1.51 +     * This constructor instantiates the object with a set of dynamically
    1.52 +     * discovered PolicyAssertionValidators.
    1.53 +     *
    1.54 +     * @throws PolicyException Thrown if the set of dynamically discovered
    1.55 +     *   PolicyAssertionValidators is empty.
    1.56 +     */
    1.57 +    private AssertionValidationProcessor() throws PolicyException {
    1.58 +        this(null);
    1.59 +    }
    1.60 +
    1.61 +    /**
    1.62 +     * This constructor adds the given set of policy validators to the dynamically
    1.63 +     * discovered PolicyAssertionValidators.
    1.64 +     *
    1.65 +     * This constructor is intended to be used by the JAX-WS com.sun.xml.internal.ws.policy.api.ValidationProcessor.
    1.66 +     *
    1.67 +     * @param policyValidators A set of PolicyAssertionValidators. May be null
    1.68 +     * @throws PolicyException Thrown if the set of given PolicyAssertionValidators
    1.69 +     *   and dynamically discovered PolicyAssertionValidators is empty.
    1.70 +     */
    1.71 +    protected AssertionValidationProcessor(final Collection<PolicyAssertionValidator> policyValidators)
    1.72 +            throws PolicyException {
    1.73 +        for(PolicyAssertionValidator validator : PolicyUtils.ServiceProvider.load(PolicyAssertionValidator.class)) {
    1.74 +            validators.add(validator);
    1.75 +        }
    1.76 +        if (policyValidators != null) {
    1.77 +            for (PolicyAssertionValidator validator : policyValidators) {
    1.78 +                validators.add(validator);
    1.79 +            }
    1.80 +        }
    1.81 +        if (validators.size() == 0) {
    1.82 +            throw LOGGER.logSevereException(new PolicyException(WSP_0076_NO_SERVICE_PROVIDERS_FOUND(PolicyAssertionValidator.class.getName())));
    1.83 +        }
    1.84 +    }
    1.85 +
    1.86 +    /**
    1.87 +     * Factory method that returns singleton instance of the class.
    1.88 +     *
    1.89 +     * This method is only intended to be used by code that has no dependencies on
    1.90 +     * JAX-WS. Otherwise use com.sun.xml.internal.ws.api.policy.ValidationProcessor.
    1.91 +     *
    1.92 +     * @return singleton An instance of the class.
    1.93 +     * @throws PolicyException If instantiation failed.
    1.94 +     */
    1.95 +    public static AssertionValidationProcessor getInstance() throws PolicyException {
    1.96 +        return new AssertionValidationProcessor();
    1.97 +    }
    1.98 +
    1.99 +    /**
   1.100 +     * Validates fitness of the {@code assertion} on the client side.
   1.101 +     *
   1.102 +     * return client side {@code assertion} fitness
   1.103 +     * @param assertion The assertion to be validated.
   1.104 +     * @return The fitness of the assertion on the client side.
   1.105 +     * @throws PolicyException If validation failed.
   1.106 +     */
   1.107 +    public PolicyAssertionValidator.Fitness validateClientSide(final PolicyAssertion assertion) throws PolicyException {
   1.108 +        PolicyAssertionValidator.Fitness assertionFitness = PolicyAssertionValidator.Fitness.UNKNOWN;
   1.109 +        for ( PolicyAssertionValidator validator : validators ) {
   1.110 +            assertionFitness = assertionFitness.combine(validator.validateClientSide(assertion));
   1.111 +            if (assertionFitness == PolicyAssertionValidator.Fitness.SUPPORTED) {
   1.112 +                break;
   1.113 +            }
   1.114 +        }
   1.115 +
   1.116 +        return assertionFitness;
   1.117 +    }
   1.118 +
   1.119 +    /**
   1.120 +     * Validates fitness of the {@code assertion} on the server side.
   1.121 +     *
   1.122 +     * return server side {@code assertion} fitness
   1.123 +     * @param assertion The assertion to be validated.
   1.124 +     * @return The fitness of the assertion on the server side.
   1.125 +     * @throws PolicyException If validation failed.
   1.126 +     */
   1.127 +    public PolicyAssertionValidator.Fitness validateServerSide(final PolicyAssertion assertion) throws PolicyException {
   1.128 +        PolicyAssertionValidator.Fitness assertionFitness = PolicyAssertionValidator.Fitness.UNKNOWN;
   1.129 +        for (PolicyAssertionValidator validator : validators) {
   1.130 +            assertionFitness = assertionFitness.combine(validator.validateServerSide(assertion));
   1.131 +            if (assertionFitness == PolicyAssertionValidator.Fitness.SUPPORTED) {
   1.132 +                break;
   1.133 +            }
   1.134 +        }
   1.135 +
   1.136 +        return assertionFitness;
   1.137 +    }
   1.138 +}

mercurial