<commit_before>/**
 * 
 */
package gov.nih.nci.security.acegi.csm.vote;

import gov.nih.nci.security.acegi.csm.authorization.AuthorizationSwitch;

import org.acegisecurity.Authentication;
import org.acegisecurity.ConfigAttribute;
import org.acegisecurity.ConfigAttributeDefinition;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.vote.AccessDecisionVoter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * If the configured AuthorizationSwitch is on, the vote method
 * returns ACCESS_ABSTAIN, otherwise it returns ACCESS_GRANTED.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */
public class AuthorizationSwitchVoter implements AccessDecisionVoter {
	
	private static final Log logger = LogFactory.getLog(AuthorizationSwitchVoter.class);
	
	private AuthorizationSwitch authorizationSwitch = new AuthorizationSwitch();
	
	private boolean requiresAuthentication = true;

	public boolean isRequiresAuthentication() {
		return requiresAuthentication;
	}

	public void setRequiresAuthentication(boolean requiresAuthentication) {
		this.requiresAuthentication = requiresAuthentication;
	}

	public AuthorizationSwitch getAuthorizationSwitch() {
		return authorizationSwitch;
	}

	public void setAuthorizationSwitch(AuthorizationSwitch authorizationSwitch) {
		this.authorizationSwitch = authorizationSwitch;
	}

	/* (non-Javadoc)
	 * @see org.acegisecurity.vote.AccessDecisionVoter#supports(org.acegisecurity.ConfigAttribute)
	 */
	public boolean supports(ConfigAttribute arg0) {
		return true;
	}

	/* (non-Javadoc)
	 * @see org.acegisecurity.vote.AccessDecisionVoter#supports(java.lang.Class)
	 */
	public boolean supports(Class arg0) {
		return true;
	}

	/* (non-Javadoc)
	 * @see org.acegisecurity.vote.AccessDecisionVoter#vote(org.acegisecurity.Authentication, java.lang.Object, org.acegisecurity.ConfigAttributeDefinition)
	 */
	public int vote(Authentication arg0, Object arg1,
			ConfigAttributeDefinition arg2) {
		int retVal = AccessDecisionVoter.ACCESS_ABSTAIN;
		if(!getAuthorizationSwitch().isOn()){
			
			logger.warn("###### AuthorizationSwitch is OFF #####");
			if(!isRequiresAuthentication() ||
					isRequiresAuthentication() && 
					SecurityContextHolder.getContext().getAuthentication() != null){
				retVal = AccessDecisionVoter.ACCESS_GRANTED;
			}
			
		}
		return retVal;
	}

}<commit_msg>Added some logging<commit_after>/**
 * 
 */
package gov.nih.nci.security.acegi.csm.vote;

import gov.nih.nci.security.acegi.csm.authorization.AuthorizationSwitch;

import org.acegisecurity.Authentication;
import org.acegisecurity.ConfigAttribute;
import org.acegisecurity.ConfigAttributeDefinition;
import org.acegisecurity.context.SecurityContextHolder;
import org.acegisecurity.vote.AccessDecisionVoter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * If the configured AuthorizationSwitch is on, the vote method
 * returns ACCESS_ABSTAIN, otherwise it returns ACCESS_GRANTED.
 * 
 * @author <a href="mailto:<EMAIL>"><NAME></a>
 *
 */
public class AuthorizationSwitchVoter implements AccessDecisionVoter {
	
	private static final Log logger = LogFactory.getLog(AuthorizationSwitchVoter.class);
	
	private AuthorizationSwitch authorizationSwitch = new AuthorizationSwitch();
	
	private boolean requiresAuthentication = true;

	public boolean isRequiresAuthentication() {
		return requiresAuthentication;
	}

	public void setRequiresAuthentication(boolean requiresAuthentication) {
		this.requiresAuthentication = requiresAuthentication;
	}

	public AuthorizationSwitch getAuthorizationSwitch() {
		return authorizationSwitch;
	}

	public void setAuthorizationSwitch(AuthorizationSwitch authorizationSwitch) {
		this.authorizationSwitch = authorizationSwitch;
	}

	/* (non-Javadoc)
	 * @see org.acegisecurity.vote.AccessDecisionVoter#supports(org.acegisecurity.ConfigAttribute)
	 */
	public boolean supports(ConfigAttribute arg0) {
		return true;
	}

	/* (non-Javadoc)
	 * @see org.acegisecurity.vote.AccessDecisionVoter#supports(java.lang.Class)
	 */
	public boolean supports(Class arg0) {
		return true;
	}

	/* (non-Javadoc)
	 * @see org.acegisecurity.vote.AccessDecisionVoter#vote(org.acegisecurity.Authentication, java.lang.Object, org.acegisecurity.ConfigAttributeDefinition)
	 */
	public int vote(Authentication arg0, Object arg1,
			ConfigAttributeDefinition arg2) {
		int retVal = AccessDecisionVoter.ACCESS_ABSTAIN;
		if(!getAuthorizationSwitch().isOn()){
			
			logger.warn("###### AuthorizationSwitch is OFF #####");
			if(!isRequiresAuthentication() ||
					isRequiresAuthentication() && 
					SecurityContextHolder.getContext().getAuthentication() != null){
				logger.warn("###### AuthorizationSwitch ACCESS_GRANTED #####");
				retVal = AccessDecisionVoter.ACCESS_GRANTED;
			}
			
		}
		return retVal;
	}

}
{'fraction_non_alphanumeric': 0.10380267214799589, 'fraction_numerical': 0.0020554984583761563, 'mean_word_length': 5.59349593495935, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '2503458', 'n_tokens_mistral': 1556, 'n_tokens_neox': 1432, 'n_words': 257}