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

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


     *
     */
    public void run() throws Exception {
        PrivilegedAction testPA = new TestPrivilegedAction();
        PrivilegedExceptionAction testPEA =
                new TestPrivilegedExceptionAction();
        AccessControlContext testACC = AccessController.getContext();
        System.setSecurityManager(new SecurityManager());
        Policy.setPolicy(new BasePolicyProvider());
        logger.fine("Security manager and policy provider are not "
                + "instances of SecurityContextSource.");
View Full Code Here


                    + "NullPointerException was expected.");
        } catch (NullPointerException npe) {
            // PASS
            logger.fine("NullPointerException was thrown as expected.");
        }
        final TestPrivilegedExceptionAction pea =
                new TestPrivilegedExceptionAction(perm);
        obj = callDoPrivileged(pea);

        if (pea.getCombiner() != null) {
            // FAIL
            throw new TestException(
                    "DomainCombiner inside 'doPrivileged' method of "
                    + pea + " was " + pea.getCombiner()
                    + " while null was expected.");
        }

        // PASS
        logger.fine("DomainCombiner inside 'doPrivileged' method of "
                + pea + " was null as expected.");

        if (!pea.isGrantedPerm()) {
            // FAIL
            throw new TestException(
                    "Privileges are not enabled inside 'doPrivileged' "
                    + "method.");
        }

        // PASS
        logger.fine("Privileges are enabled inside 'doPrivileged' "
                + "method as expected.");

        if (pea.getObject() != obj) {
            // FAIL
            throw new TestException(
                    "'doPrivileged' method returned " + obj + " while "
                    + pea.getObject() + " was expected.");
        }

        // PASS
        logger.fine("'doPrivileged' method returned " + obj
                + " as expected.");
        final TestPrivilegedExceptionAction pea1
                = new TestPrivilegedExceptionAction(perm1);
        Subject subj = new Subject();
        Principal prin = new FakePrincipal("DoPrivilegedExceptionTest");
        subj.getPrincipals().add(prin);
        SubjectDomainCombiner comb = new SubjectDomainCombiner(subj);
        AccessControlContext acc = new AccessControlContext(
                AccessController.getContext(), comb);
        obj = AccessController.doPrivileged(
                new PrivilegedExceptionAction() {
                    public Object run() throws Exception {
                        return callDoPrivileged(pea1);
                    }
                }, acc);

        if (pea1.getCombiner() != comb) {
            // FAIL
            throw new TestException(
                    "DomainCombiner inside 'doPrivileged' method of "
                    + pea1 + " was " + pea1.getCombiner()
                    + " while " + comb + " was expected.");
        }

        // PASS
        logger.fine("DomainCombiner inside 'doPrivileged' method of "
                + pea1 + " was " + comb + " as expected.");

        if (!pea1.isGrantedPerm()) {
            // FAIL
            throw new TestException(
                    "Privileges are not enabled inside 'doPrivileged' "
                    + "method.");
        }

        // PASS
        logger.fine("Privileges are enabled inside 'doPrivileged' "
                + "method as expected.");

        if (pea1.getObject() != obj) {
            // FAIL
            throw new TestException(
                    "'doPrivileged' method returned " + obj + " while "
                    + pea1.getObject() + " was expected.");
        }

        // PASS
        logger.fine("'doPrivileged' method returned " + obj
                + " as expected.");
View Full Code Here

TOP

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

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.