<commit_before>/*
 * Copyright 2005 The JA-SIG Collaborative. All rights reserved. See license
 * distributed with this file and available online at
 * http://www.uportal.org/license.html
 */
package org.jasig.cas.adaptors.generic;

import java.util.Collection;

import org.jasig.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler;
import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;

/**
 * Class to provide a list of users to automatically reject.
 * 
 * @author <NAME>
 * @version $Revision$ $Date$
 * @since 3.0
 */
public final class RejectUsersAuthenticationHandler extends
    AbstractUsernamePasswordAuthenticationHandler {

    /** The collection of users to reject. */
    private Collection users;

    public boolean authenticateUsernamePasswordInternal(
        final UsernamePasswordCredentials credentials) {

        return !this.users.contains(credentials.getUsername());
    }

    public void afterPropertiesSetInternal() throws Exception {
        if (this.users == null) {
            throw new IllegalStateException(
                "You must provide a list of users that are not allowed to use the system.");
        }
    }

    /**
     * @param users The users to set.
     */
    public void setUsers(final Collection users) {
        this.users = users;
    }
}<commit_msg>CAS-233<commit_after>/*
 * Copyright 2005 The JA-SIG Collaborative. All rights reserved. See license
 * distributed with this file and available online at
 * http://www.uportal.org/license.html
 */
package org.jasig.cas.adaptors.generic;

import java.util.Collection;

import org.jasig.cas.authentication.handler.support.AbstractUsernamePasswordAuthenticationHandler;
import org.jasig.cas.authentication.principal.UsernamePasswordCredentials;

/**
 * AuthenticationHandler which fails to authenticate a user purporting to be one
 * of the blocked usernames, and blindly authenticates all other users.
 * <p>
 * Note that the current implementation of AuthenticationManagerImpl tries all
 * AuthenitcationHandlers supporting a particular Credentials until it finds one
 * that succeeds. Since this implementation succeeds on all but those it is
 * configured to reject, adding it to the default AuthenticationManagerImpl has
 * the consequence that all users not explicitly rejected will be available for
 * authentication using any password (regardless of other handlers). Also note
 * that since this implementation does not throw any AuthenticationExceptions,
 * but only returns false for rejected users, rejecting a user using this
 * AuthenticationHandler will not prevent another AuthenticationHandler from
 * authenticating those credentials.
 * <p>
 * This is, under the current implementation of AuthenticationManagerImpl,
 * adding an instance of RejectUsersAuthenticationHandler to the
 * authenticationManager's List of AuthenticationHandlers will have no effect
 * for rejected users and will have the effect of allowing all other users to
 * authenticate regardless of presented password.
 * 
 * @author <NAME>
 * @version $Revision$ $Date$
 * @since 3.0
 */
public final class RejectUsersAuthenticationHandler extends
    AbstractUsernamePasswordAuthenticationHandler {

    /** The collection of users to reject. */
    private Collection users;

    public boolean authenticateUsernamePasswordInternal(
        final UsernamePasswordCredentials credentials) {

        return !this.users.contains(credentials.getUsername());
    }

    public void afterPropertiesSetInternal() throws Exception {
        if (this.users == null) {
            throw new IllegalStateException(
                "You must provide a list of users that are not allowed to use the system.");
        }
    }

    /**
     * Set the Collection of usernames which we will fail to authenticate.
     * 
     * @param users The Collection of usernames we should not authenticate.
     */
    public void setUsers(final Collection users) {
        this.users = users;
    }
}
{'fraction_non_alphanumeric': 0.06746328105551407, 'fraction_numerical': 0.0037341299477221808, 'mean_word_length': 3.7326266195524145, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '5112162', 'n_tokens_mistral': 985, 'n_tokens_neox': 941, 'n_words': 377}