Package org.apache.derby.security

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


            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

     * Tests SystemPermission.
     */
    private void checkSystemPermission() throws IOException {
        // test SystemPermission with null name argument
        try {
            new SystemPermission(null);
            fail("expected NullPointerException");
        } catch (NullPointerException ex) {
            // expected exception
        }

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

        // test SystemPermission with legal name argument
        final Permission sp0 = new SystemPermission(SystemPermission.SHUTDOWN);
        final Permission sp1 = new SystemPermission(SystemPermission.SHUTDOWN);

        // test SystemPermission.getName()
        assertEquals(sp0.getName(), SystemPermission.SHUTDOWN);

        // test SystemPermission.getActions()
        assertEquals(sp0.getActions(), "");

        // test SystemPermission.hashCode()
        assertTrue(sp0.hashCode() == sp1.hashCode());

        // test SystemPermission.equals()
        assertTrue(sp0.equals(sp1));
        assertTrue(!sp0.equals(null));
        assertTrue(!sp0.equals(new Object()));

        // test SystemPermission.implies()
        assertTrue(sp0.implies(sp1));
        assertTrue(sp1.implies(sp0));

        // test SystemPermission for authorized user against policy file
        final DatabasePrincipal authorizedUser
            = new DatabasePrincipal("authorizedSystemUser");
        execute(authorizedUser, new ShutdownEngineAction(sp0), true);
View Full Code Here

     * Tests SystemPermission.
     */
    private void checkSystemPermission() throws IOException {
        // test SystemPermission with null name argument
        try {
            new SystemPermission(null);
            fail("expected NullPointerException");
        } catch (NullPointerException ex) {
            // expected exception
        }

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

        // test SystemPermission with legal name argument
        final Permission sp0 = new SystemPermission(SystemPermission.SHUTDOWN);
        final Permission sp1 = new SystemPermission(SystemPermission.SHUTDOWN);

        // test SystemPermission.getName()
        assertEquals(sp0.getName(), SystemPermission.SHUTDOWN);

        // test SystemPermission.getActions()
        assertEquals(sp0.getActions(), "");

        // test SystemPermission.hashCode()
        assertTrue(sp0.hashCode() == sp1.hashCode());

        // test SystemPermission.equals()
        assertTrue(sp0.equals(sp1));
        assertTrue(!sp0.equals(null));
        assertTrue(!sp0.equals(new Object()));

        // test SystemPermission.implies()
        assertTrue(sp0.implies(sp1));
        assertTrue(sp1.implies(sp0));

        // test SystemPermission for authorized user against policy file
        final DatabasePrincipal authorizedUser
            = new DatabasePrincipal("authorizedSystemUser");
        execute(authorizedUser, new ShutdownEngineAction(sp0), true);
View Full Code Here

            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

            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

            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

            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

     * 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

    /**
     * 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

TOP

Related Classes of org.apache.derby.security.SystemPermission

Copyright © 2018 www.massapicom. 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.