Search in sources :

Example 66 with PropertyPermission

use of java.util.PropertyPermission in project jdk8u_jdk by JetBrains.

the class System method clearProperty.

/**
     * Removes the system property indicated by the specified key.
     * <p>
     * First, if a security manager exists, its
     * <code>SecurityManager.checkPermission</code> method
     * is called with a <code>PropertyPermission(key, "write")</code>
     * permission. This may result in a SecurityException being thrown.
     * If no exception is thrown, the specified property is removed.
     * <p>
     *
     * @param      key   the name of the system property to be removed.
     * @return     the previous string value of the system property,
     *             or <code>null</code> if there was no property with that key.
     *
     * @exception  SecurityException  if a security manager exists and its
     *             <code>checkPropertyAccess</code> method doesn't allow
     *              access to the specified system property.
     * @exception  NullPointerException if <code>key</code> is
     *             <code>null</code>.
     * @exception  IllegalArgumentException if <code>key</code> is empty.
     * @see        #getProperty
     * @see        #setProperty
     * @see        java.util.Properties
     * @see        java.lang.SecurityException
     * @see        java.lang.SecurityManager#checkPropertiesAccess()
     * @since 1.5
     */
public static String clearProperty(String key) {
    checkKey(key);
    SecurityManager sm = getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new PropertyPermission(key, "write"));
    }
    return (String) props.remove(key);
}
Also used : PropertyPermission(java.util.PropertyPermission)

Example 67 with PropertyPermission

use of java.util.PropertyPermission in project checker-framework by typetools.

the class System method setProperty.

/**
 * Sets the system property indicated by the specified key.
 * <p>
 * First, if a security manager exists, its
 * <code>SecurityManager.checkPermission</code> method
 * is called with a <code>PropertyPermission(key, "write")</code>
 * permission. This may result in a SecurityException being thrown.
 * If no exception is thrown, the specified property is set to the given
 * value.
 * <p>
 *
 * @param      key   the name of the system property.
 * @param      value the value of the system property.
 * @return     the previous value of the system property,
 *             or <code>null</code> if it did not have one.
 *
 * @exception  SecurityException  if a security manager exists and its
 *             <code>checkPermission</code> method doesn't allow
 *             setting of the specified property.
 * @exception  NullPointerException if <code>key</code> or
 *             <code>value</code> is <code>null</code>.
 * @exception  IllegalArgumentException if <code>key</code> is empty.
 * @see        #getProperty
 * @see        java.lang.System#getProperty(java.lang.String)
 * @see        java.lang.System#getProperty(java.lang.String, java.lang.String)
 * @see        java.util.PropertyPermission
 * @see        SecurityManager#checkPermission
 * @since      1.2
 */
public static String setProperty(String key, String value) {
    checkKey(key);
    SecurityManager sm = getSecurityManager();
    if (sm != null) {
        sm.checkPermission(new PropertyPermission(key, SecurityConstants.PROPERTY_WRITE_ACTION));
    }
    return (String) props.setProperty(key, value);
}
Also used : PropertyPermission(java.util.PropertyPermission)

Example 68 with PropertyPermission

use of java.util.PropertyPermission in project rt.equinox.framework by eclipse.

the class AdminPermissionTests method testAdminPermission.

public void testAdminPermission() {
    AdminPermission p1 = new AdminPermission();
    // $NON-NLS-1$ //$NON-NLS-2$
    AdminPermission p2 = new AdminPermission("*", "*");
    // $NON-NLS-1$ //$NON-NLS-2$
    Permission op = new PropertyPermission("java.home", "read");
    shouldImply(p1, p2);
    shouldImply(p1, p1);
    shouldNotImply(p1, op);
    shouldEqual(p1, p2);
    shouldNotEqual(p1, op);
    PermissionCollection pc = p1.newPermissionCollection();
    checkEnumeration(pc.elements(), true);
    shouldNotImply(pc, p1);
    shouldAdd(pc, p1);
    shouldAdd(pc, p2);
    shouldNotAdd(pc, op);
    pc.setReadOnly();
    shouldNotAdd(pc, new AdminPermission());
    shouldImply(pc, p1);
    shouldImply(pc, p2);
    shouldNotImply(pc, op);
    checkEnumeration(pc.elements(), false);
    testSerialization(p1);
    testSerialization(p2);
}
Also used : PermissionCollection(java.security.PermissionCollection) AdminPermission(org.osgi.framework.AdminPermission) PropertyPermission(java.util.PropertyPermission) Permission(java.security.Permission) AdminPermission(org.osgi.framework.AdminPermission) PropertyPermission(java.util.PropertyPermission)

Example 69 with PropertyPermission

use of java.util.PropertyPermission in project Payara by payara.

the class SSLUtils method checkPermission.

public static void checkPermission(String key) {
    try {
        // Checking a random permission to check if it is server.
        if (Util.isEmbeddedServer() || Util.getDefaultHabitat() == null || Util.getInstance().isACC() || Util.getInstance().isNotServerOrACC()) {
            return;
        }
        Permission perm = new RuntimePermission("SSLPassword");
        AccessController.checkPermission(perm);
    } catch (AccessControlException e) {
        String message = e.getMessage();
        Permission perm = new PropertyPermission(key, "read");
        if (message != null) {
            message = message.replace(e.getPermission().toString(), perm.toString());
        }
        throw new AccessControlException(message, perm);
    }
}
Also used : PropertyPermission(java.util.PropertyPermission) PropertyPermission(java.util.PropertyPermission) Permission(java.security.Permission) AccessControlException(java.security.AccessControlException)

Example 70 with PropertyPermission

use of java.util.PropertyPermission in project Payara by payara.

the class SecuritySupportImpl method checkPermission.

public void checkPermission(String key) {
    try {
        // Checking a random permission to check if it is server.
        if (isEmbeddedServer() || habitat == null || isACC() || isNotServerORACC()) {
            return;
        }
        Permission perm = new RuntimePermission("SSLPassword");
        AccessController.checkPermission(perm);
    } catch (AccessControlException e) {
        String message = e.getMessage();
        Permission perm = new PropertyPermission(key, "read");
        if (message != null) {
            message = message.replace(e.getPermission().toString(), perm.toString());
        }
        throw new AccessControlException(message, perm);
    }
}
Also used : PropertyPermission(java.util.PropertyPermission) PropertyPermission(java.util.PropertyPermission) Permission(java.security.Permission) AccessControlException(java.security.AccessControlException)

Aggregations

PropertyPermission (java.util.PropertyPermission)99 Deployment (org.jboss.arquillian.container.test.api.Deployment)49 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)46 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)35 FilePermission (java.io.FilePermission)23 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)18 SocketPermission (java.net.SocketPermission)13 JMSOperations (org.jboss.as.test.integration.common.jms.JMSOperations)13 Permission (java.security.Permission)10 AccessControlException (java.security.AccessControlException)8 RemotingPermission (org.jboss.remoting3.security.RemotingPermission)8 PermissionCollection (java.security.PermissionCollection)7 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)7 ReflectPermission (java.lang.reflect.ReflectPermission)6 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)6 Permissions (java.security.Permissions)5 SecurityPermission (java.security.SecurityPermission)5 AccessControlContext (java.security.AccessControlContext)4 TimeoutUtil (org.jboss.as.test.shared.TimeoutUtil)4 Method (java.lang.reflect.Method)3