Java Code Examples for java.security.PrivilegedExceptionAction

The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.

Example 1

From project javassist, under directory /src/main/javassist/util/proxy/.

Source file: SerializedProxy.java

  21 
vote

/** 
 * Load class.
 * @param className the class name
 * @return loaded class
 * @throws ClassNotFoundException for any error
 */
protected Class loadClass(final String className) throws ClassNotFoundException {
  try {
    return (Class)AccessController.doPrivileged(new PrivilegedExceptionAction(){
      public Object run() throws Exception {
        ClassLoader cl=Thread.currentThread().getContextClassLoader();
        return Class.forName(className,true,cl);
      }
    }
);
  }
 catch (  PrivilegedActionException pae) {
    throw new RuntimeException("cannot load the class: " + className,pae.getException());
  }
}
 

Example 2

From project Android_1, under directory /org.eclipse.ecf.android/src/org/eclipse/ecf/android/.

Source file: SharedObjectMsg.java

  20 
vote

/** 
 * Find a Method instance on given class. This method searches for a method on the given class (first parameter), of the given name (second parameter), with arity defined by the third parameter. Calls searchForMethod to actually do the searching.
 * @param clazz the Class to look on
 * @param meth the method name to look for
 * @param args the arguments that will be passed to the method on the invoke call
 * @return Method instance found on given class. Null if none found.
 */
public static Method findMethod(final Class clazz,String meth,Class args[]){
  Method methods[]=null;
  try {
    methods=(Method[])AccessController.doPrivileged(new PrivilegedExceptionAction(){
      public Object run() throws Exception {
        return clazz.getDeclaredMethods();
      }
    }
);
  }
 catch (  PrivilegedActionException e) {
    return null;
  }
  return searchForMethod(methods,meth,args);
}
 

Example 3

From project jboss-jstl-api_spec, under directory /src/main/java/org/apache/taglibs/standard/tag/common/sql/.

Source file: DriverManagerAccessor.java

  20 
vote

/** 
 * Delegates to  {@link java.sql.DriverManager#getConnection(String,String,String)}. If this fails it attempts to load a class into the class loader cl and tries again.
 * @param jdbcURL  The JDBC url
 * @param userName The username
 * @param password The password
 * @return A database connection
 */
public static Connection getConnection(final String jdbcURL,final String userName,final String password) throws SQLException {
  try {
    return getRealConnection(jdbcURL,userName,password);
  }
 catch (  final SQLException sqlException) {
    try {
      return (Connection)AccessController.doPrivileged(new PrivilegedExceptionAction(){
        public Object run() throws Exception {
          final ClassLoader cl=Thread.currentThread().getContextClassLoader();
          if (cl != null && cl != DriverManagerAccessor.class.getClassLoader()) {
            final Class<?> definedClass=DriverManagerAccessorSupport.define(cl);
            final Method method=definedClass.getDeclaredMethod("getRealConnection",String.class,String.class,String.class);
            method.setAccessible(true);
            return method.invoke(null,jdbcURL,userName,password);
          }
 else {
            throw sqlException;
          }
        }
      }
);
    }
 catch (    PrivilegedActionException e) {
      throw sqlException;
    }
  }
}
 

Example 4

From project alfredo, under directory /alfredo/src/main/java/com/cloudera/alfredo/server/.

Source file: KerberosAuthenticationHandler.java

  19 
vote

/** 
 * Initializes the authentication handler instance. <p/> It creates a Kerberos context using the principal and keytab specified in the configuration. <p/> This method is invoked by the  {@link AuthenticationFilter#init} method.
 * @param config configuration properties to initialize the handler.
 * @throws ServletException thrown if the handler could not be initialized.
 */
@Override public void init(Properties config) throws ServletException {
  try {
    principal=config.getProperty(PRINCIPAL,principal);
    if (principal == null || principal.trim().length() == 0) {
      throw new ServletException("Principal not defined in configuration");
    }
    keytab=config.getProperty(KEYTAB,keytab);
    if (keytab == null || keytab.trim().length() == 0) {
      throw new ServletException("Keytab not defined in configuration");
    }
    if (!new File(keytab).exists()) {
      throw new ServletException("Keytab does not exist: " + keytab);
    }
    Set<Principal> principals=new HashSet<Principal>();
    principals.add(new KerberosPrincipal(principal));
    Subject subject=new Subject(false,principals,new HashSet<Object>(),new HashSet<Object>());
    KerberosConfiguration kerberosConfiguration=new KerberosConfiguration(keytab,principal);
    loginContext=new LoginContext("",subject,null,kerberosConfiguration);
    loginContext.login();
    Subject serverSubject=loginContext.getSubject();
    try {
      gssManager=Subject.doAs(serverSubject,new PrivilegedExceptionAction<GSSManager>(){
        @Override public GSSManager run() throws Exception {
          return GSSManager.getInstance();
        }
      }
);
    }
 catch (    PrivilegedActionException ex) {
      throw ex.getException();
    }
    LOG.info("Initialized, principal [{}] from keytab [{}]",principal,keytab);
  }
 catch (  Exception ex) {
    throw new ServletException(ex);
  }
}
 

Example 5

From project android-client_1, under directory /src/org/apache/harmony/javax/security/auth/login/.

Source file: LoginContext.java

  19 
vote

/** 
 * Warning: calling the method more than once may result in undefined behaviour if logout() method is not invoked before.
 */
public void login() throws LoginException {
  PrivilegedExceptionAction<Void> action=new PrivilegedExceptionAction<Void>(){
    public Void run() throws LoginException {
      loginImpl();
      return null;
    }
  }
;
  try {
    if (userProvidedConfig) {
      AccessController.doPrivileged(action,userContext);
    }
 else {
      AccessController.doPrivileged(action);
    }
  }
 catch (  PrivilegedActionException ex) {
    throw (LoginException)ex.getException();
  }
}
 

Example 6

From project arquillian-container-openshift, under directory /openshift-express/src/main/java/org/jboss/arquillian/container/openshift/express/auth/.

Source file: SecurityActions.java

  19 
vote

static String getProperty(final String key){
  try {
    String value=AccessController.doPrivileged(new PrivilegedExceptionAction<String>(){
      public String run(){
        return System.getProperty(key);
      }
    }
);
    return value;
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof SecurityException) {
      throw (SecurityException)t;
    }
    if (t instanceof NullPointerException) {
      throw (NullPointerException)t;
    }
 else     if (t instanceof IllegalArgumentException) {
      throw (IllegalArgumentException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 7

From project arquillian-core, under directory /container/impl-base/src/main/java/org/jboss/arquillian/container/impl/client/container/.

Source file: SecurityActions.java

  19 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
static <T>Constructor<T> getConstructor(final Class<T> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<T>>(){
      public Constructor<T> run() throws NoSuchMethodException {
        return clazz.getDeclaredConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 8

From project arquillian-extension-android, under directory /android-configuration/src/main/java/org/jboss/arquillian/android/configuration/.

Source file: SecurityActions.java

  19 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 9

From project arquillian-extension-drone, under directory /drone-configuration/src/main/java/org/jboss/arquillian/drone/configuration/.

Source file: SecurityActions.java

  19 
vote

static Map<String,String> getProperties(final String prefix){
  try {
    Map<String,String> value=AccessController.doPrivileged(new PrivilegedExceptionAction<Map<String,String>>(){
      public Map<String,String> run(){
        Properties props=System.getProperties();
        Map<String,String> subset=new LinkedHashMap<String,String>();
        for (        Map.Entry<Object,Object> entry : props.entrySet()) {
          String name=entry.getKey().toString();
          if (name.startsWith(prefix)) {
            subset.put(name,entry.getValue().toString());
          }
        }
        return subset;
      }
    }
);
    return value;
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof SecurityException) {
      throw (SecurityException)t;
    }
    if (t instanceof NullPointerException) {
      throw (NullPointerException)t;
    }
 else     if (t instanceof IllegalArgumentException) {
      throw (IllegalArgumentException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 10

From project arquillian-extension-persistence, under directory /impl/src/main/java/org/jboss/arquillian/persistence/core/configuration/.

Source file: SecurityActions.java

  19 
vote

static String getProperty(final String key){
  try {
    String value=AccessController.doPrivileged(new PrivilegedExceptionAction<String>(){
      public String run(){
        return System.getProperty(key);
      }
    }
);
    return value;
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof SecurityException) {
      throw (SecurityException)t;
    }
    if (t instanceof NullPointerException) {
      throw (NullPointerException)t;
    }
 else     if (t instanceof IllegalArgumentException) {
      throw (IllegalArgumentException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 11

From project arquillian-extension-seam2, under directory /src/main/java/org/jboss/arquillian/seam2/configuration/.

Source file: SecurityActions.java

  19 
vote

static String getProperty(final String key){
  try {
    String value=AccessController.doPrivileged(new PrivilegedExceptionAction<String>(){
      public String run(){
        return System.getProperty(key);
      }
    }
);
    return value;
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof SecurityException) {
      throw (SecurityException)t;
    }
    if (t instanceof NullPointerException) {
      throw (NullPointerException)t;
    }
 else     if (t instanceof IllegalArgumentException) {
      throw (IllegalArgumentException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 12

From project arquillian-extension-warp, under directory /impl/src/main/java/org/jboss/arquillian/warp/impl/server/test/.

Source file: SecurityActions.java

  19 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 13

From project arquillian-graphene, under directory /graphene-webdriver/graphene-webdriver-impl/src/main/java/org/jboss/arquillian/graphene/configuration/.

Source file: SecurityActions.java

  19 
vote

static Map<String,String> getProperties(final String prefix){
  try {
    Map<String,String> value=AccessController.doPrivileged(new PrivilegedExceptionAction<Map<String,String>>(){
      public Map<String,String> run(){
        Properties props=System.getProperties();
        Map<String,String> subset=new LinkedHashMap<String,String>();
        for (        Map.Entry<Object,Object> entry : props.entrySet()) {
          String name=entry.getKey().toString();
          if (name.startsWith(prefix)) {
            subset.put(name,entry.getValue().toString());
          }
        }
        return subset;
      }
    }
);
    return value;
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof SecurityException) {
      throw (SecurityException)t;
    }
    if (t instanceof NullPointerException) {
      throw (NullPointerException)t;
    }
 else     if (t instanceof IllegalArgumentException) {
      throw (IllegalArgumentException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 14

From project arquillian-showcase, under directory /extensions/autodiscover/src/main/java/org/jboss/arquillian/showcase/extension/autodiscover/.

Source file: ReflectionHelper.java

  19 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
public static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 15

From project arquillian_deprecated, under directory /extensions/drone/src/main/java/org/jboss/arquillian/drone/configuration/.

Source file: SecurityActions.java

  19 
vote

static String getProperty(final String key){
  try {
    String value=AccessController.doPrivileged(new PrivilegedExceptionAction<String>(){
      public String run(){
        return System.getProperty(key);
      }
    }
);
    return value;
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof SecurityException) {
      throw (SecurityException)t;
    }
    if (t instanceof NullPointerException) {
      throw (NullPointerException)t;
    }
 else     if (t instanceof IllegalArgumentException) {
      throw (IllegalArgumentException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 16

From project AsmackService, under directory /src/org/apache/harmony/javax/security/auth/login/.

Source file: LoginContext.java

  19 
vote

/** 
 * Warning: calling the method more than once may result in undefined behaviour if logout() method is not invoked before.
 */
public void login() throws LoginException {
  PrivilegedExceptionAction<Void> action=new PrivilegedExceptionAction<Void>(){
    public Void run() throws LoginException {
      loginImpl();
      return null;
    }
  }
;
  try {
    if (userProvidedConfig) {
      AccessController.doPrivileged(action,userContext);
    }
 else {
      AccessController.doPrivileged(action);
    }
  }
 catch (  PrivilegedActionException ex) {
    throw (LoginException)ex.getException();
  }
}
 

Example 17

From project blueprint-namespaces, under directory /blueprint/blueprint-core/src/main/java/org/apache/aries/blueprint/container/.

Source file: BlueprintContainerImpl.java

  19 
vote

public Class loadClass(final String name) throws ClassNotFoundException {
  if (accessControlContext == null) {
    return bundleContext.getBundle().loadClass(name);
  }
 else {
    try {
      return AccessController.doPrivileged(new PrivilegedExceptionAction<Class>(){
        public Class run() throws Exception {
          return bundleContext.getBundle().loadClass(name);
        }
      }
,accessControlContext);
    }
 catch (    PrivilegedActionException e) {
      Exception cause=e.getException();
      if (cause instanceof ClassNotFoundException) {
        throw (ClassNotFoundException)cause;
      }
      throw new IllegalStateException("Unexpected checked exception",cause);
    }
  }
}
 

Example 18

From project ceylon-runtime, under directory /api/src/main/java/ceylon/modules/api/runtime/.

Source file: SecurityActions.java

  19 
vote

/** 
 * Get module.
 * @param moduleClass the module class
 * @return module instance
 * @throws Exception for any error
 */
static Module getModule(final Class<?> moduleClass) throws Exception {
  final SecurityManager sm=System.getSecurityManager();
  if (sm != null) {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Module>(){
      public Module run() throws Exception {
        return getModuleInternal(moduleClass);
      }
    }
);
  }
 else {
    return getModuleInternal(moduleClass);
  }
}
 

Example 19

From project conversation, under directory /spi/src/main/java/org/jboss/seam/conversation/spi/.

Source file: SeamConversationContextFactory.java

  19 
vote

/** 
 * Match current Seam conversation context instance with store type.
 * @param scc       current Seam conversation context
 * @param storeType the store type
 * @return true if scc can be used together with store type, false otherwise
 */
private static boolean match(SeamConversationContext scc,final Class<?> storeType){
  try {
    Class<?> current=scc.getClass();
    while (current != Object.class) {
      final Class<?> clazz=current;
      Method doAssociate=AccessController.doPrivileged(new PrivilegedExceptionAction<Method>(){
        public Method run() throws Exception {
          try {
            return clazz.getDeclaredMethod("doAssociate",storeType);
          }
 catch (          NoSuchMethodException nsme) {
            return null;
          }
        }
      }
);
      if (doAssociate != null)       return true;
      current=current.getSuperclass();
    }
  }
 catch (  Throwable ignored) {
  }
  return false;
}
 

Example 20

From project core_5, under directory /exo.core.component.database/src/main/java/org/exoplatform/services/database/creator/.

Source file: DBCreator.java

  19 
vote

/** 
 * Open connection to the DB.
 * @param connectionProperties connection properties
 * @return connection
 * @throws DBCreatorException if can't establish connection to DB
 */
private Connection openConnection() throws DBCreatorException {
  Connection conn=null;
  try {
    ClassLoading.forName(connectionProperties.get(DRIVER_NAME),this);
    conn=SecurityHelper.doPrivilegedSQLExceptionAction(new PrivilegedExceptionAction<Connection>(){
      public Connection run() throws Exception {
        return DriverManager.getConnection(serverUrl,connectionProperties.get(USERNAME),connectionProperties.get(PASSWORD));
      }
    }
);
    return conn;
  }
 catch (  SQLException e) {
    throw new DBCreatorException("Can't establish the JDBC connection to database " + serverUrl,e);
  }
catch (  ClassNotFoundException e) {
    throw new DBCreatorException("Can't load the JDBC driver " + connectionProperties.get(DRIVER_NAME),e);
  }
}
 

Example 21

From project cxf-dosgi, under directory /dsw/cxf-dsw/src/main/java/org/apache/cxf/dosgi/dsw/handlers/.

Source file: ServiceInvocationHandler.java

  19 
vote

public Object invoke(Object proxy,final Method m,Object[] params) throws Throwable {
  if (OBJECT_METHODS.contains(m)) {
    if (m.getName().equals("equals")) {
      params=new Object[]{Proxy.getInvocationHandler(params[0])};
    }
    return m.invoke(this,params);
  }
  ClassLoader oldCl=Thread.currentThread().getContextClassLoader();
  try {
    Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
    final Object[] paramsFinal=params;
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
      public Object run() throws Exception {
        return m.invoke(serviceObject,paramsFinal);
      }
    }
);
  }
 catch (  Throwable ex) {
    Throwable theCause=ex.getCause() == null ? ex : ex.getCause();
    Throwable theCauseCause=theCause.getCause() == null ? theCause : theCause.getCause();
    List<Class<?>> excTypes=exceptionsMap.get(m);
    if (excTypes != null) {
      for (      Class<?> type : excTypes) {
        if (type.isAssignableFrom(theCause.getClass())) {
          throw theCause;
        }
        if (type.isAssignableFrom(theCauseCause.getClass())) {
          throw theCauseCause;
        }
      }
    }
    throw new ServiceException(REMOTE_EXCEPTION_TYPE,theCause);
  }
 finally {
    Thread.currentThread().setContextClassLoader(oldCl);
  }
}
 

Example 22

From project dolphin, under directory /texcel/compile/sun/misc/.

Source file: URLClassPath.java

  19 
vote

@SuppressWarnings({"unchecked","rawtypes"}) private Loader getLoader(final URL url) throws IOException {
  try {
    return (Loader)java.security.AccessController.doPrivileged(new java.security.PrivilegedExceptionAction(){
      public Object run() throws IOException {
        String file=url.getFile();
        if (file != null && file.endsWith("/")) {
          if ("file".equals(url.getProtocol())) {
            return new FileLoader(url);
          }
 else {
            return new Loader(url);
          }
        }
 else {
          return new JarLoader(url,jarHandler,lmap);
        }
      }
    }
);
  }
 catch (  java.security.PrivilegedActionException pae) {
    throw (IOException)pae.getException();
  }
}
 

Example 23

From project dragon, under directory /hadoop-dragon-core/src/main/java/org/apache/hadoop/realtime/child/.

Source file: ChildServiceDelegate.java

  19 
vote

private DragonChildProtocol getProxy() throws YarnException {
  if (proxy != null) {
    return proxy;
  }
  try {
    Token<JobTokenIdentifier> jt=loadCredentials(conf,amAddress);
    UserGroupInformation taskOwner=UserGroupInformation.createRemoteUser(jobId);
    taskOwner.addToken(jt);
    if (LOG.isDebugEnabled()) {
      LOG.debug("Connecting to " + amAddress);
    }
    proxy=taskOwner.doAs(new PrivilegedExceptionAction<DragonChildProtocol>(){
      @Override public DragonChildProtocol run() throws IOException {
        return instantiateAMProxy(amAddress);
      }
    }
);
    return proxy;
  }
 catch (  IOException e) {
    LOG.info("Could not connect to " + amAddress.toString(),e);
  }
catch (  InterruptedException e) {
    LOG.warn("getProxy() call interruped",e);
    throw new YarnException(e);
  }
  return null;
}
 

Example 24

From project flume, under directory /flume-ng-sinks/flume-hdfs-sink/src/main/java/org/apache/flume/sink/hdfs/.

Source file: BucketWriter.java

  19 
vote

/** 
 * Allow methods to act as another user (typically used for HDFS Kerberos)
 * @param < T >
 * @param action
 * @return
 * @throws IOException
 * @throws InterruptedException
 */
private <T>T runPrivileged(final PrivilegedExceptionAction<T> action) throws IOException, InterruptedException {
  if (user != null) {
    return user.doAs(action);
  }
 else {
    try {
      return action.run();
    }
 catch (    IOException ex) {
      throw ex;
    }
catch (    InterruptedException ex) {
      throw ex;
    }
catch (    RuntimeException ex) {
      throw ex;
    }
catch (    Exception ex) {
      throw new RuntimeException("Unexpected exception.",ex);
    }
  }
}
 

Example 25

From project Gemini-Blueprint, under directory /core/src/main/java/org/eclipse/gemini/blueprint/context/support/internal/classloader/.

Source file: ChainedClassLoader.java

  19 
vote

public Class<?> loadClass(final String name) throws ClassNotFoundException {
  if (System.getSecurityManager() != null) {
    try {
      return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<?>>(){
        public Class<?> run() throws Exception {
          return doLoadClass(name);
        }
      }
);
    }
 catch (    PrivilegedActionException pae) {
      throw (ClassNotFoundException)pae.getException();
    }
  }
 else {
    return doLoadClass(name);
  }
}
 

Example 26

From project gemini.web.gemini-web-container, under directory /org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/loading/.

Source file: ChainedClassLoader.java

  19 
vote

@Override public Enumeration<URL> getResources(final String name) throws IOException {
  if (System.getSecurityManager() != null) {
    try {
      return AccessController.doPrivileged(new PrivilegedExceptionAction<Enumeration<URL>>(){
        @Override public Enumeration<URL> run() throws Exception {
          return doGetResources(name);
        }
      }
);
    }
 catch (    PrivilegedActionException e) {
      Exception exception=e.getException();
      if (exception instanceof RuntimeException) {
        throw (RuntimeException)exception;
      }
 else       if (exception instanceof IOException) {
        throw (IOException)exception;
      }
 else {
        throw new IllegalStateException("Unexpected Exception from privileged action.",exception);
      }
    }
  }
 else {
    return doGetResources(name);
  }
}
 

Example 27

From project geronimo-jaspi, under directory /geronimo-jaspi/src/main/java/org/apache/geronimo/components/jaspi/impl/.

Source file: ConfigProviderImpl.java

  19 
vote

public static AuthConfigProvider newConfigProvider(final AuthConfigFactory authConfigFactory,final ConfigProviderType configProviderType){
  AuthConfigProvider provider;
  if (configProviderType.getClassName() == null) {
    provider=new ConfigProviderImpl(configProviderType.getClientAuthConfig(),configProviderType.getServerAuthConfig());
  }
 else {
    try {
      provider=java.security.AccessController.doPrivileged(new PrivilegedExceptionAction<AuthConfigProvider>(){
        public AuthConfigProvider run() throws ClassNotFoundException, SecurityException, NoSuchMethodException, IllegalArgumentException, InstantiationException, IllegalAccessException, InvocationTargetException {
          Class<? extends AuthConfigProvider> cl=ProviderLocator.loadClass(configProviderType.getClassName(),getClass(),Thread.currentThread().getContextClassLoader()).asSubclass(AuthConfigProvider.class);
          Constructor<? extends AuthConfigProvider> cnst=cl.getConstructor(Map.class,AuthConfigFactory.class);
          return cnst.newInstance(configProviderType.getProperties(),authConfigFactory);
        }
      }
);
    }
 catch (    PrivilegedActionException e) {
      Exception inner=e.getException();
      if (inner instanceof InstantiationException) {
        throw new SecurityException("AuthConfigFactory error:" + inner.getCause().getMessage(),inner.getCause());
      }
 else {
        throw new SecurityException("AuthConfigFactory error: " + inner,inner);
      }
    }
catch (    Exception e) {
      throw new SecurityException("AuthConfigFactory error: " + e,e);
    }
  }
  return provider;
}
 

Example 28

From project ha-jdbc, under directory /src/main/java/net/sf/hajdbc/sync/.

Source file: DumpRestoreSynchronizationStrategy.java

  19 
vote

private void startProcess(final ProcessBuilder processBuilder) throws Exception {
  PrivilegedExceptionAction<Process> action=new PrivilegedExceptionAction<Process>(){
    @Override public Process run() throws Exception {
      return processBuilder.start();
    }
  }
;
  Process process=Security.run(action);
  try {
    int status=process.waitFor();
    if (status != 0) {
      StringBuilder builder=new StringBuilder();
      BufferedReader reader=new BufferedReader(new InputStreamReader(process.getErrorStream()));
      String line=reader.readLine();
      while (line != null) {
        builder.append(line).append(Strings.NEW_LINE);
        line=reader.readLine();
      }
      throw new Exception(builder.toString());
    }
  }
 catch (  InterruptedException e) {
    Thread.currentThread().interrupt();
    throw new Exception(processBuilder.toString(),e);
  }
}
 

Example 29

From project hcatalog, under directory /webhcat/svr/src/main/java/org/apache/hcatalog/templeton/.

Source file: LauncherDelegator.java

  19 
vote

private String queueAsUser(UserGroupInformation ugi,final List<String> args) throws IOException, InterruptedException {
  String id=ugi.doAs(new PrivilegedExceptionAction<String>(){
    public String run() throws Exception {
      String[] array=new String[args.size()];
      TempletonControllerJob ctrl=new TempletonControllerJob();
      ToolRunner.run(ctrl,args.toArray(array));
      return ctrl.getSubmittedId();
    }
  }
);
  return id;
}
 

Example 30

From project hoop, under directory /hoop-client/src/test/java/com/cloudera/hoop/client/fs/.

Source file: TestHoopFileSystem.java

  19 
vote

@Test(dataProvider="Operations") @TestDir @TestServlet @TestHadoop public void testOperationDoAs(final Operation op) throws Exception {
  createHoopServer();
  UserGroupInformation ugi=UserGroupInformation.createProxyUser(getHadoopUsers()[0],UserGroupInformation.getCurrentUser());
  ugi.doAs(new PrivilegedExceptionAction<Void>(){
    @Override public Void run() throws Exception {
      operation(op);
      return null;
    }
  }
);
}
 

Example 31

From project infinispan-arquillian-container, under directory /infinispan-impl/src/main/java/org/infinispan/arquillian/core/.

Source file: SecurityActions.java

  19 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 32

From project Ivory, under directory /test-util/src/main/java/org/apache/ivory/cluster/util/.

Source file: EmbeddedCluster.java

  19 
vote

public static EmbeddedCluster newCluster(final String name,final boolean withMR,final String user) throws Exception {
  UserGroupInformation hdfsUser=UserGroupInformation.createRemoteUser(user);
  return hdfsUser.doAs(new PrivilegedExceptionAction<EmbeddedCluster>(){
    @Override public EmbeddedCluster run() throws Exception {
      return createClusterAsUser(name,withMR);
    }
  }
);
}
 

Example 33

From project jboss-classfilewriter, under directory /src/main/java/org/jboss/classfilewriter/annotations/.

Source file: AnnotationBuilder.java

  19 
vote

public static ClassAnnotation createAnnotation(ConstPool constPool,final Annotation annotation){
  Class<? extends Annotation> annotationType=annotation.annotationType();
  List<AnnotationValue> values=new ArrayList<AnnotationValue>();
  try {
    for (    final Method m : annotationType.getDeclaredMethods()) {
      Object value=AccessController.doPrivileged(new PrivilegedExceptionAction<Object>(){
        @Override public Object run() throws InvocationTargetException, IllegalAccessException {
          m.setAccessible(true);
          return m.invoke(annotation);
        }
      }
);
      values.add(createValue(constPool,m.getName(),value));
    }
  }
 catch (  IllegalArgumentException e) {
    throw new RuntimeException(e);
  }
catch (  PrivilegedActionException e) {
    throw new RuntimeException(e);
  }
  return new ClassAnnotation(constPool,annotationType.getName(),values);
}
 

Example 34

From project jboss-rmi-api_spec, under directory /src/main/java/org/jboss/com/sun/corba/se/impl/encoding/.

Source file: CDRInputStream_1_0.java

  19 
vote

private Object readBoxedIDLEntity(Class<?> clazz,String codebase){
  Class<?> cls=null;
  try {
    ClassLoader clazzLoader=(clazz == null ? null : clazz.getClassLoader());
    cls=Utility.loadClassForClass(clazz.getName() + "Helper",codebase,clazzLoader,clazz,clazzLoader);
    final Class<?> helperClass=cls;
    final Class<?> argTypes[]={org.omg.CORBA.portable.InputStream.class};
    Method readMethod=null;
    try {
      readMethod=AccessController.doPrivileged(new PrivilegedExceptionAction<Method>(){
        public Method run() throws NoSuchMethodException {
          return helperClass.getDeclaredMethod(kReadMethod,argTypes);
        }
      }
);
    }
 catch (    PrivilegedActionException pae) {
      throw (NoSuchMethodException)pae.getException();
    }
    Object args[]={parent};
    return readMethod.invoke(null,args);
  }
 catch (  ClassNotFoundException cnfe) {
    throw wrapper.couldNotInvokeHelperReadMethod(cnfe,cls);
  }
catch (  NoSuchMethodException nsme) {
    throw wrapper.couldNotInvokeHelperReadMethod(nsme,cls);
  }
catch (  IllegalAccessException iae) {
    throw wrapper.couldNotInvokeHelperReadMethod(iae,cls);
  }
catch (  InvocationTargetException ite) {
    throw wrapper.couldNotInvokeHelperReadMethod(ite,cls);
  }
}
 

Example 35

From project JGlobus, under directory /ssl-proxies/src/main/java/org/globus/gsi/gssapi/jaas/.

Source file: GlobusSubject.java

  19 
vote

public Object runAs(Subject subject,PrivilegedExceptionAction action) throws PrivilegedActionException {
  subjects.push(subject);
  try {
    return Subject.doAs(subject,action);
  }
  finally {
    subjects.pop();
  }
}
 

Example 36

From project jsfunit, under directory /jboss-jsfunit-arquillian/src/main/java/org/jboss/jsfunit/arquillian/container/.

Source file: SecurityActions.java

  19 
vote

/** 
 * Obtains the Constructor specified from the given Class and argument types
 * @param clazz
 * @param argumentTypes
 * @return
 * @throws NoSuchMethodException
 */
static Constructor<?> getConstructor(final Class<?> clazz,final Class<?>... argumentTypes) throws NoSuchMethodException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<Constructor<?>>(){
      public Constructor<?> run() throws NoSuchMethodException {
        return clazz.getConstructor(argumentTypes);
      }
    }
);
  }
 catch (  final PrivilegedActionException pae) {
    final Throwable t=pae.getCause();
    if (t instanceof NoSuchMethodException) {
      throw (NoSuchMethodException)t;
    }
 else {
      try {
        throw (RuntimeException)t;
      }
 catch (      final ClassCastException cce) {
        throw new RuntimeException("Obtained unchecked Exception; this code should never be reached",t);
      }
    }
  }
}
 

Example 37

From project karaf, under directory /webconsole/console/src/main/java/org/apache/felix/webconsole/internal/.

Source file: KarafOsgiManager.java

  19 
vote

@Override public void service(final ServletRequest req,final ServletResponse res) throws ServletException, IOException {
  Object obj=req.getAttribute(SUBJECT_RUN_AS);
  if (obj instanceof Subject) {
    try {
      Subject.doAs((Subject)obj,new PrivilegedExceptionAction<Object>(){
        public Object run() throws Exception {
          doService(req,res);
          return null;
        }
      }
);
    }
 catch (    PrivilegedActionException e) {
      Exception cause=e.getException();
      if (cause instanceof ServletException) {
        throw (ServletException)cause;
      }
      if (cause instanceof IOException) {
        throw (IOException)cause;
      }
      throw new ServletException(cause);
    }
  }
 else {
    super.service(req,res);
  }
}
 

Example 38

From project kernel_1, under directory /exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/.

Source file: MimeTypeResolver.java

  19 
vote

public MimeTypeResolver(){
  try {
    SecurityHelper.doPrivilegedIOExceptionAction(new PrivilegedExceptionAction<Void>(){
      public Void run() throws Exception {
        Scanner scanner=null;
        String mimeTypeProperties=System.getProperty("org.exoplatform.mimetypes");
        if (mimeTypeProperties != null) {
          InputStream stream=Thread.currentThread().getContextClassLoader().getResourceAsStream(mimeTypeProperties);
          if (stream != null) {
            scanner=new Scanner(stream,"ISO-8859-1");
          }
        }
        if (scanner == null) {
          scanner=new Scanner(getClass().getResourceAsStream("mimetypes.properties"),"ISO-8859-1");
        }
        try {
          while (scanner.hasNextLine()) {
            processLine(scanner.nextLine());
          }
        }
  finally {
          scanner.close();
        }
        return null;
      }
    }
);
  }
 catch (  IOException e) {
    throw new InternalError("Unable to load mimetypes: " + e.toString());
  }
}