Search in sources :

Example 61 with Permission

use of java.security.Permission in project system-rules by stefanbirkner.

the class NoExitSecurityManagerTest method checkPermission_without_context_is_delegated_to_original_security_manager.

@Test
public void checkPermission_without_context_is_delegated_to_original_security_manager() {
    Permission permission = mock(Permission.class);
    managerWithOriginal.checkPermission(permission);
    verify(originalSecurityManager).checkPermission(permission);
}
Also used : Permission(java.security.Permission) Test(org.junit.Test)

Example 62 with Permission

use of java.security.Permission in project system-rules by stefanbirkner.

the class NoExitSecurityManagerTest method checkPermission_with_context_may_be_called_without_original_security_manager.

@Test
public void checkPermission_with_context_may_be_called_without_original_security_manager() {
    Permission permission = mock(Permission.class);
    Object context = new Object();
    managerWithoutOriginal.checkPermission(permission, context);
}
Also used : Permission(java.security.Permission) Test(org.junit.Test)

Example 63 with Permission

use of java.security.Permission in project system-rules by stefanbirkner.

the class NoExitSecurityManagerTest method checkPermission_with_context_is_delegated_to_original_security_manager.

@Test
public void checkPermission_with_context_is_delegated_to_original_security_manager() {
    Permission permission = mock(Permission.class);
    Object context = new Object();
    managerWithOriginal.checkPermission(permission, context);
    verify(originalSecurityManager).checkPermission(permission, context);
}
Also used : Permission(java.security.Permission) Test(org.junit.Test)

Example 64 with Permission

use of java.security.Permission in project scout.rt by eclipse.

the class LenientPermissionsWrapper method writeObject.

/**
 * @serialData Default fields.
 */
private void writeObject(ObjectOutputStream out) throws IOException {
    // no call to defaultWriteObject
    ObjectOutputStream.PutField pfields = out.putFields();
    ArrayList<LenientPermissionWrapper> list = null;
    if (m_permissions != null) {
        list = new ArrayList<LenientPermissionWrapper>();
        for (Enumeration<Permission> en = m_permissions.elements(); en.hasMoreElements(); ) {
            Permission perm = en.nextElement();
            if (perm != null) {
                list.add(new LenientPermissionWrapper(perm));
            }
        }
    }
    pfields.put("m_permissions", list);
    out.writeFields();
}
Also used : Permission(java.security.Permission) ObjectOutputStream(java.io.ObjectOutputStream)

Example 65 with Permission

use of java.security.Permission in project scout.rt by eclipse.

the class AbstractAccessControlService method getPermissionLevel.

@Override
public int getPermissionLevel(Permission p) {
    if (p == null) {
        return BasicHierarchyPermission.LEVEL_NONE;
    }
    if (!(p instanceof BasicHierarchyPermission)) {
        if (checkPermission(p)) {
            return BasicHierarchyPermission.LEVEL_ALL;
        } else {
            return BasicHierarchyPermission.LEVEL_NONE;
        }
    }
    BasicHierarchyPermission hp = (BasicHierarchyPermission) p;
    PermissionCollection c = getPermissions();
    if (c == null) {
        List<Integer> levels = hp.getValidLevels();
        return levels.get(levels.size() - 1);
    } else {
        int maxLevel = BasicHierarchyPermission.LEVEL_UNDEFINED;
        Enumeration<Permission> en = c.elements();
        while (en.hasMoreElements()) {
            Permission grantedPermission = en.nextElement();
            // catch AllPermission
            if (grantedPermission instanceof AllPermission) {
                return BasicHierarchyPermission.LEVEL_ALL;
            }
            // process basic hierarchy permissions
            if (grantedPermission instanceof BasicHierarchyPermission) {
                BasicHierarchyPermission hgrantedPermission = (BasicHierarchyPermission) grantedPermission;
                if (hgrantedPermission.getClass().isAssignableFrom(hp.getClass())) {
                    maxLevel = Math.max(maxLevel, hgrantedPermission.getLevel());
                    if (maxLevel >= BasicHierarchyPermission.LEVEL_ALL) {
                        break;
                    }
                }
            }
        }
        return maxLevel;
    }
}
Also used : PermissionCollection(java.security.PermissionCollection) AllPermission(java.security.AllPermission) BasicHierarchyPermission(org.eclipse.scout.rt.shared.security.BasicHierarchyPermission) Permission(java.security.Permission) BasicHierarchyPermission(org.eclipse.scout.rt.shared.security.BasicHierarchyPermission) AllPermission(java.security.AllPermission)

Aggregations

Permission (java.security.Permission)236 Test (org.junit.Test)55 PermissionCollection (java.security.PermissionCollection)39 FilePermission (java.io.FilePermission)38 Permissions (java.security.Permissions)31 ProtectionDomain (java.security.ProtectionDomain)27 IOException (java.io.IOException)20 AllPermission (java.security.AllPermission)20 QuickTest (com.hazelcast.test.annotation.QuickTest)17 File (java.io.File)17 URL (java.net.URL)16 AccessControlException (java.security.AccessControlException)14 Principal (java.security.Principal)14 PropertyPermission (java.util.PropertyPermission)14 Policy (java.security.Policy)13 MBeanPermission (javax.management.MBeanPermission)13 AccessControlContext (java.security.AccessControlContext)12 CodeSource (java.security.CodeSource)11 SecurityPermission (java.security.SecurityPermission)11 ArrayList (java.util.ArrayList)10