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

Thu, 12 Oct 2017 19:44:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 19:44:07 +0800
changeset 760
e530533619ec
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

     1 /*
     2  * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     8  * particular file as subject to the "Classpath" exception as provided
     9  * by Oracle in the LICENSE file that accompanied this code.
    10  *
    11  * This code is distributed in the hope that it will be useful, but WITHOUT
    12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    14  * version 2 for more details (a copy is included in the LICENSE file that
    15  * accompanied this code).
    16  *
    17  * You should have received a copy of the GNU General Public License version
    18  * 2 along with this work; if not, write to the Free Software Foundation,
    19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    20  *
    21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    22  * or visit www.oracle.com if you need additional information or have any
    23  * questions.
    24  */
    26 package com.sun.xml.internal.ws.policy;
    28 import com.sun.xml.internal.ws.policy.privateutil.PolicyLogger;
    29 import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;
    30 import com.sun.xml.internal.ws.policy.spi.PolicyAssertionValidator;
    31 import static com.sun.xml.internal.ws.policy.privateutil.LocalizationMessages.WSP_0076_NO_SERVICE_PROVIDERS_FOUND;
    33 import java.util.Collection;
    34 import java.util.LinkedList;
    36 /**
    37  * Provides methods for assertion validation.
    38  *
    39  * @author Marek Potociar (marek.potociar at sun.com)
    40  * @author Fabian Ritzmann
    41  */
    42 public class AssertionValidationProcessor {
    43     private static final PolicyLogger LOGGER = PolicyLogger.getLogger(AssertionValidationProcessor.class);
    45     private final Collection<PolicyAssertionValidator> validators = new LinkedList<PolicyAssertionValidator>();
    47     /**
    48      * This constructor instantiates the object with a set of dynamically
    49      * discovered PolicyAssertionValidators.
    50      *
    51      * @throws PolicyException Thrown if the set of dynamically discovered
    52      *   PolicyAssertionValidators is empty.
    53      */
    54     private AssertionValidationProcessor() throws PolicyException {
    55         this(null);
    56     }
    58     /**
    59      * This constructor adds the given set of policy validators to the dynamically
    60      * discovered PolicyAssertionValidators.
    61      *
    62      * This constructor is intended to be used by the JAX-WS com.sun.xml.internal.ws.policy.api.ValidationProcessor.
    63      *
    64      * @param policyValidators A set of PolicyAssertionValidators. May be null
    65      * @throws PolicyException Thrown if the set of given PolicyAssertionValidators
    66      *   and dynamically discovered PolicyAssertionValidators is empty.
    67      */
    68     protected AssertionValidationProcessor(final Collection<PolicyAssertionValidator> policyValidators)
    69             throws PolicyException {
    70         for(PolicyAssertionValidator validator : PolicyUtils.ServiceProvider.load(PolicyAssertionValidator.class)) {
    71             validators.add(validator);
    72         }
    73         if (policyValidators != null) {
    74             for (PolicyAssertionValidator validator : policyValidators) {
    75                 validators.add(validator);
    76             }
    77         }
    78         if (validators.size() == 0) {
    79             throw LOGGER.logSevereException(new PolicyException(WSP_0076_NO_SERVICE_PROVIDERS_FOUND(PolicyAssertionValidator.class.getName())));
    80         }
    81     }
    83     /**
    84      * Factory method that returns singleton instance of the class.
    85      *
    86      * This method is only intended to be used by code that has no dependencies on
    87      * JAX-WS. Otherwise use com.sun.xml.internal.ws.api.policy.ValidationProcessor.
    88      *
    89      * @return singleton An instance of the class.
    90      * @throws PolicyException If instantiation failed.
    91      */
    92     public static AssertionValidationProcessor getInstance() throws PolicyException {
    93         return new AssertionValidationProcessor();
    94     }
    96     /**
    97      * Validates fitness of the {@code assertion} on the client side.
    98      *
    99      * return client side {@code assertion} fitness
   100      * @param assertion The assertion to be validated.
   101      * @return The fitness of the assertion on the client side.
   102      * @throws PolicyException If validation failed.
   103      */
   104     public PolicyAssertionValidator.Fitness validateClientSide(final PolicyAssertion assertion) throws PolicyException {
   105         PolicyAssertionValidator.Fitness assertionFitness = PolicyAssertionValidator.Fitness.UNKNOWN;
   106         for ( PolicyAssertionValidator validator : validators ) {
   107             assertionFitness = assertionFitness.combine(validator.validateClientSide(assertion));
   108             if (assertionFitness == PolicyAssertionValidator.Fitness.SUPPORTED) {
   109                 break;
   110             }
   111         }
   113         return assertionFitness;
   114     }
   116     /**
   117      * Validates fitness of the {@code assertion} on the server side.
   118      *
   119      * return server side {@code assertion} fitness
   120      * @param assertion The assertion to be validated.
   121      * @return The fitness of the assertion on the server side.
   122      * @throws PolicyException If validation failed.
   123      */
   124     public PolicyAssertionValidator.Fitness validateServerSide(final PolicyAssertion assertion) throws PolicyException {
   125         PolicyAssertionValidator.Fitness assertionFitness = PolicyAssertionValidator.Fitness.UNKNOWN;
   126         for (PolicyAssertionValidator validator : validators) {
   127             assertionFitness = assertionFitness.combine(validator.validateServerSide(assertion));
   128             if (assertionFitness == PolicyAssertionValidator.Fitness.SUPPORTED) {
   129                 break;
   130             }
   131         }
   133         return assertionFitness;
   134     }
   135 }

mercurial