Package net.jini.security

Examples of net.jini.security.SecurityContext


      if (strongRef instanceof Unreferenced) {
    final Unreferenced obj = (Unreferenced) strongRef;
    final Thread t = (Thread) AccessController.doPrivileged(
        new NewThreadAction(new Runnable() {
      public void run() {
          SecurityContext securityContext =
        target.getSecurityContext();
          AccessController.doPrivileged(securityContext.wrap(
        new PrivilegedAction() {
            public Object run() {
          obj.unreferenced();
          return null;
            }
        }), securityContext.getAccessControlContext());
      }
        }, "Unreferenced", false, true));
    AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
      t.setContextClassLoader(
View Full Code Here


      public Object run() { return null; }
  };
  PrivilegedExceptionAction pea = new PrivilegedExceptionAction() {
      public Object run() { return null; }
  };
  SecurityContext ctx = Security.getContext();
  if (ctx.wrap(pa) != pa || ctx.wrap(pea) != pea) {
      throw new Error("default context should not wrap actions");
  }

  TestSecurityManager tsm = new TestSecurityManager();
  System.setSecurityManager(tsm);
View Full Code Here

     *
     * @return  {@inheritDoc}
     */
    public SecurityContext getContext() {
  Policy p = getCurrentSubPolicy();
  SecurityContext sc = (p instanceof SecurityContextSource) ?
      ((SecurityContextSource) p).getContext() :
      new DefaultSecurityContext();
  return new AggregateSecurityContext(sc);
    }
View Full Code Here

      if (strongRef instanceof Unreferenced) {
    final Unreferenced obj = (Unreferenced) strongRef;
    final Thread t = (Thread) AccessController.doPrivileged(
        new NewThreadAction(new Runnable() {
      public void run() {
          SecurityContext securityContext =
        target.getSecurityContext();
          AccessController.doPrivileged(securityContext.wrap(
        new PrivilegedAction() {
            public Object run() {
          obj.unreferenced();
          return null;
            }
        }), securityContext.getAccessControlContext());
      }
        }, "Unreferenced", false, true));
    AccessController.doPrivileged(new PrivilegedAction() {
        public Object run() {
      t.setContextClassLoader(
View Full Code Here

    {
  DgcRequestDispatcher[] rds = new DgcRequestDispatcher[requestDispatchers.length];
  for (int i = 0; i < requestDispatchers.length; i++) {
      rds[i] = getRD(requestDispatchers[i]);
  }
        SecurityContext securityContext = Security.getContext();
        ClassLoader ccl = Thread.currentThread().getContextClassLoader();
        Target t = null;
        t = new Target(id, rds, allowDGC, keepAlive,this,
                securityContext, ccl, keepAliveCount);
        synchronized (requestDispatchersLock){
View Full Code Here

      } else {
    return null;
      }
  }
  logger.log(Level.FINER, "{0} has ProxyTrustIterator", obj);
  SecurityContext rsc = uosc.getContext();
  ProxyTrustIterator iter;
  try {
      iter = (ProxyTrustIterator) restrictedInvoke(m, obj, rsc);
  } catch (IllegalAccessException e) {
      throw new AssertionError(e);
View Full Code Here

        System.setSecurityManager(new SecurityManager());
        Policy.setPolicy(new BasePolicyProvider());
        logger.fine("Security manager and policy provider are not "
                + "instances of SecurityContextSource.");
        logger.fine("Calling 'Security.getContext()' method.");
        SecurityContext sc = Security.getContext();

        if (sc.wrap(testPA) != testPA) {
            // FAIL
            throw new TestException(
                    "Returned SecurityContext's 'wrap(PrivilegedAction)' "
                    + "method returned " + sc.wrap(testPA) + " while "
                    + testPA + " was expected.");
        }

        if (sc.wrap(testPEA) != testPEA) {
            // FAIL
            throw new TestException(
                    "Returned SecurityContext's "
                    + "'wrap(PrivilegedExceptionAction)' method returned "
                    + sc.wrap(testPEA) + " while " + testPEA
                    + " was expected.");
        }

        // PASS
        logger.fine("Method returned correct SecurityContext instance.");
        logger.fine("Set policy provider to SCSPolicyProvider.");
        SCSPolicyProvider policy = new SCSPolicyProvider();
        Policy.setPolicy(policy);
        sc = Security.getContext();

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

        if (!sc.equals(policy.getContext())) {
            // FAIL
            throw new TestException(
                    "'Security.getContext()' method returned " + sc
                    + " SecurityPolicy while " + policy.getContext()
                    + " was expected.");
        }

        // PASS
        logger.fine("Method works as expected.");
        logger.fine("Set security manager to SCSSecurityManager.");
        SCSSecurityManager sm = new SCSSecurityManager();
        System.setSecurityManager(sm);
        policy.resetCallsNum();
        sc = Security.getContext();

        if (sm.getCallsNum() != 1) {
            // FAIL
            throw new TestException(
                    "'getContext' method of installed security manager was "
                    + "called " + sm.getCallsNum() + " times while 1 "
                    + "call was expected.");
        }

        if (policy.getCallsNum() != 0) {
            // FAIL
            throw new TestException(
                    "'getContext' method of installed policy provider was "
                    + "called " + policy.getCallsNum()
                    + " times while no calls were expected.");
        }

        if (!sc.equals(sm.getContext())) {
            // FAIL
            throw new TestException(
                    "'Security.getContext()' method returned " + sc
                    + " SecurityPolicy while " + sm.getContext()
                    + " was expected.");
View Full Code Here

TOP

Related Classes of net.jini.security.SecurityContext

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.