
prng.seeds.UserPrefsStorage Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of SecurePRNG-core Show documentation
Show all versions of SecurePRNG-core Show documentation
The core random number generators
package prng.seeds;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.prefs.Preferences;
import prng.SecureRandomProvider;
/**
* Store seed data in the JVM's user preferences storage
*
* @author Simon Greatrix
*/
public class UserPrefsStorage extends PreferenceStorage {
/**
* New storage using user preferences
*
* @throws StorageException if the user preferences cannot be accessed
*/
public UserPrefsStorage() throws StorageException {
// no-op
}
@Override
protected Preferences getPreferences() throws StorageException {
try {
return AccessController.doPrivileged(
(PrivilegedAction) () -> Preferences.userNodeForPackage(
SeedStorage.class));
} catch (SecurityException e) {
SecureRandomProvider.LOG.warn(
"Lacking permission \"RuntimePermission preferences\" or access to user preferences - cannot access seed data in user preferences");
throw new StorageException(
"Privilege 'preferences' is required to use preferences",
e);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy