[prev in list] [next in list] [prev in thread] [next in thread] 

List:       log4j-dev
Subject:    RE: Question -- Hiding Password in log4j.xml while using JDBCAppender
From:       "Mateen Moiz" <M.Moiz () eaa ! unsw ! edu ! au>
Date:       2012-06-21 6:42:55
Message-ID: B6EFFA5E171BF144ADC163A08B58E52A902878 () ETCMAIL02 ! etc ! unsw ! edu ! au
[Download RAW message or body]

Hi,

I am using Log4j with JDBCAppender using XML configuration, to make the
logs in the database. The problem is that the password in log4j.xml file
is in plain text. How can I hide this password?

I have used

MDC.put("pass", "abc");  

to place the password and it works fine with "sql" and proper password
is being inserted into the database

<param name="sql" value="INSERT INTO LOGS(Password, Message) VALUES
('%X{pass}', '%m')" />

But it's not working with the "password" param and giving "Access denied
for user ..."

<param name="password" value="%X{pass}" />

Please suggest what to do?

Code snap of log4j.xml is as follows.

<appender name="jdbc" class="org.apache.log4j.jdbc.JDBCAppender">  
    <param name="URL" value="jdbc:mysql://global/CL" />  
    <param name="user" value="Myapp" />  
    <param name="password" value="%X{pass}" />  
    <param name="driver" value="com.mysql.jdbc.Driver" />  
    <param name="sql" value="INSERT INTO LOGS(Password, MESSAGE) VALUES
('%X{pass}','%m')" />  
 </appender>  

 

Best Regards,

Mateen Moiz


[Attachment #3 (text/html)]

<html xmlns:v="urn:schemas-microsoft-com:vml" \
xmlns:o="urn:schemas-microsoft-com:office:office" \
xmlns:w="urn:schemas-microsoft-com:office:word" \
xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" \
xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type \
content="text/html; charset=us-ascii"><meta name=Generator content="Microsoft Word 12 \
(filtered medium)"><style><!-- /* Font Definitions */
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
	{font-family:Consolas;
	panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	margin-bottom:.0001pt;
	font-size:11.0pt;
	font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:blue;
	text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
	{mso-style-priority:99;
	color:purple;
	text-decoration:underline;}
p
	{mso-style-priority:99;
	mso-margin-top-alt:auto;
	margin-right:0cm;
	margin-bottom:12.0pt;
	margin-left:0cm;
	font-size:12.0pt;
	font-family:"Times New Roman","serif";}
code
	{mso-style-priority:99;
	font-family:Consolas;
	background:#EEEEEE;}
pre
	{mso-style-priority:99;
	mso-style-link:"HTML Preformatted Char";
	margin-top:0cm;
	margin-right:0cm;
	margin-bottom:7.5pt;
	margin-left:0cm;
	background:#EEEEEE;
	font-size:10.0pt;
	font-family:Consolas;}
span.HTMLPreformattedChar
	{mso-style-name:"HTML Preformatted Char";
	mso-style-priority:99;
	mso-style-link:"HTML Preformatted";
	font-family:Consolas;
	background:#EEEEEE;}
span.EmailStyle21
	{mso-style-type:personal;
	font-family:"Calibri","sans-serif";
	color:windowtext;}
span.EmailStyle22
	{mso-style-type:personal-reply;
	font-family:"Calibri","sans-serif";
	color:#1F497D;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]--></head><body lang=EN-AU link=blue vlink=purple><div \
class=WordSection1><p class=MsoNormal \
style='mso-margin-top-alt:auto;margin-bottom:12.0pt;margin-left:36.0pt;line-height:130%'><span \
style='font-size:10.0pt;line-height:130%;font-family:"Arial","sans-serif";color:black'>Hi,<o:p></o:p></span></p><p \
class=MsoNormal style='mso-margin-top-alt:auto;margin-bottom:12.0pt;margin-left:36.0pt;line-height:130%'><span \
style='font-size:10.0pt;line-height:130%;font-family:"Arial","sans-serif";color:black'>I \
am using Log4j with JDBCAppender using XML configuration, to make the logs in the \
database. The problem is that the password in log4j.xml file is in plain text. How \
can I hide this password?<o:p></o:p></span></p><p class=MsoNormal \
style='mso-margin-top-alt:auto;margin-bottom:12.0pt;margin-left:36.0pt;line-height:130%'><span \
style='font-size:10.0pt;line-height:130%;font-family:"Arial","sans-serif";color:black'>I \
have used<o:p></o:p></span></p><p class=MsoNormal \
style='mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:7.5pt;margin-left:36.0pt;line-height:130%;background:#EEEEEE'><span \
style='font-size:10.0pt;line-height:130%;font-family:Consolas;color:black'>MDC.put(&quot;pass&quot;, \
&#8220;abc&#8221;);&nbsp; <o:p></o:p></span></p><p class=MsoNormal \
style='mso-margin-top-alt:auto;margin-left:36.0pt;line-height:130%'><span \
style='font-size:10.0pt;line-height:130%;font-family:"Arial","sans-serif";color:black'>to \
place the password and it works fine with &#8220;sql&#8221; and proper password is \
being inserted into the database<o:p></o:p></span></p><pre \
style='margin-left:36.0pt;line-height:130%'><code><span style='color:black'>&lt;param \
name=&quot;sql&quot; value=&quot;INSERT INTO LOGS(Password, Message) VALUES \
('%X{pass}', '%m')&quot; /&gt;</span><o:p></o:p></code></pre><p \
style='margin-left:36.0pt;line-height:130%'><span \
style='font-size:10.0pt;line-height:130%;font-family:"Arial","sans-serif";color:black'>But \
it&#8217;s not working with the &#8220;password&#8221; param and giving &quot;Access \
denied for user ...&quot;</span><span \
style='font-family:"Arial","sans-serif"'><o:p></o:p></span></p><pre \
style='margin-left:36.0pt;line-height:130%'><code><span style='color:black'>&lt;param \
name=&quot;password&quot; value=&quot;%X{pass}&quot; \
/&gt;</span><o:p></o:p></code></pre><p \
style='margin-left:36.0pt;line-height:130%'><span \
style='font-size:10.0pt;line-height:130%;font-family:"Arial","sans-serif";color:black'>Please \
suggest what to do?</span><span \
style='font-family:"Arial","sans-serif"'><o:p></o:p></span></p><p \
style='margin-left:36.0pt;line-height:130%'><span \
style='font-size:10.0pt;line-height:130%;font-family:"Arial","sans-serif";color:black'>Code \
snap of log4j.xml is as follows.<o:p></o:p></span></p><pre \
style='margin-left:36.0pt;line-height:130%'><code><span \
style='color:black'>&lt;appender name=&quot;jdbc&quot; \
class=&quot;org.apache.log4j.jdbc.JDBCAppender&quot;&gt;&nbsp; \
</span><o:p></o:p></code></pre><pre \
style='margin-left:36.0pt;line-height:130%'><code><span \
style='color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;param name=&quot;URL&quot; \
value=&quot;jdbc:mysql://global/CL&quot; /&gt;&nbsp; \
<o:p></o:p></span></code></pre><pre \
style='margin-left:36.0pt;line-height:130%'><code><span \
style='color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;param name=&quot;user&quot; \
value=&quot;Myapp&quot; /&gt;&nbsp; <o:p></o:p></span></code></pre><pre \
style='margin-left:36.0pt;line-height:130%'><code><span \
style='color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;param name=&quot;password&quot; \
value=&quot;%X{pass}&quot; /&gt;&nbsp; <o:p></o:p></span></code></pre><pre \
style='margin-left:36.0pt;line-height:130%'><code><span \
style='color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;param name=&quot;driver&quot; \
value=&quot;com.mysql.jdbc.Driver&quot; /&gt;&nbsp; \
<o:p></o:p></span></code></pre><pre \
style='margin-left:36.0pt;line-height:130%'><code><span \
style='color:black'>&nbsp;&nbsp;&nbsp;&nbsp;&lt;param name=&quot;sql&quot; \
value=&quot;INSERT INTO LOGS(Password, MESSAGE) VALUES ('%X{pass}','%m')&quot; \
/&gt;&nbsp; <o:p></o:p></span></code></pre><pre \
style='margin-left:36.0pt;line-height:130%'><code><span \
style='color:black'>&nbsp;&lt;/appender&gt;&nbsp; <o:p></o:p></span></code></pre><p \
class=MsoNormal style='mso-margin-top-alt:auto;margin-left:36.0pt;line-height:130%'><span \
style='font-family:"Arial","sans-serif"'><o:p>&nbsp;</o:p></span></p><p \
class=MsoNormal style='margin-left:36.0pt'>Best Regards,<o:p></o:p></p><p \
class=MsoNormal style='margin-left:36.0pt'>Mateen \
Moiz<o:p></o:p></p></div></body></html>



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic