예제 #1
0
 /**
  * Get an annotation. This is wrappered to avoid a Java2Security violation.
  *
  * @param cls Class that contains annotation
  * @param annotation Class of requrested Annotation
  * @return annotation or null
  */
 private static Annotation getAnnotation(final AnnotatedElement element, final Class annotation) {
   return (Annotation)
       AccessController.doPrivileged(
           new PrivilegedAction() {
             public Object run() {
               return element.getAnnotation(annotation);
             }
           });
 }
예제 #2
0
  public Thread newThread(final Runnable r) {
    if (threadGroup == null) {
      try {
        threadGroup =
            (ThreadGroup)
                AccessController.doPrivileged(
                    new PrivilegedExceptionAction() {
                      public Object run() {
                        return new ThreadGroup("JAX-WS Default Executor Group " + groupNumber++);
                      }
                    });
      } catch (PrivilegedActionException e) {
        if (log.isDebugEnabled()) {
          log.debug("Exception thrown from AccessController: " + e);
        }
        throw ExceptionFactory.makeWebServiceException(e.getException());
      }
    }

    threadNumber++;
    Thread returnThread = null;
    try {
      returnThread =
          (Thread)
              AccessController.doPrivileged(
                  new PrivilegedExceptionAction() {
                    public Object run() {
                      Thread newThread = new Thread(threadGroup, r);
                      newThread.setDaemon(true);
                      return newThread;
                    }
                  });
    } catch (PrivilegedActionException e) {
      if (log.isDebugEnabled()) {
        log.debug("Exception thrown from AccessController: " + e);
      }
      throw ExceptionFactory.makeWebServiceException(e.getException());
    }

    return returnThread;
  }
 // Implement Actor's takeAction method
 public void takeAction() {
   try {
     if (_usingDoPrivilege) {
       final AccessControlContext acc = AccessController.getContext();
       // Demostrate the usage of AccessController.doPrivileged(PrivilegeAction action,
       // AccessContext ctx)
       AccessController.doPrivileged(
           new PrivilegedAction() {
             public Object run() {
               _actor.takeAction();
               return null;
             }
           },
           acc);
     } else {
       // Use no doPrivileged
       _actor.takeAction();
     }
   } catch (Exception e) {
     e.printStackTrace(System.out);
   }
 }
  private static ClassLoader getContextClassLoader(final ClassLoader classLoader) {
    ClassLoader cl;
    try {
      cl =
          (ClassLoader)
              AccessController.doPrivileged(
                  new PrivilegedExceptionAction() {
                    public Object run() throws ClassNotFoundException {
                      return classLoader != null
                          ? classLoader
                          : Thread.currentThread().getContextClassLoader();
                    }
                  });
    } catch (PrivilegedActionException e) {
      if (log.isDebugEnabled()) {
        log.debug("Exception thrown from AccessController: " + e.getMessage(), e);
      }
      throw ExceptionFactory.makeWebServiceException(e.getException());
    }

    return cl;
  }