<commit_before>/* Copyright 2004 Acegi Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.sf.acegisecurity.afterinvocation;

import net.sf.acegisecurity.AccessDeniedException;
import net.sf.acegisecurity.AfterInvocationManager;
import net.sf.acegisecurity.Authentication;
import net.sf.acegisecurity.ConfigAttribute;
import net.sf.acegisecurity.ConfigAttributeDefinition;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.InitializingBean;

import java.util.Iterator;
import java.util.List;


/**
 * Provider-based implementation of {@link AfterInvocationManager}.
 * 
 * <p>
 * Handles configuration of a bean context defined list of  {@link
 * AfterInvocationProvider}s.
 * </p>
 * 
 * <p>
 * Every <code>AfterInvocationProvider</code> will be polled when the {@link
 * #decide(Authentication, Object, ConfigAttributeDefinition, Object)} method
 * is called. The <code>Object</code> returned from each provider will be
 * presented to the successive provider for processing. This means each
 * provider <b>must</b> ensure they return the <code>Object</code>, even if
 * they are not interested in the "after invocation" decision (perhaps as the
 * secure object invocation did not include a configuration attribute a given
 * provider is configured to respond to).
 * </p>
 *
 * @author <NAME>
 * @version $Id$
 */
public class AfterInvocationProviderManager implements AfterInvocationManager,
    InitializingBean {
    //~ Static fields/initializers =============================================

    protected static final Log logger = LogFactory.getLog(AfterInvocationProviderManager.class);

    //~ Instance fields ========================================================

    private List providers;

    //~ Methods ================================================================

    public void setProviders(List newList) {
        checkIfValidList(newList);

        Iterator iter = newList.iterator();

        while (iter.hasNext()) {
            Object currentObject = null;

            try {
                currentObject = iter.next();

                AfterInvocationProvider attemptToCast = (AfterInvocationProvider) currentObject;
            } catch (ClassCastException cce) {
                throw new IllegalArgumentException("AfterInvocationProvider "
                    + currentObject.getClass().getName()
                    + " must implement AfterInvocationProvider");
            }
        }

        this.providers = newList;
    }

    public List getProviders() {
        return this.providers;
    }

    public void afterPropertiesSet() throws Exception {
        checkIfValidList(this.providers);
    }

    public Object decide(Authentication authentication, Object object,
        ConfigAttributeDefinition config, Object returnedObject)
        throws AccessDeniedException {
        Iterator iter = this.providers.iterator();

        Object result = returnedObject;

        while (iter.hasNext()) {
            AfterInvocationProvider provider = (AfterInvocationProvider) iter
                .next();
            result = provider.decide(authentication, object, config, result);
        }

        return result;
    }

    public boolean supports(ConfigAttribute attribute) {
        Iterator iter = this.providers.iterator();

        while (iter.hasNext()) {
            AfterInvocationProvider provider = (AfterInvocationProvider) iter
                .next();

            logger.fatal("Evaluating " + attribute + " against " + provider);

            if (provider.supports(attribute)) {
                return true;
            }
        }

        return false;
    }

    /**
     * Iterates through all <code>AfterInvocationProvider</code>s and ensures
     * each can support the presented class.
     * 
     * <p>
     * If one or more providers cannot support the presented class,
     * <code>false</code> is returned.
     * </p>
     *
     * @param clazz the secure object class being queries
     *
     * @return if the <code>AfterInvocationProviderManager</code> can support
     *         the secure object class, which requires every one of its
     *         <code>AfterInvocationProvider</code>s to support the secure
     *         object class
     */
    public boolean supports(Class clazz) {
        Iterator iter = this.providers.iterator();
<commit_msg>Remove noisy logging.<commit_after>/* Copyright 2004 Acegi Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package net.sf.acegisecurity.afterinvocation;

import net.sf.acegisecurity.AccessDeniedException;
import net.sf.acegisecurity.AfterInvocationManager;
import net.sf.acegisecurity.Authentication;
import net.sf.acegisecurity.ConfigAttribute;
import net.sf.acegisecurity.ConfigAttributeDefinition;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.InitializingBean;

import java.util.Iterator;
import java.util.List;


/**
 * Provider-based implementation of {@link AfterInvocationManager}.
 * 
 * <p>
 * Handles configuration of a bean context defined list of  {@link
 * AfterInvocationProvider}s.
 * </p>
 * 
 * <p>
 * Every <code>AfterInvocationProvider</code> will be polled when the {@link
 * #decide(Authentication, Object, ConfigAttributeDefinition, Object)} method
 * is called. The <code>Object</code> returned from each provider will be
 * presented to the successive provider for processing. This means each
 * provider <b>must</b> ensure they return the <code>Object</code>, even if
 * they are not interested in the "after invocation" decision (perhaps as the
 * secure object invocation did not include a configuration attribute a given
 * provider is configured to respond to).
 * </p>
 *
 * @author <NAME>
 * @version $Id$
 */
public class AfterInvocationProviderManager implements AfterInvocationManager,
    InitializingBean {
    //~ Static fields/initializers =============================================

    protected static final Log logger = LogFactory.getLog(AfterInvocationProviderManager.class);

    //~ Instance fields ========================================================

    private List providers;

    //~ Methods ================================================================

    public void setProviders(List newList) {
        checkIfValidList(newList);

        Iterator iter = newList.iterator();

        while (iter.hasNext()) {
            Object currentObject = null;

            try {
                currentObject = iter.next();

                AfterInvocationProvider attemptToCast = (AfterInvocationProvider) currentObject;
            } catch (ClassCastException cce) {
                throw new IllegalArgumentException("AfterInvocationProvider "
                    + currentObject.getClass().getName()
                    + " must implement AfterInvocationProvider");
            }
        }

        this.providers = newList;
    }

    public List getProviders() {
        return this.providers;
    }

    public void afterPropertiesSet() throws Exception {
        checkIfValidList(this.providers);
    }

    public Object decide(Authentication authentication, Object object,
        ConfigAttributeDefinition config, Object returnedObject)
        throws AccessDeniedException {
        Iterator iter = this.providers.iterator();

        Object result = returnedObject;

        while (iter.hasNext()) {
            AfterInvocationProvider provider = (AfterInvocationProvider) iter
                .next();
            result = provider.decide(authentication, object, config, result);
        }

        return result;
    }

    public boolean supports(ConfigAttribute attribute) {
        Iterator iter = this.providers.iterator();

        while (iter.hasNext()) {
            AfterInvocationProvider provider = (AfterInvocationProvider) iter
                .next();

            if (logger.isDebugEnabled()) {
                logger.debug("Evaluating " + attribute + " against " + provider);
            }

            if (provider.supports(attribute)) {
                return true;
            }
        }

        return false;
    }

    /**
     * Iterates through all <code>AfterInvocationProvider</code>s and ensures
     * each can support the presented class.
     * 
     * <p>
     * If one or more providers cannot support the presented class,
     * <code>false</code> is returned.
     * </p>
     *
     * @param clazz the secure object class being queries
     *
     * @return if the <code>AfterInvocationProviderManager</code> can support
     *         the secure object class, which requires every one of its
     *         <code>AfterInvocationProvider</code>s to support the secure
     *         object class
     */
    public boolean supports(Class clazz) {
        Iterator iter = this.providers.iterator();

{'fraction_non_alphanumeric': 0.11461777377016331, 'fraction_numerical': 0.001603045786995291, 'mean_word_length': 2.962683604605002, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 49, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '380759', 'n_tokens_mistral': 2504, 'n_tokens_neox': 2384, 'n_words': 778}