Examples of SystemPermission


Examples of org.apache.derby.security.SystemPermission

            return;
        }

        // the check
        try {
            final Permission sp  = new SystemPermission(
                  SystemPermission.SERVER, SystemPermission.SHUTDOWN);
            // For porting the network server to J2ME/CDC, consider calling
            // abstract method InternalDriver.checkShutdownPrivileges(user)
            // instead of static SecurityUtil.checkUserHasPermission().
            // SecurityUtil.checkUserHasPermission(userArg, sp);
View Full Code Here

Examples of org.apache.derby.security.SystemPermission

            return;
        }

        // the check
        try {
            final Permission sp  = new SystemPermission(
                  SystemPermission.SERVER, SystemPermission.SHUTDOWN);
            // SecurityUtil.checkUserHasPermission(userArg, sp);
        } catch (AccessControlException ace) {
            throw Util.generateCsSQLException(
                SQLState.AUTH_SHUTDOWN_MISSING_PERMISSION,
View Full Code Here

Examples of org.apache.derby.security.SystemPermission

            return;
        }

        // the check
        try {
            final Permission sp = new SystemPermission(
                SystemPermission.ENGINE, SystemPermission.SHUTDOWN);
            checkSystemPrivileges(user, sp);
        } catch (AccessControlException ace) {
            throw Util.generateCsSQLException(
        SQLState.AUTH_SHUTDOWN_MISSING_PERMISSION,
View Full Code Here

Examples of org.apache.derby.security.SystemPermission

     * Tests SystemPermission.
     */
    public void testSystemPermission() {
        // test SystemPermission with null name argument
        try {
            new SystemPermission(null, null);
            fail("expected NullPointerException");
        } catch (NullPointerException ex) {
            // expected exception
        }

        // test SystemPermission with empty name argument
        try {
            new SystemPermission("", null);
            fail("expected IllegalArgumentException");
        } catch (IllegalArgumentException ex) {
            // expected exception
        }
       
        // test SystemPermission with illegal name argument
        try {
            new SystemPermission("illegal_name", null);
            fail("expected IllegalArgumentException");
        } catch (IllegalArgumentException ex) {
            // expected exception
        }

        // actions cannot be null
        try {
            new SystemPermission("server", null);
            fail("expected NullPointerException");
        } catch (NullPointerException ex) {
            // expected exception
        }

        // Illegal and duplicate actions are ignored.
        assertEquals("", new SystemPermission("server", "").getActions());
        assertEquals("", new SystemPermission("server", ",,").getActions());
        assertEquals("",
                     new SystemPermission("server", "illegal_action")
                             .getActions());
        assertEquals("control",
                     new SystemPermission("server", "control,").getActions());
        assertEquals("control",
                     new SystemPermission("server", "control,illegal_action")
                             .getActions());
        assertEquals("control",
                     new SystemPermission("server", "control,control")
                             .getActions());
        assertEquals("control,monitor",
                     new SystemPermission("server", "control, monitor, control")
                             .getActions());
        assertEquals("control,monitor",
                     new SystemPermission("server", "monitor, control, monitor")
                             .getActions());
        assertEquals("control",
                     new SystemPermission("server", "CoNtRoL")
                             .getActions());
        assertEquals("control",
                     new SystemPermission("server", "CoNtRoL,control")
                             .getActions());

        String[] validNames = {
            SystemPermission.ENGINE,
            SystemPermission.JMX,
            SystemPermission.SERVER
        };
       
        // In order of the canonical actions expected
        String[] validActions = {
            SystemPermission.CONTROL,
            SystemPermission.MONITOR,
            SystemPermission.SHUTDOWN,
        };
       
        // Check all valid combinations (which is all) with
        // a single action
        Permission[] all = new Permission[
                        validNames.length * validActions.length];
       
        int c = 0;
        for (int tn = 0; tn < validNames.length; tn++)
        {
            for (int a = 0; a < validActions.length; a++) {
                Permission p = new SystemPermission(
                        validNames[tn], validActions[a]);
               
                assertEquals(validNames[tn], p.getName());
                assertEquals(validActions[a], p.getActions());
               
                // test SystemPermission.equals()
                assertFalse(p.equals(null));
                assertFalse(p.equals(new Object()));
               
                this.assertEquivalentPermissions(p, p);

                all[c++] = p;
            }
        }
        // All the permissions are different.
        checkDistinctPermissions(all);
       
        // Check two actions
        for (int n = 0; n < validNames.length; n++)
        {
            for (int a = 0; a < validActions.length; a++)
            {
                Permission base = new SystemPermission(
                        validNames[n], validActions[a]);
               
                // Two actions
                for (int oa = 0; oa < validActions.length; oa++)
                {
                    Permission p = new SystemPermission(
                            validNames[n],                          
                            validActions[a] + "," + validActions[oa]);
                   
                    if (oa == a)
                    {
                        // Same action added twice
                        assertEquivalentPermissions(base, p);
                        // Canonical form should collapse into a single action
                        assertEquals(validActions[a], p.getActions());
                    }
                    else
                    {
                        // Implies logic, the one with one permission
                        // is implied by the other but not vice-versa.
                        assertTrue(p.implies(base));
                        assertFalse(base.implies(p));
                       
                        // Names in canonical form
                        int f;
                        int s;
                        if (oa < a)
                        {
                            f = oa;
                            s = a;
                        }
                        else
                        {
                            f = a;
                            s = oa;
                        }
                        if (oa < a)
                        assertEquals(validActions[f] + "," + validActions[s],
                                p.getActions());
                    }
                }
            }
        }

View Full Code Here

Examples of org.apache.derby.security.SystemPermission

    /**
     * Tests SystemPermissions against the Policy.
     */
    public void policyTestSystemPermissionGrants() {
        final Permission shutdown
            = new SystemPermission(
                SystemPermission.SERVER,
                SystemPermission.SHUTDOWN);
       
        // test SystemPermission for authorized user
        final SystemPrincipal authorizedUser
View Full Code Here

Examples of org.apache.derby.security.SystemPermission

        // serialize and deserialize.
        for (String name : VALID_SYSPERM_NAMES) {
            for (String action : VALID_SYSPERM_ACTIONS) {
                // Actions are case-insensitive, so test both lower-case
                // and upper-case.
                SystemPermission pl =
                    new SystemPermission(name, action.toLowerCase(Locale.US));
                SystemPermission pu =
                    new SystemPermission(name, action.toUpperCase(Locale.US));
                assertEquals(pl, serializeDeserialize(pl, null));
                assertEquals(pu, serializeDeserialize(pu, null));
            }
        }

        // A permission can specify multiple actions ...
        SystemPermission sp = new SystemPermission(
                "server", "control,monitor,shutdown");
        assertEquals(sp, serializeDeserialize(sp, null));

        // ... but only a single name, so this should fail.
        // (Did not fail before DERBY-3476.)
        serializeDeserialize(
                createSyspermNoCheck("server,jmx", "control"),
                IllegalArgumentException.class);

        // Invalid and duplicate actions should be ignored.
        sp = serializeDeserialize(createSyspermNoCheck(
                    VALID_SYSPERM_NAMES[0],
                    "control,invalid,control,,shutdown"),
                null);
        // The next assert failed before DERBY-3476.
        assertEquals("control,shutdown", sp.getActions());

        // Empty action is allowed.
        sp = new SystemPermission(VALID_SYSPERM_NAMES[0], "");
        assertEquals(sp, serializeDeserialize(sp, null));

        // Name is case-sensitive, so this should fail.
        // (Did not fail before DERBY-3476.)
        serializeDeserialize(createSyspermNoCheck(
View Full Code Here

Examples of org.apache.derby.security.SystemPermission

     */
    private static SystemPermission
                        createSyspermNoCheck(String name, String actions) {
        // First create a valid permission object, so that the checks in
        // the constructor are happy.
        SystemPermission sysperm = new SystemPermission("server", "control");

        // Then use reflection to override the values of the fields with
        // potentially invalid values.
        setField(Permission.class, "name", sysperm, name);
        setField(SystemPermission.class, "actions", sysperm, actions);
View Full Code Here

Examples of org.apache.derby.security.SystemPermission

            return;
        }

        // the check
        try {
            final Permission sp  = new SystemPermission(
                  SystemPermission.SERVER, SystemPermission.SHUTDOWN);
            // For porting the network server to J2ME/CDC, consider calling
            // abstract method InternalDriver.checkShutdownPrivileges(user)
            // instead of static SecurityUtil.checkUserHasPermission().
            // SecurityUtil.checkUserHasPermission(userArg, sp);
View Full Code Here

Examples of org.apache.derby.security.SystemPermission

            return;
        }

        // the check
        try {
            final Permission sp = new SystemPermission(
                SystemPermission.ENGINE, SystemPermission.SHUTDOWN);
            checkSystemPrivileges(user, sp);
        } catch (AccessControlException ace) {
            throw Util.generateCsSQLException(
        SQLState.AUTH_SHUTDOWN_MISSING_PERMISSION,
View Full Code Here

Examples of org.apache.derby.security.SystemPermission

            return;
        }

        // the check
        try {
            final Permission sp = new SystemPermission(
                SystemPermission.ENGINE, SystemPermission.SHUTDOWN);
            checkSystemPrivileges(user, sp);
        } catch (AccessControlException ace) {
            throw Util.generateCsSQLException(
        SQLState.AUTH_SHUTDOWN_MISSING_PERMISSION,
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.