Home » Core Java » security (page 4)

security

Check if a permission implies another permission example

In this example we shall show you how to check if a permission to a file implies another permission. To check the permissions to a specific file one should perform the following steps: Create a new FilePermission with a given String as path and another given String as actions. Create a second FilePermission with a another String as path and ...

Read More »

Control access to an Object example

With this example we are going to demonstrate how to control access to an Object in Java. In short, to control access to an Object you should: Create a Guard, which is an object that is used to protect access to another object, with the String name of the system property, and a String of comma-separated actions granted on the ...

Read More »

Check read/write permission for a directory example

This is an example of how to check read/write permission for a directory. Checking read/write permission for a directory implies that you should: Create a FilePermission for the pathname of the directory, and a comma-separated list of the actions granted on the directory. Invoke the checkPermission(Permission perm) API method of the AccessController, in order to check whether the access request ...

Read More »

Generate a secure random number example

In this example we shall show you how to generate a secure random number. To generate secure random numbers one should perform the following steps: Create a SecureRandom for the SHA1PRNG algorithm, which is a secure number generator, using the getInstance(String algorithm) API method. Create a new byte array with a specific length (128 in the example). Invoke the nextBytes(byte[] ...

Read More »