当前位置: 首页>>代码示例>>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;未经允许,请勿转载。