<commit_before>/*
 * 
 * 
 * Copyright (C) 2005 SIPfoundry Inc.
 * Licensed by SIPfoundry under the LGPL license.
 * 
 * Copyright (C) 2005 Pingtel Corp.
 * Licensed to SIPfoundry under a Contributor Agreement.
 * 
 * $
 */
package org.sipfoundry.sipxconfig.security;

import net.sf.acegisecurity.GrantedAuthority;
import net.sf.acegisecurity.GrantedAuthorityImpl;
import net.sf.acegisecurity.UserDetails;
import net.sf.acegisecurity.providers.dao.AuthenticationDao;
import net.sf.acegisecurity.providers.dao.UsernameNotFoundException;

import org.sipfoundry.sipxconfig.common.CoreContext;
import org.sipfoundry.sipxconfig.common.User;

public class AuthenticationDaoImpl implements AuthenticationDao {
    /** Whether dummy admin user is enabled. For use only by unit tests! */
    private static boolean s_dummyAdminUserEnabled;
    private static final String DUMMY_ADMIN_USER_NAME = "dummyAdminUserNameForTestingOnly";
    
    // granted authorities
    private static final GrantedAuthority AUTH_USER = new GrantedAuthorityImpl(User.ROLE_USER);
    private static final GrantedAuthority AUTH_ADMIN = new GrantedAuthorityImpl(User.ROLE_ADMIN);
    private static final GrantedAuthority[] AUTH_USER_ARRAY = new GrantedAuthority[] {AUTH_USER};
    private static final GrantedAuthority[] AUTH_USER_AND_ADMIN_ARRAY =
        new GrantedAuthority[] {AUTH_USER, AUTH_ADMIN};
    
    private CoreContext m_coreContext;

    public UserDetails loadUserByUsername(String userNameOrAlias) {
        if (isDummyAdminUserEnabled() && userNameOrAlias.equals(DUMMY_ADMIN_USER_NAME)) {
            return loadDummyAdminUser();
        }
        
        User user = m_coreContext.loadUserByUserNameOrAlias(userNameOrAlias);
        if (user == null) {<commit_msg>give AUTH_USER_AND_ADMIN_ARRAY package scope rather than private scope, for unit testing<commit_after>/*
 * 
 * 
 * Copyright (C) 2005 SIPfoundry Inc.
 * Licensed by SIPfoundry under the LGPL license.
 * 
 * Copyright (C) 2005 Pingtel Corp.
 * Licensed to SIPfoundry under a Contributor Agreement.
 * 
 * $
 */
package org.sipfoundry.sipxconfig.security;

import net.sf.acegisecurity.GrantedAuthority;
import net.sf.acegisecurity.GrantedAuthorityImpl;
import net.sf.acegisecurity.UserDetails;
import net.sf.acegisecurity.providers.dao.AuthenticationDao;
import net.sf.acegisecurity.providers.dao.UsernameNotFoundException;

import org.sipfoundry.sipxconfig.common.CoreContext;
import org.sipfoundry.sipxconfig.common.User;

public class AuthenticationDaoImpl implements AuthenticationDao {
    /** Whether dummy admin user is enabled. For use only by unit tests! */
    private static boolean s_dummyAdminUserEnabled;
    private static final String DUMMY_ADMIN_USER_NAME = "dummyAdminUserNameForTestingOnly";
    
    // granted authorities
    private static final GrantedAuthority AUTH_USER = new GrantedAuthorityImpl(User.ROLE_USER);
    private static final GrantedAuthority AUTH_ADMIN = new GrantedAuthorityImpl(User.ROLE_ADMIN);
    private static final GrantedAuthority[] AUTH_USER_ARRAY = new GrantedAuthority[] {AUTH_USER};
    static final GrantedAuthority[] AUTH_USER_AND_ADMIN_ARRAY =
        new GrantedAuthority[] {AUTH_USER, AUTH_ADMIN};
    
    private CoreContext m_coreContext;

    public UserDetails loadUserByUsername(String userNameOrAlias) {
        if (isDummyAdminUserEnabled() && userNameOrAlias.equals(DUMMY_ADMIN_USER_NAME)) {
            return loadDummyAdminUser();
        }
        
        User user = m_coreContext.loadUserByUserNameOrAlias(userNameOrAlias);
        if (user == null) {
{'fraction_non_alphanumeric': 0.07464355605255801, 'fraction_numerical': 0.004473022085546547, 'mean_word_length': 4.521604938271605, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3406975', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1079, 'n_words': 247}