<commit_before>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.emory.cci.aiw.cvrg.eureka.cas;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.AuthenticationException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;
/**
 *
 * @author <NAME>
 */
public class SQLStringGenerator {
    private String jndiName;


	public String getJndiName() {
                return jndiName;	
        }
        
        public void setJndiName(String jndiName){           
                this.jndiName  = jndiName;        
        }

        public String getUserVerficationSQLString(){
                String result="select a2.password from users a1 join local_users a2 on (a1.id=a2.id) where a1.username=? and a1.active=1";
                String driverName;
                Connection connection = null;
                Context initContext = null;
                
                try {
                        initContext = new InitialContext();
                        DataSource ds = (DataSource)initContext.lookup(jndiName);

                        connection = ds.getConnection();
                        driverName = connection.getMetaData().getDriverName();
                        if(driverName.toLowerCase().contains("postgresql")) {
                                result="select a2.password from users a1 join local_users a2 on (a1.id=a2.id) where a1.username=? and a1.active='true'";
                        }
                } catch (AuthenticationException ex) {
                        Logger.getLogger("Error in Authentication Exception: " + SQLStringGenerator.class.getName()).log(Level.SEVERE, null, ex);
                } catch ( NamingException ex) {
                        Logger.getLogger("Error in Naming Exception: " + SQLStringGenerator.class.getName()).log(Level.SEVERE, null, ex);
                } catch (SQLException ex) {
                        Logger.getLogger("Error in SQL Exeception: "+SQLStringGenerator.class.getName()).log(Level.SEVERE, null, ex);
                } finally {
                        if (initContext != null) {
                                try {
                                    initContext.close();
                                } catch (NamingException ex) {
                                    Logger.getLogger("Error in Naming Exception for closing initContext: " + SQLStringGenerator.class.getName()).log(Level.SEVERE, null, ex);
                                }
                        }  
                        if (connection != null) {
                                try {
                                    connection.close();
                                } catch (SQLException ex) {
                                    Logger.getLogger("Error in SQL Exeception for closing connection: "+SQLStringGenerator.class.getName()).log(Level.SEVERE, null, ex);
                                }
                        }
                }

                return result;          
        }
        
    
}
<commit_msg>Logger changes for the fix of hardcoded postgreSQL password<commit_after>/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.emory.cci.aiw.cvrg.eureka.cas;

import javax.naming.AuthenticationException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.sql.DataSource;

import java.sql.Connection;
import java.sql.SQLException;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
 *
 * @author <NAME>
 */
public class SQLStringGenerator {
	/**
	 * The class level logger.
	 */
	private static final Logger LOGGER = LoggerFactory.getLogger(
			SQLStringGenerator.class);
        
        private String jndiName;


	public String getJndiName() {
                return jndiName;	
        }
        
        public void setJndiName(String jndiName){           
                this.jndiName  = jndiName;        
        }

        public String getUserVerficationSQLString(){
                String result="select a2.password from users a1 join local_users a2 on (a1.id=a2.id) where a1.username=? and a1.active=1";
                String driverName;
                Connection connection = null;
                Context initContext = null;
                
                try {
                        initContext = new InitialContext();
                        DataSource ds = (DataSource)initContext.lookup(jndiName);

                        connection = ds.getConnection();
                        driverName = connection.getMetaData().getDriverName();
                        if(driverName.toLowerCase().contains("postgresql")) {
                                result="select a2.password from users a1 join local_users a2 on (a1.id=a2.id) where a1.username=? and a1.active='true'";
                        }
                } catch (AuthenticationException ex) {
                        LOGGER.error("Error authenticating user: "
                                        +"user credentials is invalid or naming/directory service failed.",
                                        ex.getMessage());
                } catch ( NamingException ex) {
                        LOGGER.error("NamingException in initializing context.",
                                        ex.getMessage());
                } catch (SQLException ex) {
                        LOGGER.error("SQLException in getting data source connetion or driver name.",
                                        ex.getMessage());
                } finally {
                        if (initContext != null) {
                                try {
                                    initContext.close();
                                } catch (NamingException ex) {
                                    LOGGER.error("NamingException in closing context.",
                                                    ex.getMessage());
                                }
                        }  
                        if (connection != null) {
                                try {
                                    connection.close();
                                } catch (SQLException ex) {
                                    LOGGER.error("SQLException in closing connection.",
                                                    ex.getMessage());
                                }
                        }
                }

                return result;          
        }
        
    
}

{'fraction_non_alphanumeric': 0.08212209302325581, 'fraction_numerical': 0.004651162790697674, 'mean_word_length': 1.316835016835017, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2771020', 'n_tokens_mistral': 1623, 'n_tokens_neox': 1545, 'n_words': 389}