<commit_before>/*
 * Copyright (C) 2005 <NAME>
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
 * Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the
 *
 * Free Software Foundation, Inc.
 * 59 Temple Place, Suite 330
 * Boston, MA 02111-1307
 * USA
 *
 * Or, you may view it online at
 * http://www.opensource.org/licenses/lgpl-license.php
 */

package org.jsecurity.ri.authc.module.dao;

import org.jsecurity.authc.AuthenticationException;
import org.jsecurity.authc.AuthenticationInfo;
import org.jsecurity.authc.AuthenticationToken;
import org.jsecurity.authc.ExpiredCredentialException;
import org.jsecurity.authc.IncorrectCredentialException;
import org.jsecurity.authc.LockedAccountException;
import org.jsecurity.authc.UnknownAccountException;
import org.jsecurity.authc.UsernamePasswordToken;
import org.jsecurity.authc.module.AuthenticationModule;
import org.jsecurity.ri.authc.credential.CredentialMatcher;
import org.jsecurity.ri.authc.credential.PlainTextCredentialMatcher;

import java.security.Principal;

/**
 * <p>Module that authenticates a user by delegating the lookup of
 * authentication and authorization information to an {@link AuthenticationDAO}.
 * Users of JSecurity can create their own DAO, or use one of the provided
 * DAO implementations.</p>
 *
 * <p>This module is intended to encapsulate the generic behavior of
 * authenticating a user from a username and password based on the
 * {@link org.jsecurity.authc.AuthenticationInfo} retrieved from the {@link AuthenticationDAO}.</p>
 *
 * @since 0.1
 * @author <NAME>
 */
public class DAOAuthenticationModule implements AuthenticationModule {

    /*--------------------------------------------
    |             C O N S T A N T S             |
    ============================================*/

    /*--------------------------------------------
    |    I N S T A N C E   V A R I A B L E S    |
    ============================================*/
    /**
     * The DAO used to retrieve user authentication and authorization
     * information from a data store.
     */
    private AuthenticationDAO authenticationDao;

    /**
     * Password matcher used to determine if the provided password matches
     * the password stored in the data store.
     */
    private CredentialMatcher credentialMatcher = new PlainTextCredentialMatcher();

    /*--------------------------------------------
    |         C O N S T R U C T O R S           |
    ============================================*/

    /*--------------------------------------------
    |  A C C E S S O R S / M O D I F I E R S    |
    ============================================*/
    public void setAuthenticationDao(AuthenticationDAO authenticationDao) {
        this.authenticationDao = authenticationDao;
    }

    public void setPasswordMatcher(CredentialMatcher credentialMatcher ) {
        this.credentialMatcher = credentialMatcher;
    }


    /*--------------------------------------------
    |               M E T H O D S               |<commit_msg>Fixed setter method on DAO module.<commit_after>/*
 * Copyright (C) 2005 <NAME>
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published
 * by the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
 * Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this library; if not, write to the
 *
 * Free Software Foundation, Inc.
 * 59 Temple Place, Suite 330
 * Boston, MA 02111-1307
 * USA
 *
 * Or, you may view it online at
 * http://www.opensource.org/licenses/lgpl-license.php
 */

package org.jsecurity.ri.authc.module.dao;

import org.jsecurity.authc.*;
import org.jsecurity.authc.module.AuthenticationModule;
import org.jsecurity.ri.authc.credential.CredentialMatcher;
import org.jsecurity.ri.authc.credential.PlainTextCredentialMatcher;

import java.security.Principal;

/**
 * <p>Module that authenticates a user by delegating the lookup of
 * authentication and authorization information to an {@link AuthenticationDAO}.
 * Users of JSecurity can create their own DAO, or use one of the provided
 * DAO implementations.</p>
 *
 * <p>This module is intended to encapsulate the generic behavior of
 * authenticating a user from a username and password based on the
 * {@link org.jsecurity.authc.AuthenticationInfo} retrieved from the {@link AuthenticationDAO}.</p>
 *
 * @since 0.1
 * @author <NAME>
 */
public class DAOAuthenticationModule implements AuthenticationModule {

    /*--------------------------------------------
    |             C O N S T A N T S             |
    ============================================*/

    /*--------------------------------------------
    |    I N S T A N C E   V A R I A B L E S    |
    ============================================*/
    /**
     * The DAO used to retrieve user authentication and authorization
     * information from a data store.
     */
    private AuthenticationDAO authenticationDao;

    /**
     * Password matcher used to determine if the provided password matches
     * the password stored in the data store.
     */
    private CredentialMatcher credentialMatcher = new PlainTextCredentialMatcher();

    /*--------------------------------------------
    |         C O N S T R U C T O R S           |
    ============================================*/

    /*--------------------------------------------
    |  A C C E S S O R S / M O D I F I E R S    |
    ============================================*/
    public void setAuthenticationDao(AuthenticationDAO authenticationDao) {
        this.authenticationDao = authenticationDao;
    }

    public void setCredentialMatcher(CredentialMatcher credentialMatcher ) {
        this.credentialMatcher = credentialMatcher;
    }


    /*--------------------------------------------
    |               M E T H O D S               |
{'fraction_non_alphanumeric': 0.18208734270910437, 'fraction_numerical': 0.006513693560325684, 'mean_word_length': 2.4753086419753085, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 21, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2501998', 'n_tokens_mistral': 1712, 'n_tokens_neox': 1631, 'n_words': 671}