Search in sources :

Example 46 with PropertyPermission

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

the class WildcardPrincipalName method main.

public static void main(String[] args) throws Exception {
    X500Principal duke = new X500Principal("CN=Duke");
    PropertyPermission pp = new PropertyPermission("user.home", "read");
    RunAsPrivilegedUserAction runAsPrivilegedUserAction = new RunAsPrivilegedUserAction(duke, new CheckPermissionAction(pp));
    AccessController.doPrivileged(runAsPrivilegedUserAction);
    System.out.println("test PASSED");
}
Also used : PropertyPermission(java.util.PropertyPermission) X500Principal(javax.security.auth.x500.X500Principal)

Example 47 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 48 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 49 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 50 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)50 Deployment (org.jboss.arquillian.container.test.api.Deployment)26 JavaArchive (org.jboss.shrinkwrap.api.spec.JavaArchive)19 StringAsset (org.jboss.shrinkwrap.api.asset.StringAsset)17 WebArchive (org.jboss.shrinkwrap.api.spec.WebArchive)11 SocketPermission (java.net.SocketPermission)9 FilePermission (java.io.FilePermission)7 Permission (java.security.Permission)7 AccessControlException (java.security.AccessControlException)5 JMSOperations (org.jboss.as.test.integration.common.jms.JMSOperations)5 OperateOnDeployment (org.jboss.arquillian.container.test.api.OperateOnDeployment)4 PermissionCollection (java.security.PermissionCollection)3 Properties (java.util.Properties)3 CommonCriteria (org.jboss.as.test.categories.CommonCriteria)3 EnterpriseArchive (org.jboss.shrinkwrap.api.spec.EnterpriseArchive)3 Test (org.junit.Test)3 ReflectPermission (java.lang.reflect.ReflectPermission)2 SecurityPermission (java.security.SecurityPermission)2 AuthPermission (javax.security.auth.AuthPermission)2 RegistryRetriever (org.jboss.as.test.clustering.cluster.registry.bean.RegistryRetriever)2