Saturday 15 July 2017

Create policy file in JAVA

Java provides 'policytool' command, to manage (create, edit) policy file. ‘policytool’ command is in the ‘bin’ directory of java installation.

Open command prompt (or) shell and run ‘policytool’ command. It opens below window.

Click on the button ‘Add Policy Entry’. It opens ‘Policy Entry’ window.

By using policy entry, we can specify the permissions for the code from a given code base (for ex: some url like https://github.com) and the organization who signed this code etc.,

What is codebase?
It specifies the location from where the source code exists. If you do not specify any value for this, then it do not add any permission check on from where this code is coming.

What is SignedBy?
It specifies the alias of a certificate that stored in the keystore. The source code must be signed by the private key of the source code provider. By using the public key (of this alias) presented in the keystore, we check the authenticity of the signer.

I just given the codebase name as ‘https://github.com’ and left the SignedBy as empty.

Click on the button ‘Done’. You can see, new policy entry is added.

Save the policy file
File -> Save As…

Give the policy file name as ‘demoPolicy’ and save.

Once the policy file is saved successfully, you can able to see below successful window.

You can open the demoPolicy file in any text editor. ‘demoPolicy’ file has below content

demoPolicy
/* AUTOMATICALLY GENERATED ON Thu Jul 13 12:29:46 IST 2017*/
/* DO NOT EDIT */

grant codeBase "https://github.com" {
};

In my next post, I am going to explain how to update the policy file to grant the permissions.



Previous                                                 Next                                                 Home

No comments:

Post a Comment