當前位置: 首頁>>代碼示例>>Java>>正文


Java PrivilegedActionException類代碼示例

本文整理匯總了Java中java.security.PrivilegedActionException的典型用法代碼示例。如果您正苦於以下問題:Java PrivilegedActionException類的具體用法?Java PrivilegedActionException怎麽用?Java PrivilegedActionException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


PrivilegedActionException類屬於java.security包,在下文中一共展示了PrivilegedActionException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getMethod

import java.security.PrivilegedActionException; //導入依賴的package包/類
/** Convenience method for getting access to a method through reflection.
 * Same as Class.getDeclaredMethod, but only throws RuntimeExceptions.
 * @param cls The class to search for a method.
 * @param name The method name.
 * @param types The array of argument types.
 * @return The Method if found.
 * @throws GmbalException if no such method is found.
 */
public static Method getMethod( final Class<?> cls, final String name,
    final Class<?>... types ) {

    try {
        return AccessController.doPrivileged(
            new PrivilegedExceptionAction<Method>() {
                public Method run() throws Exception {
                    return cls.getDeclaredMethod(name, types);
                }
            });
    } catch (PrivilegedActionException ex) {
        throw new GmbalException( "Unexpected exception", ex ) ;
    } catch (SecurityException exc) {
        throw new GmbalException( "Unexpected exception", exc ) ;
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:25,代碼來源:ManagedObjectManagerFactory.java

示例2: validateServiceTicket

import java.security.PrivilegedActionException; //導入依賴的package包/類
public static String validateServiceTicket(Subject subject, final byte[] serviceTicket)
    throws GSSException, IllegalAccessException, NoSuchFieldException, ClassNotFoundException,
    PrivilegedActionException {
  // Kerberos version 5 OID
  Oid krb5Oid = KerberosUtils.getOidInstance("GSS_KRB5_MECH_OID");


  // Accept the context and return the client principal name.
  return Subject.doAs(subject, new PrivilegedExceptionAction<String>() {

    @Override
    public String run() throws Exception {
      String clientName = null;
      // Identify the server that communications are being made to.
      GSSManager manager = GSSManager.getInstance();
      GSSContext context = manager.createContext((GSSCredential) null);
      context.acceptSecContext(serviceTicket, 0, serviceTicket.length);
      clientName = context.getSrcName().toString();
      return clientName;
    }
  });
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:23,代碼來源:KerberosTicketOperations.java

示例3: isRegistered

import java.security.PrivilegedActionException; //導入依賴的package包/類
public boolean isRegistered(ObjectName name,
                            Subject delegationSubject) throws IOException {
    try {
        final Object params[] = new Object[] { name };
        return ((Boolean)
            doPrivilegedOperation(
              IS_REGISTERED,
              params,
              delegationSubject)).booleanValue();
    } catch (PrivilegedActionException pe) {
        Exception e = extractException(pe);
        if (e instanceof IOException)
            throw (IOException) e;
        throw newIOException("Got unexpected server exception: " + e, e);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:RMIConnectionImpl.java

示例4: doPrivilegedIOException

import java.security.PrivilegedActionException; //導入依賴的package包/類
public static <T> T doPrivilegedIOException(PrivilegedExceptionAction<T> operation) throws IOException {
    SpecialPermission.check();
    try {
        return AccessController.doPrivileged(operation);
    } catch (PrivilegedActionException e) {
        throw (IOException) e.getCause();
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:9,代碼來源:SocketAccess.java

示例5: doPrivilegedVoidException

import java.security.PrivilegedActionException; //導入依賴的package包/類
public static void doPrivilegedVoidException(StorageRunnable action) throws StorageException, URISyntaxException {
    SpecialPermission.check();
    try {
        AccessController.doPrivileged((PrivilegedExceptionAction<Void>) () -> {
            action.executeCouldThrow();
            return null;
        });
    } catch (PrivilegedActionException e) {
        Throwable cause = e.getCause();
        if (cause instanceof StorageException) {
            throw (StorageException) cause;
        } else {
            throw (URISyntaxException) cause;
        }
    }
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:17,代碼來源:SocketAccess.java

示例6: checkDirectory

import java.security.PrivilegedActionException; //導入依賴的package包/類
private static File checkDirectory(final String path, final ScriptEnvironment env, final boolean readOnly) throws IOException {
    try {
        return AccessController.doPrivileged(new PrivilegedExceptionAction<File>() {
            @Override
            public File run() throws IOException {
                final File dir = new File(path, getVersionDir(env)).getAbsoluteFile();
                if (readOnly) {
                    if (!dir.exists() || !dir.isDirectory()) {
                        throw new IOException("Not a directory: " + dir.getPath());
                    } else if (!dir.canRead()) {
                        throw new IOException("Directory not readable: " + dir.getPath());
                    }
                } else if (!dir.exists() && !dir.mkdirs()) {
                    throw new IOException("Could not create directory: " + dir.getPath());
                } else if (!dir.isDirectory()) {
                    throw new IOException("Not a directory: " + dir.getPath());
                } else if (!dir.canRead() || !dir.canWrite()) {
                    throw new IOException("Directory not readable or writable: " + dir.getPath());
                }
                return dir;
            }
        });
    } catch (final PrivilegedActionException e) {
        throw (IOException) e.getException();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:CodeStore.java

示例7: unload

import java.security.PrivilegedActionException; //導入依賴的package包/類
@Override
public void unload() throws IOException {
	if (SecurityUtil.isPackageProtectionEnabled()) {
		try {
			AccessController.doPrivileged(new PrivilegedDoUnload());
		} catch (PrivilegedActionException ex) {
			Exception exception = ex.getException();
			if (exception instanceof IOException) {
				throw (IOException) exception;
			}
			if (log.isDebugEnabled()) {
				log.debug("Unreported exception in unLoad()", exception);
			}
		}
	} else {
		doUnload();
	}
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:19,代碼來源:StandardManager.java

示例8: findResourcesInBundle

import java.security.PrivilegedActionException; //導入依賴的package包/類
private Enumeration<URL> findResourcesInBundle(final String resName, final Bundle inBundle) throws IOException {
    Enumeration<URL> resources = null;
    try {
        // Bundle.getResources requires privileges that the client may not
        // have but we need
        // use a doPriv so that only this bundle needs the privileges
        resources = AccessController.doPrivileged(new PrivilegedExceptionAction<Enumeration<URL>>() {
            @Override
            public Enumeration<URL> run() throws IOException {
                return inBundle.getResources(resName);
            }
        });
    } catch (PrivilegedActionException pae) {
        // thrownException can never be a RuntimeException, as that would escape the doPriv normally
        Exception thrownException = pae.getException();
        if (thrownException instanceof IOException) {
            throw (IOException)thrownException;
        } else {
            LOG.warn("Exception during findResourcesInBundle", pae);
        }
    }
    return resources;
}
 
開發者ID:apache,項目名稱:aries-jpa,代碼行數:24,代碼來源:TempBundleDelegatingClassLoader.java

示例9: createJobClassLoader

import java.security.PrivilegedActionException; //導入依賴的package包/類
private static ClassLoader createJobClassLoader(final String appClasspath,
    final String[] systemClasses) throws IOException {
  try {
    return AccessController.doPrivileged(
      new PrivilegedExceptionAction<ClassLoader>() {
        @Override
        public ClassLoader run() throws MalformedURLException {
          return new ApplicationClassLoader(appClasspath,
              MRApps.class.getClassLoader(), Arrays.asList(systemClasses));
        }
    });
  } catch (PrivilegedActionException e) {
    Throwable t = e.getCause();
    if (t instanceof MalformedURLException) {
      throw (MalformedURLException) t;
    }
    throw new IOException(e);
  }
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:20,代碼來源:MRApps.java

示例10: getClassLoaderFor

import java.security.PrivilegedActionException; //導入依賴的package包/類
private ClassLoader getClassLoaderFor(final ObjectName name)
    throws InstanceNotFoundException {
    try {
        return (ClassLoader)
            AccessController.doPrivileged(
                new PrivilegedExceptionAction<Object>() {
                    public Object run() throws InstanceNotFoundException {
                        return mbeanServer.getClassLoaderFor(name);
                    }
                },
                withPermissions(new MBeanPermission("*", "getClassLoaderFor"))
        );
    } catch (PrivilegedActionException pe) {
        throw (InstanceNotFoundException) extractException(pe);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:17,代碼來源:RMIConnectionImpl.java

示例11: forward

import java.security.PrivilegedActionException; //導入依賴的package包/類
/**
 * Forward this request and response to another resource for processing.
 * Any runtime exception, IOException, or ServletException thrown by the
 * called servlet will be propagated to the caller.
 *
 * @param request The servlet request to be forwarded
 * @param response The servlet response to be forwarded
 *
 * @exception IOException if an input/output error occurs
 * @exception ServletException if a servlet exception occurs
 */
@Override
public void forward(ServletRequest request, ServletResponse response)
    throws ServletException, IOException
{
    if (Globals.IS_SECURITY_ENABLED) {
        try {
            PrivilegedForward dp = new PrivilegedForward(request,response);
            AccessController.doPrivileged(dp);
        } catch (PrivilegedActionException pe) {
            Exception e = pe.getException();
            if (e instanceof ServletException)
                throw (ServletException) e;
            throw (IOException) e;
        }
    } else {
        doForward(request,response);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:30,代碼來源:ApplicationDispatcher.java

示例12: getMBeanCount

import java.security.PrivilegedActionException; //導入依賴的package包/類
public Integer getMBeanCount(Subject delegationSubject)
    throws IOException {
    try {
        final Object params[] = new Object[] { };

        if (logger.debugOn()) logger.debug("getMBeanCount",
             "connectionId=" + connectionId);

        return (Integer)
            doPrivilegedOperation(
              GET_MBEAN_COUNT,
              params,
              delegationSubject);
    } catch (PrivilegedActionException pe) {
        Exception e = extractException(pe);
        if (e instanceof IOException)
            throw (IOException) e;
        throw newIOException("Got unexpected server exception: " + e, e);
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:21,代碼來源:RMIConnectionImpl.java

示例13: UNIXProcess

import java.security.PrivilegedActionException; //導入依賴的package包/類
UNIXProcess(final byte[] prog,
            final byte[] argBlock, final int argc,
            final byte[] envBlock, final int envc,
            final byte[] dir,
            final int[] fds,
            final boolean redirectErrorStream)
        throws IOException {

    pid = forkAndExec(launchMechanism.ordinal() + 1,
                      helperpath,
                      prog,
                      argBlock, argc,
                      envBlock, envc,
                      dir,
                      fds,
                      redirectErrorStream);

    try {
        doPrivileged((PrivilegedExceptionAction<Void>) () -> {
            initStreams(fds);
            return null;
        });
    } catch (PrivilegedActionException ex) {
        throw (IOException) ex.getException();
    }
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:27,代碼來源:UNIXProcess.java

示例14: forward

import java.security.PrivilegedActionException; //導入依賴的package包/類
@Override
public void forward(final String relativeUrlPath) throws ServletException,
        IOException {
    if (SecurityUtil.isPackageProtectionEnabled()) {
        try {
            AccessController.doPrivileged(
                    new PrivilegedExceptionAction<Void>() {
                @Override
                public Void run() throws Exception {
                    doForward(relativeUrlPath);
                    return null;
                }
            });
        } catch (PrivilegedActionException e) {
            Exception ex = e.getException();
            if (ex instanceof IOException) {
                throw (IOException) ex;
            } else {
                throw (ServletException) ex;
            }
        }
    } else {
        doForward(relativeUrlPath);
    }
}
 
開發者ID:liaokailin,項目名稱:tomcat7,代碼行數:26,代碼來源:PageContextImpl.java

示例15: getContextClassLoader

import java.security.PrivilegedActionException; //導入依賴的package包/類
/**
 * Dynamically accesses the current context class loader. 
 * Includes a check for priviledges against java2 security 
 * to ensure no security related exceptions are encountered. 
 * Returns null if there is no per-thread context class loader.
 */
public static ClassLoader getContextClassLoader()
{
    if (System.getSecurityManager() != null) 
    {
        try 
        {
            ClassLoader cl = AccessController.doPrivileged(new PrivilegedExceptionAction<ClassLoader>()
                    {
                        public ClassLoader run() throws PrivilegedActionException
                        {
                            return Thread.currentThread().getContextClassLoader();
                        }
                    });
            return cl;
        }
        catch (PrivilegedActionException pae)
        {
            throw new FacesException(pae);
        }
    }
    else
    {
        return Thread.currentThread().getContextClassLoader();
    }
}
 
開發者ID:apache,項目名稱:myfaces-trinidad,代碼行數:32,代碼來源:ClassLoaderUtils.java


注:本文中的java.security.PrivilegedActionException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。