use of java.security.PrivilegedAction in project felix by apache.
the class MX4JMBeanServer method createMBeanRepository.
/**
* Creates a new repository for MBeans.
* The system property {@link mx4j.MX4JSystemKeys#MX4J_MBEANSERVER_REPOSITORY} is tested
* for a full qualified name of a class implementing the {@link MBeanRepository} interface.
* In case the system property is not defined or the class is not loadable or instantiable, a default
* implementation is returned.
*/
private MBeanRepository createMBeanRepository() {
Logger logger = getLogger();
if (logger.isEnabledFor(Logger.TRACE))
logger.trace("Checking for system property " + MX4JSystemKeys.MX4J_MBEANSERVER_REPOSITORY);
String value = (String) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty(MX4JSystemKeys.MX4J_MBEANSERVER_REPOSITORY);
}
});
if (value != null) {
if (logger.isEnabledFor(Logger.DEBUG))
logger.debug("Property found for custom MBeanServer registry; class is: " + value);
try {
MBeanRepository registry = (MBeanRepository) Thread.currentThread().getContextClassLoader().loadClass(value).newInstance();
if (logger.isEnabledFor(Logger.TRACE)) {
logger.trace("Custom MBeanServer registry created successfully");
}
return registry;
} catch (Exception x) {
if (logger.isEnabledFor(Logger.TRACE)) {
logger.trace("Custom MBeanServer registry could not be created", x);
}
}
}
return new DefaultMBeanRepository();
}
use of java.security.PrivilegedAction in project felix by apache.
the class SecurityMBeanServerInterceptor method checkTrustRegistration.
private void checkTrustRegistration(final Class cls) {
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
ProtectionDomain domain = (ProtectionDomain) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return cls.getProtectionDomain();
}
});
MBeanTrustPermission permission = new MBeanTrustPermission("register");
if (!domain.implies(permission)) {
throw new AccessControlException("Access denied " + permission + ": MBean class " + cls.getName() + " is not trusted for registration");
}
}
}
use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.
the class PKCS12KeyStore method encryptPrivateKey.
/*
* Encrypt private key using Password-based encryption (PBE)
* as defined in PKCS#5.
*
* NOTE: By default, pbeWithSHAAnd3-KeyTripleDES-CBC algorithmID is
* used to derive the key and IV.
*
* @return encrypted private key encoded as EncryptedPrivateKeyInfo
*/
private byte[] encryptPrivateKey(byte[] data, KeyStore.PasswordProtection passwordProtection) throws IOException, NoSuchAlgorithmException, UnrecoverableKeyException {
byte[] key = null;
try {
String algorithm;
AlgorithmParameters algParams;
AlgorithmId algid;
// Initialize PBE algorithm and parameters
algorithm = passwordProtection.getProtectionAlgorithm();
if (algorithm != null) {
AlgorithmParameterSpec algParamSpec = passwordProtection.getProtectionParameters();
if (algParamSpec != null) {
algParams = AlgorithmParameters.getInstance(algorithm);
algParams.init(algParamSpec);
} else {
algParams = getAlgorithmParameters(algorithm);
}
} else {
// Check default key protection algorithm for PKCS12 keystores
algorithm = AccessController.doPrivileged(new PrivilegedAction<String>() {
public String run() {
String prop = Security.getProperty(KEY_PROTECTION_ALGORITHM[0]);
if (prop == null) {
prop = Security.getProperty(KEY_PROTECTION_ALGORITHM[1]);
}
return prop;
}
});
if (algorithm == null || algorithm.isEmpty()) {
algorithm = "PBEWithSHA1AndDESede";
}
algParams = getAlgorithmParameters(algorithm);
}
ObjectIdentifier pbeOID = mapPBEAlgorithmToOID(algorithm);
if (pbeOID == null) {
throw new IOException("PBE algorithm '" + algorithm + " 'is not supported for key entry protection");
}
// Use JCE
SecretKey skey = getPBEKey(passwordProtection.getPassword());
Cipher cipher = Cipher.getInstance(algorithm);
cipher.init(Cipher.ENCRYPT_MODE, skey, algParams);
byte[] encryptedKey = cipher.doFinal(data);
algid = new AlgorithmId(pbeOID, cipher.getParameters());
if (debug != null) {
debug.println(" (Cipher algorithm: " + cipher.getAlgorithm() + ")");
}
// wrap encrypted private key in EncryptedPrivateKeyInfo
// as defined in PKCS#8
EncryptedPrivateKeyInfo encrInfo = new EncryptedPrivateKeyInfo(algid, encryptedKey);
key = encrInfo.getEncoded();
} catch (Exception e) {
UnrecoverableKeyException uke = new UnrecoverableKeyException("Encrypt Private Key failed: " + e.getMessage());
uke.initCause(e);
throw uke;
}
return key;
}
use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.
the class JRELocaleProviderAdapter method isNonENLangSupported.
/*
* Returns true if the non EN resources jar file exists in jre
* extension directory. @returns true if the jar file is there. Otherwise,
* returns false.
*/
private static boolean isNonENLangSupported() {
if (isNonENSupported == null) {
synchronized (JRELocaleProviderAdapter.class) {
if (isNonENSupported == null) {
final String sep = File.separator;
String localeDataJar = java.security.AccessController.doPrivileged(new sun.security.action.GetPropertyAction("java.home")) + sep + "lib" + sep + "ext" + sep + LOCALE_DATA_JAR_NAME;
/*
* Peek at the installed extension directory to see if
* localedata.jar is installed or not.
*/
final File f = new File(localeDataJar);
isNonENSupported = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
@Override
public Boolean run() {
return f.exists();
}
});
}
}
}
return isNonENSupported;
}
use of java.security.PrivilegedAction in project jdk8u_jdk by JetBrains.
the class FileDialogFilter method init.
private void init(FileDialog target) {
//new Dialog(target, target.getTitle(), false);
fileDialog = target;
this.title = target.getTitle();
this.mode = target.getMode();
this.target = target;
this.filter = target.getFilenameFilter();
savedFile = target.getFile();
savedDir = target.getDirectory();
// Shouldn't save 'user.dir' to 'savedDir'
// since getDirectory() will be incorrect after handleCancel
userDir = (String) AccessController.doPrivileged(new PrivilegedAction() {
public Object run() {
return System.getProperty("user.dir");
}
});
installStrings();
gbl = new GridBagLayout();
gblButtons = new GridBagLayout();
gbc = new GridBagConstraints();
fileDialog.setLayout(gbl);
// create components
buttons = new Panel();
buttons.setLayout(gblButtons);
actionButtonText = (target.getMode() == FileDialog.SAVE) ? saveButtonText : openButtonText;
openButton = new Button(actionButtonText);
filterButton = new Button(filterLabelText);
cancelButton = new Button(cancelButtonText);
directoryList = new List();
fileList = new List();
filterField = new TextField();
selectionField = new TextField();
boolean isMultipleMode = AWTAccessor.getFileDialogAccessor().isMultipleMode(target);
fileList.setMultipleMode(isMultipleMode);
// the insets used by the components in the fileDialog
Insets noInset = new Insets(0, 0, 0, 0);
Insets textFieldInset = new Insets(0, 8, 0, 8);
Insets leftListInset = new Insets(0, 8, 0, 4);
Insets rightListInset = new Insets(0, 4, 0, 8);
Insets separatorInset = new Insets(8, 0, 0, 0);
Insets labelInset = new Insets(0, 8, 0, 0);
Insets buttonsInset = new Insets(10, 8, 10, 8);
// add components to GridBagLayout "gbl"
Font f = new Font(Font.DIALOG, Font.PLAIN, 12);
Label label = new Label(pathLabelText);
label.setFont(f);
addComponent(label, gbl, gbc, 0, 0, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.NONE, labelInset);
// Fixed 6260650: FileDialog.getDirectory() does not return null when file dialog is cancelled
// After showing we should display 'user.dir' as current directory
// if user didn't set directory programatically
pathField = new TextField(savedDir != null ? savedDir : userDir);
pathChoice = new Choice() {
public Dimension getPreferredSize() {
return new Dimension(PATH_CHOICE_WIDTH, pathField.getPreferredSize().height);
}
};
pathPanel = new Panel();
pathPanel.setLayout(new BorderLayout());
pathPanel.add(pathField, BorderLayout.CENTER);
pathPanel.add(pathChoice, BorderLayout.EAST);
//addComponent(pathField, gbl, gbc, 0, 1, 2,
// GridBagConstraints.WEST, (Container)fileDialog,
// 1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
//addComponent(pathChoice, gbl, gbc, 1, 1, GridBagConstraints.RELATIVE,
// GridBagConstraints.WEST, (Container)fileDialog,
// 1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
addComponent(pathPanel, gbl, gbc, 0, 1, 2, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
label = new Label(filterLabelText);
label.setFont(f);
addComponent(label, gbl, gbc, 0, 2, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.NONE, labelInset);
addComponent(filterField, gbl, gbc, 0, 3, 2, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
label = new Label(foldersLabelText);
label.setFont(f);
addComponent(label, gbl, gbc, 0, 4, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.NONE, labelInset);
label = new Label(filesLabelText);
label.setFont(f);
addComponent(label, gbl, gbc, 1, 4, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.NONE, labelInset);
addComponent(directoryList, gbl, gbc, 0, 5, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 1, GridBagConstraints.BOTH, leftListInset);
addComponent(fileList, gbl, gbc, 1, 5, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 1, GridBagConstraints.BOTH, rightListInset);
label = new Label(enterFileNameLabelText);
label.setFont(f);
addComponent(label, gbl, gbc, 0, 6, 1, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.NONE, labelInset);
addComponent(selectionField, gbl, gbc, 0, 7, 2, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.HORIZONTAL, textFieldInset);
addComponent(new Separator(fileDialog.size().width, 2, Separator.HORIZONTAL), gbl, gbc, 0, 8, 15, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.HORIZONTAL, separatorInset);
// add buttons to GridBagLayout Buttons
addComponent(openButton, gblButtons, gbc, 0, 0, 1, GridBagConstraints.WEST, (Container) buttons, 1, 0, GridBagConstraints.NONE, noInset);
addComponent(filterButton, gblButtons, gbc, 1, 0, 1, GridBagConstraints.CENTER, (Container) buttons, 1, 0, GridBagConstraints.NONE, noInset);
addComponent(cancelButton, gblButtons, gbc, 2, 0, 1, GridBagConstraints.EAST, (Container) buttons, 1, 0, GridBagConstraints.NONE, noInset);
// add ButtonPanel to the GridBagLayout of this class
addComponent(buttons, gbl, gbc, 0, 9, 2, GridBagConstraints.WEST, (Container) fileDialog, 1, 0, GridBagConstraints.HORIZONTAL, buttonsInset);
fileDialog.setSize(400, 400);
// Update choice's popup width
XChoicePeer choicePeer = (XChoicePeer) pathChoice.getPeer();
choicePeer.setDrawSelectedItem(false);
choicePeer.setAlignUnder(pathField);
filterField.addActionListener(this);
selectionField.addActionListener(this);
directoryList.addActionListener(this);
directoryList.addItemListener(this);
fileList.addItemListener(this);
fileList.addActionListener(this);
openButton.addActionListener(this);
filterButton.addActionListener(this);
cancelButton.addActionListener(this);
pathChoice.addItemListener(this);
pathField.addActionListener(this);
// b6227750 FileDialog is not disposed when clicking the 'close' (X) button on the top right corner, XToolkit
target.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
handleCancel();
}
});
// 6259434 PIT: Choice in FileDialog is not responding to keyboard interactions, XToolkit
pathChoice.addItemListener(this);
}
Aggregations