Friday, December 14, 2012

how to use Vi to view file in hex mode


":%!xxd" (minus quotes) will show file in hex mode
“:%!xxd -r“ will return to normal editing.

Monday, December 10, 2012

debug the java security policy

while run a java app with security manager,it just simply failed,we need more information.invoke app with following parameters:
java -Djava.security.manager -Djava.security.debug=access:failure
then we get following result:

About to get os.name property value
access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks)
access: access allowed (java.security.SecurityPermission getProperty.policy.expandProperties)
access: access allowed (java.security.SecurityPermission getProperty.policy.ignoreIdentityScope)
access: access allowed (java.security.SecurityPermission getProperty.policy.allowSystemProperty)
access: access allowed (java.util.PropertyPermission sun.security.policy.utf8 read)
access: access allowed (java.util.PropertyPermission sun.security.policy.numcaches read)
access: access allowed (java.util.PropertyPermission java.security.policy read)
access: access allowed (java.security.SecurityPermission getProperty.policy.url.1)
access: access allowed (java.util.PropertyPermission java.home read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\security\java.policy read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\security\java.policy read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\security\java.policy read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\security\java.policy read)
access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks)
access: access allowed (java.util.PropertyPermission java.ext.dirs read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\ext\* read)
access: access allowed (java.io.FilePermission C:\Windows\Sun\Java\lib\ext\* read)
access: access allowed (java.security.SecurityPermission getProperty.policy.url.2)
access: access allowed (java.util.PropertyPermission user.home read)
access: access allowed (java.io.FilePermission C:\Users\dwei\.java.policy read)
access: access allowed (java.io.FilePermission C:\Users\dwei\.java.policy read)
access: access allowed (java.io.FilePermission C:\Users\dwei\.java.policy read)
access: access allowed (java.security.SecurityPermission getProperty.policy.url.3)
access: access allowed (java.util.PropertyPermission java.home read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\security\examplepolicy read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\security\examplepolicy read)
access: access allowed (java.util.PropertyPermission java.protocol.handler.pkgs read)
access: access allowed (java.lang.reflect.ReflectPermission suppressAccessChecks)
access: access allowed (java.util.PropertyPermission java.util.logging.manager read)
access: access allowed (java.lang.RuntimePermission setContextClassLoader)
access: access allowed (java.lang.RuntimePermission shutdownHooks)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.PropertyPermission java.util.logging.config.class read)
access: access allowed (java.util.PropertyPermission java.util.logging.config.file read)
access: access allowed (java.util.PropertyPermission java.home read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\logging.properties read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\logging.properties read)
access: access allowed (java.io.FilePermission C:\Program Files (x86)\Java\jdk1.6.0_30\jre\lib\logging.properties read)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.logging.LoggingPermission control)
access: access allowed (java.util.PropertyPermission http.maxRedirects read)
access: access allowed (java.util.PropertyPermission java.version read)
access: access allowed (java.util.PropertyPermission http.agent read)
access: access allowed (java.util.PropertyPermission http.auth.digest.validateProxy read)
access: access allowed (java.util.PropertyPermission http.auth.digest.validateServer read)
access: access allowed (java.util.PropertyPermission sun.net.http.errorstream.enableBuffering read)
access: access allowed (java.util.PropertyPermission sun.net.http.errorstream.timeout read)
access: access allowed (java.util.PropertyPermission sun.net.http.errorstream.bufferSize read)
access: access allowed (java.util.PropertyPermission sun.net.http.allowRestrictedHeaders read)
access: access allowed (java.util.PropertyPermission http.auth.serializeRequests read)
access: access allowed (java.util.PropertyPermission http.auth.ntlm.domain read)
access: access allowed (java.net.NetPermission getCookieHandler)
access: access allowed (java.net.NetPermission getResponseCache)
access: access allowed (java.util.PropertyPermission user.dir read)
access: access allowed (java.io.FilePermission C:\test read)
access: access allowed (java.security.SecurityPermission getProperty.policy.url.4)
access: access allowed (java.util.PropertyPermission java.security.auth.policy read)
access: access allowed (java.security.SecurityPermission getProperty.auth.policy.url.1)
access: access allowed (java.io.FilePermission C:\test read)
  The name of your operating system is: Windows 7
About to get java.version property value
access: access allowed (java.util.PropertyPermission java.version read)
  The version of the JVM you are running is: 1.6.0_30
About to get user.home property value
access: access allowed (java.util.PropertyPermission user.home read)
  Your user home directory is: C:\Users\dwei
About to get java.home property value
access: access allowed (java.util.PropertyPermission java.home read)
  Your JRE installation directory is: C:\Program Files (x86)\Java\jdk1.6.0_30\jre

specify the policy file while run a applet

try out the java security guide,created the policy file,saved as a examplepolicy in local folder,the go to run the command line that invoke the applet view from sun.
appletviewer -J-Djava.security.policy=examplepolicy http://docs.oracle.com/javase/tutorial/security/tour1/examples/WriteFile.html

if we run the appletviewer from the folder that contains examplepolicy,the applet will be correctly run.oterwise the examplepolicy can not be find,so the applet will fail.

since the default jre\lib\security\java.security has a default item that load the policy from {user_home}\.java.policy,we can save newly created policy into that file,the invoke the applet anywhere,just make sure has the permission to write to that folder.

developers normally set up their JAVA_HOME to a JDK, so make sure change the java.security file in JDK\JRE\lib\security\java.security ,not the file under Program Files\Java\Jre\lib\security\java.security


locally fill a PDF form from FDF file

while open the insurance company online PDF documentation,it should automatically fill the claim form with logged in personal information.but it is downloading a file content call FDF, forms data format file which was used to fill the pdf.

open up the FDF file,found out that the file contains the url of the pdf file,I change that url to pdf file that downloaded previously from the same web site,vola, when double click th FDF file,the pdf was opened and automatically filled with information in FDF file.

take a look at the FDF file,we can also change the information in FDF to fill the PDF form.