Hiding or Encrypting Password in log4j.properties file SMTP Appender - java

I am using custom gmail smtp appendar for sending error logs from my gmail account.
Following the instructions: http://www.tgerm.com/2010/05/log4j-smtpappender-gmail-custom.html - Everything works great.
Except one thing:
In my log4j.properties: I don't want to type my password "log4j.appender.EMAIL.SMTPPassword=somepass" so that I can share this project with my team mates. Does anyone have a suggestion ?
Below is log4j.properties part:
log4j.appender.EMAIL=com.tgerm.log4j.appender.GmailSMTPAppender
log4j.appender.EMAIL.SMTPHost=smtp.gmail.com
log4j.appender.EMAIL.SMTPDebug=true
log4j.appender.EMAIL.From=from#gmail.com
log4j.appender.EMAIL.To=to#tgerm.com
log4j.appender.EMAIL.SMTPUsername=smtpuser#gmail.com
log4j.appender.EMAIL.SMTPPassword=somepass //this is the problematic part
log4j.appender.EMAIL.Subject=Email Notification from Gmail SMTP Appender
log4j.appender.EMAIL.cc=cc#gmail.com
log4j.appender.EMAIL.layout=org.apache.log4j.PatternLayout
log4j.appender.EMAIL.layout.ConversionPattern=%p %t %c - %m%n
log4j.appender.EMAIL.BufferSize=1

For starters: don't use your personal email address - create a new account to be shared with your team members.
If you still want to encrypt, put the encrypted information in a separate properties or xml file, write code to encrypt and decrypt it, and configure that portion of log4j programatically.
(And, as gdt says below, remember, if the application can decrypt the password, others can too. There is no 100% safe solution. Protecting the file access permissions is often more effective than encrypting.)

Create a service email account (not personal) which can be shared.
To hide password, specify it in properies file, but after first run, read it, encrypt and write back to the properties file.

Related

Read a .txt file from an anonymous FTP page?

My goal is to to convert a .txt file on an FTP page to a simple String for easy manipulation.
The specific .txt file is here: ftp://ftp.nasdaqtrader.com/SymbolDirectory/nasdaqlisted.txt. It is an anonymous FTP page, so when I use my computer's browser, there's no need for a username or password.
I've tried incorporating different codes and tips from the following sources:
Reading Text File From Server on Android
http://examples.javacodegeeks.com/core-java/apache/commons/net-commons/download-file-from-ftp-server/
How to read a text file via FTP?
Reading txt file from an ftp server and returning it from AsyncTask
unable to read file from ftp in android?
Howto do a simple ftp get file on Android
http://www.javaworld.com/article/2073325/java-app-dev/java-ftp-client-libraries-reviewed.html
http://developer.android.com/reference/java/net/URLConnection.html
None of what I've tried above helped. I'm not quite sure what I'm doing wrong.
To be clear, all I want to do is to get the plain text from the posted .txt file. I have no interest in downloading said file onto my device's memory.
If you could provide me with a step-by-step explanation on how to do this, I'd be very thankful.
Ok. I've got it. For those who are in the same boat, the step-by-step answer is below:
A lot of problems other users were encountering could be solved by having permissions for internet turned on in the manifest, but mine was a little more complicated. Turns out, the main trick is to not include ftp:// in the address in Java.* Also, when you are entering an FTP site, make sure you enter via the root page, so my original page of ftp://ftp.nasdaqtrader.com/SymbolDirectory/nasdaqlisted.txt becomes: ftp.nasdaqtrader.com.
Make sure to download and include the right Apache Commons library in your project (here: http://commons.apache.org/proper/commons-net/download_net.cgi).
Connect to the root page:
FTPClient ftpClient = new FTPClient();
ftpClient.connect("ftp.nasdaqtrader.com");
Login anonymously, in this case, both username and password are "anonymous". This might be the case with many FTP pages, but I can't be sure:
ftpClient.login("anonymous", "anonymous");
Then, go to the correct directory (be careful about including/excluding the slashes):
ftpClient.changeWorkingDirectory("/SymbolDirectory");
Finally! You can now get the InputStream from the posted text file:
InputStream is = new BufferedInputStream(ftpClient.retrieveFileStream("nasdaqlisted.txt"));
Then, convert the InputStream into String and manipulate as needed. There are many ways to do this. One of which can be found here: How can I convert InputStream data to String in Android SOAP Webservices
*Source: Android FTP connection Failed
If you get "425 Unable to build data connection: Connection timed out" error, then after connecting to ftp server, I would recommend you to set the local mode to passive mode by the following statement.
ftpClient.enterLocalPassiveMode();

glassfish smtp from name

We use a GlassFish server (JavaEE 7) with JavaMail.
Afaik, the official E-Mail RFC states that mail addresses may look something like this:
Tom Tester <tom.tester#test.com>
which would include a nicer representation than using only the email address. The Glassfish server is able to use this when configuring it on the admin console, clients like the GMail web client then display "Tom Tester" as sender. However, I'd like to specify the mail resource in the glassfish-resources.xml within our project, the configuration file doesn't allow < or >, because it's xml. I tried
<mail-resource
from="Tom Tester <tom.tester#test.com>"
...
and
<mail-resource
from="Tom Tester tom.tester#test.com"
...
, but these configurations won't work. Both approaches end up in sending only "tom.tester#test.com" as sender. I also didn't find any specification details from the GlassFish docs. Does somebody know if the desired behaviour is possible?
In case you want to explicitly set the personal name for the sender, you need to do it while creating the email message.
Let's say you have the session mailSession from the GlassFish Resource and you are creating a message mailMessage
Now you can set the from attribute of the message:
mailMessage.setFrom(new InternetAddress(mailSession.getProperty("mail.from"), "Tom Tester"));
Read more here.

Apple Autoingestion class: username and password "deprecated", properties file?

I want to collect daily sales summaries from iTunes Connect and store them in my database. A step on this path is to use Apple's iTunes Connect Autoingestion java class to download the report data.
When I run the tool from my Windows XP command line, I get a curious error message.
C:\iTunes sales reports>java -cp Autoingestion Autoingestion myuser
"myP#ssw0rd" 80000000 Sales Daily Summary 20130707
The username and password parameters have been deprecated. Please use the
properties file for user credentials.
S_D_80000000_20130707.txt.gz
File Downloaded Successfully
I'm curious about how to resolve the error message, ''The username and password parameters have been deprecated. Please use the properties file for user credentials.''
I don't see anything about this message in Apple's documentation, ''iTunes Connect
Sales and Trends Guide: App Store v8''.
In the directory next to Autoingestion.class is a file autoingestion.properties. This file contains the two lines:
userID = <UserID>
password = <Password>
An obvious guess is that the Autoingestion class wants me to put my userID and password in this file. There's no indication of the values need to be quoted or not. When I put my user ID and password in the file (unquoted), and then leave the userID and password out of the commend line, I get the following error message:
C:\iTunes sales reports\Autoingestion>java -cp . Autoingestion
80000000 Daily Summary 20130707
The username and password parameters have been deprecated. Please use the
properties file for user credentials.
Please enter all the required parameters. For help, please download the
latest User Guide from the Sales and Trends module in iTunes Connect.
So, I don't know how to supply the user credentials in a way that resolves this error message. Does anybody know how? Is there maybe a commonly-known convention for properties files which java novices like me haven't heard of?
jemeshu is correct, they updated the Autoingest tool and the document reflects the old usage. It still works to download, but gives you the deprecation message. The new format is:
java Autoingestion autoingestion.properties 80000000 Sales Daily Summary 20130707
The properties file name needs to be supplied in place of the old username and password. I believe it also has to end with .properties.
Further info: the values work unquoted in the properties file.
The instructions documented in "iTunes Connect Sales and Trends Guide" is for an old version of Autoingestion tool. Apple has yet to update the document.
Please log an error to bugreport.apple.com and Apple developer forum. The more people reporting it, the sooner the staff at Apple in charge of this documentation will update it.

Pass password for proxy server in Maven2 through command line or prompt?

As I'm uncomfortable storing my username and password (must auth to the proxy server with my normal login credentials) in plaintext in .m2/settings.xml, I'm trying to see if there is a better way to pass my credentials.
What I've tried
Relying on system proxy settings - didn't work (obviously)
Leaving out password - downloaded 5k - 740b jars. Right...
Adding -Dmaven.proxy.password=mypass to command line - Same as above
is there anyway I can pass this information over command line? Or even better, is there a way to have it prompt me for the password?
FYI, it works as expected when I do have the password in the configuration file
I have never used this particular feature of Maven, but they do have some support for encrypting passwords in your settings.xml. You can read more here: http://maven.apache.org/guides/mini/guide-encryption.html
That doesn't exactly answer your question, but it might solve your root problem.

email log file, generated by Java WebLogic Application Server

does this requirement conform to the J2EE Standards?
is there a easy way to implement this, log file gets generated by Log4J and in the end I will access the file system and email the whole file(s). can I access the file system?
Log4j has an email appender...
See: http://www.onjava.com/pub/a/onjava/2004/09/29/smtp-logging.html?page=2
(Also look on page 1)
with log4j, you can add an email appender to your configuration. You can declare the appender in your log4j.proeprties so:
log4j.appender.email=org.apache.log4j.net.SMTPAppender
log4j.appender.email.To= #recepient's email address
log4j.appender.email.From= #the sender's email address
log4j.appender.email.SMTPHost= #location of your smtp server
log4j.appender.email.Threshold=FATAL #the lowest log level on which the email is generated
log4j.appender.email.BufferSize=512
log4j.appender.email.Subject= #subject line of the email sent out
log4j.appender.email.layout=org.apache.log4j.PatternLayout
log4j.appender.email.layout.ConversionPattern=-[%d] %-4L %-5p %c %x - %m%n #message format
Something to remember: this appender will send an email on every log message that meets the threshold requirement so having a high threshold is recommended so your inbox doesn't get flooded with messages that are non critical.

Categories

Resources