Package com.sun.jini.test.spec.security.util

Examples of com.sun.jini.test.spec.security.util.TestDynamicPolicyProvider


        logger.fine("Called 'Security.grantSupported()' method returned "
                + "false as expected.");
        logger.fine("Set policy provider to TestDynamicPolicyProvider "
                + "with value returned by 'grantSupported' method set "
                + "to false.");
        TestDynamicPolicyProvider policy = new TestDynamicPolicyProvider();
        policy.setGrantSupported(false);
        Policy.setPolicy(policy);
        res = Security.grantSupported();

        if (res) {
            // FAIL
            throw new TestException(
                    "Called 'Security.grantSupported()' method returned "
                    + "true while false was expected.");
        }

        // PASS
        logger.fine("Called 'Security.grantSupported()' method returned "
                + "false as expected.");

        if (policy.getGrantSupNum() != 1) {
            // FAIL
            throw new TestException(
                    "'grantSupported()' method of installed policy "
                    + "provider was called " + policy.getGrantSupNum()
                    + " times while 1 call was expected.");
        }

        // PASS
        logger.fine("'grantSupported()' method of installed policy "
                + "provider was called as expected.");
        logger.fine("Set value returned by 'grantSupported' method "
                + "to true.");
        policy.setGrantSupported(true);
        res = Security.grantSupported();

        if (!res) {
            // FAIL
            throw new TestException(
                    "Called 'Security.grantSupported()' method returned "
                    + "false while true was expected.");
        }

        // PASS
        logger.fine("Called 'Security.grantSupported()' method returned "
                + "true as expected.");

        if (policy.getGrantSupNum() != 2) {
            // FAIL
            throw new TestException(
                    "'grantSupported()' method of installed policy "
                    + "provider was called " + (policy.getGrantSupNum() - 1)
                    + " times while 1 call was expected.");
        }

        // PASS
        logger.fine("'grantSupported()' method of installed policy "
View Full Code Here


            new GrantPermission(new FilePermission("*", "read")),
            new GrantPermission(new RuntimePermission("getClassLoader")) };
        Principal testPrin = new FakePrincipal();
        Subject subj = new Subject();
        subj.getPrincipals().add(testPrin);
        TestDynamicPolicyProvider policy =
                new TestDynamicPolicyProvider(testPerm);
        logger.fine("Policy provider is " + policy);
        Policy.setPolicy(policy);
        Subject.doAs(subj, new FakePrivilegedAction(fromClass, toClass));
        Object[] params = policy.getGetGrantsParams();

        if (params == null || params.length == 0) {
            // FAIL
            throw new TestException(
                    "'getGrants' method of " + policy + " was not called.");
        }

        if (!params[0].equals(fromClass)) {
            // FAIL
            throw new TestException(
                    "1-st parameter to 'getGrants' was " + params[0]
                    + " while " + fromClass + " was expected.");
        }

        if (params[1] == null || ((Object []) params[1]).length != 1
                || !((Object []) params[1])[0].equals(testPrin)) {
            // FAIL
            throw new TestException(
                    "2-nd parameter to 'getGrants' was "
                    + Util.arrayToString((Object []) params[1])
                    + " while " + testPrin + " was expected.");
        }

        // PASS
        logger.fine("'getGrants' method of installed policy provider "
                + " was called with correct parameters.");
        params = policy.getGrantParams();

        if (params == null || params.length == 0) {
            // FAIL
            throw new TestException(
                    "'grant' method of " + policy + " was not called.");
        }

        if (!params[0].equals(toClass)) {
           // FAIL
           throw new TestException(
                   "1-st parameter was " + params[0]
                   + " while " + toClass + " was expected.");
        }

        if (params[1] == null || ((Object []) params[1]).length != 1
                || !((Object []) params[1])[0].equals(testPrin)) {
            // FAIL
            throw new TestException(
                    "2-nd parameter was "
                    + Util.arrayToString((Object []) params[1])
                    + " while " + testPrin + " was expected.");
        }

        if (!Util.comparePermissions((Object []) params[2], testPerm)) {
          // FAIL
            throw new TestException(
                    "3-rd parameter was "
                    + Util.arrayToString((Object []) params[2])
                    + " while " + Util.arrayToString(testPerm)
                    + " was expected.");
        }

        // PASS
        logger.fine("'grant' method of installed policy provider "
                + " was called with correct parameters.");

        // not granted list of permissions
        Permission[] notGrantedPerm = new Permission[] {
            new GrantPermission(new PropertyPermission("*", "read")),
            new GrantPermission(new RuntimePermission("getClassLoader")) };
        policy = new TestDynamicPolicyProvider(testPerm, notGrantedPerm);
        logger.fine("Policy provider is " + policy);
        Policy.setPolicy(policy);
        Subject.doAs(subj, new FakePrivilegedAction(fromClass, toClass));
        params = policy.getGetGrantsParams();

        if (params == null || params.length == 0) {
            // FAIL
            throw new TestException(
                    "'getGrants' method of " + policy + " was not called.");
        }

        if (!params[0].equals(fromClass)) {
            // FAIL
            throw new TestException(
                    "1-st parameter to 'getGrants' was " + params[0]
                    + " while " + fromClass + " was expected.");
        }

        if (params[1] == null || ((Object []) params[1]).length != 1
                || !((Object []) params[1])[0].equals(testPrin)) {
            // FAIL
            throw new TestException(
                    "2-nd parameter to 'getGrants' was "
                    + Util.arrayToString((Object []) params[1])
                    + " while " + testPrin + " was expected.");
        }

        // PASS
        logger.fine("'getGrants' method of installed policy provider "
                + " was called with correct parameters.");
        params = policy.getGrantParams();

        if (params == null || params.length == 0) {
            // FAIL
            throw new TestException(
                    "'grant' method of " + policy + " was not called.");
View Full Code Here

TOP

Related Classes of com.sun.jini.test.spec.security.util.TestDynamicPolicyProvider

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.