Java Code Examples for java.security.PrivilegedActionException

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 kernel_1, under directory /exo.kernel.commons/src/main/java/org/exoplatform/commons/utils/.

Source file: SecurityHelper.java

  21 
vote

/** 
 * Launches action in privileged mode. 
 * @param < E >
 * @param action
 * @return
 */
public static <E>E doPrivilegedExceptionAction(PrivilegedExceptionAction<E> action) throws PrivilegedActionException {
  if (System.getSecurityManager() != null) {
    return AccessController.doPrivileged(action);
  }
  try {
    return action.run();
  }
 catch (  RuntimeException e) {
    throw e;
  }
catch (  Exception e) {
    throw new PrivilegedActionException(e);
  }
}
 

Example 2

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

Source file: SecurityActions.java

  20 
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 3

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 4

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 5

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

Source file: SharedObjectMsg.java

  19 
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 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 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 16

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 17

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

Source file: MSXPPTDocumentReader.java

  19 
vote

public Properties getProperties(final InputStream is) throws IOException, DocumentReadException {
  final POIPropertiesReader reader=new POIPropertiesReader();
  try {
    SecurityHelper.doPrivilegedExceptionAction(new PrivilegedExceptionAction<Void>(){
      public Void run() throws Exception {
        reader.readDCProperties(new XSLFSlideShow(OPCPackage.open(is)));
        return null;
      }
    }
);
  }
 catch (  PrivilegedActionException pae) {
    Throwable cause=pae.getCause();
    if (cause instanceof InvalidFormatException) {
      throw new DocumentReadException("Can't read properties from OOXML document",cause);
    }
 else     if (cause instanceof OpenXML4JException) {
      throw new DocumentReadException("Can't read properties from OOXML document",cause);
    }
 else     if (cause instanceof XmlException) {
      throw new DocumentReadException("Can't read properties from OOXML document",cause);
    }
 else     if (cause instanceof RuntimeException) {
      throw (RuntimeException)cause;
    }
 else {
      throw new RuntimeException(cause);
    }
  }
  return reader.getProperties();
}
 

Example 18

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

Source file: DefaultWatchService.java

  19 
vote

/** 
 * Register the given file with this watch service
 */
@Override public WatchKey register(final Path path,WatchEvent.Kind<?>... events) throws IOException {
  if (events.length == 0)   throw new IllegalArgumentException("No events to register");
  final Set<WatchEvent.Kind<?>> eventSet=new HashSet<WatchEvent.Kind<?>>(events.length);
  for (  WatchEvent.Kind<?> event : events) {
    if (event == StandardWatchEventKinds.ENTRY_CREATE || event == StandardWatchEventKinds.ENTRY_MODIFY || event == StandardWatchEventKinds.ENTRY_DELETE) {
      eventSet.add(event);
      continue;
    }
    if (event == StandardWatchEventKinds.OVERFLOW) {
      if (events.length == 1)       throw new IllegalArgumentException("No events to register");
      continue;
    }
    if (event == null)     throw new NullPointerException("An element in event set is 'null'");
    throw new UnsupportedOperationException(event.name());
  }
  if (!isOpen())   throw new ClosedWatchServiceException();
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<DefaultWatchKey>(){
      @Override public DefaultWatchKey run() throws IOException {
        return doPrivilegedRegister(path,eventSet);
      }
    }
);
  }
 catch (  PrivilegedActionException pae) {
    Throwable cause=pae.getCause();
    if (cause != null && cause instanceof IOException)     throw (IOException)cause;
    throw new AssertionError(pae);
  }
}
 

Example 19

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 20

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 21

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 22

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 23

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

Source file: SecurityActions.java

  19 
vote

static Method getDeclaredMethod(final Class clazz,final String name,final Class[] types) throws NoSuchMethodException {
  if (System.getSecurityManager() == null)   return clazz.getDeclaredMethod(name,types);
 else {
    try {
      return (Method)AccessController.doPrivileged(new PrivilegedExceptionAction(){
        public Object run() throws Exception {
          return clazz.getDeclaredMethod(name,types);
        }
      }
);
    }
 catch (    PrivilegedActionException e) {
      if (e.getCause() instanceof NoSuchMethodException)       throw (NoSuchMethodException)e.getCause();
      throw new RuntimeException(e.getCause());
    }
  }
}
 

Example 24

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 25

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

Source file: DriverManagerAccessor.java

  19 
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 26

From project jboss-marshalling, under directory /river/src/main/java/org/jboss/marshalling/river/.

Source file: RiverMarshaller.java

  19 
vote

private RiverObjectOutputStream createObjectOutputStream() throws IOException {
  try {
    return AccessController.doPrivileged(createObjectOutputStreamAction);
  }
 catch (  PrivilegedActionException e) {
    throw (IOException)e.getCause();
  }
}
 

Example 27

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 28

From project jenkins-publish-over-ssh-plugin, under directory /src/test/java/jenkins/plugins/publish_over_ssh/jenkins/.

Source file: JenkinsTestHelper.java

  19 
vote

public CopyOnWriteList<BapSshHostConfiguration> getHostConfigurations() throws NoSuchFieldException, IllegalAccessException {
  final Field hostConfigurations=BapSshPublisherPluginDescriptor.class.getDeclaredField("hostConfigurations");
  try {
    return AccessController.doPrivileged(new GetMeTheHostConfigurations(hostConfigurations));
  }
 catch (  PrivilegedActionException pae) {
    throw (IllegalAccessException)pae.getException();
  }
}
 

Example 29

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 30

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 31

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 32

From project kevoree-library, under directory /javase/org.kevoree.library.javase.javaseOSGINode/src/main/scala/org/kevoree/library/defaultNodeTypes/osgi/deploy/runtime/shell/.

Source file: ShellActivator.java

  19 
vote

public synchronized void executeCommand(String commandLine,PrintStream out,PrintStream err) throws Exception {
  commandLine=commandLine.trim();
  String commandName=(commandLine.indexOf(' ') >= 0) ? commandLine.substring(0,commandLine.indexOf(' ')) : commandLine;
  Command command=getCommand(commandName);
  if (command != null) {
    if (System.getSecurityManager() != null) {
      try {
        AccessController.doPrivileged(new ExecutePrivileged(command,commandLine,out,err));
      }
 catch (      PrivilegedActionException ex) {
        throw ex.getException();
      }
    }
 else {
      try {
        command.execute(commandLine,out,err);
      }
 catch (      Throwable ex) {
        err.println("Unable to execute command: " + ex);
        ex.printStackTrace(err);
      }
    }
  }
 else {
    err.println("Command not found.");
  }
}
 

Example 33

From project litle-sdk-for-java, under directory /lib/xerces-2_11_0/samples/xni/.

Source file: SecuritySupport.java

  19 
vote

static FileInputStream getFileInputStream(final File file) throws FileNotFoundException {
  try {
    return (FileInputStream)AccessController.doPrivileged(new PrivilegedExceptionAction(){
      public Object run() throws FileNotFoundException {
        return new FileInputStream(file);
      }
    }
);
  }
 catch (  PrivilegedActionException e) {
    throw (FileNotFoundException)e.getException();
  }
}
 

Example 34

From project makegood, under directory /com.piece_framework.makegood.aspect/lib/javassist-3.11.0/src/main/javassist/util/proxy/.

Source file: SecurityActions.java

  19 
vote

static Method getDeclaredMethod(final Class clazz,final String name,final Class[] types) throws NoSuchMethodException {
  if (System.getSecurityManager() == null)   return clazz.getDeclaredMethod(name,types);
 else {
    try {
      return (Method)AccessController.doPrivileged(new PrivilegedExceptionAction(){
        public Object run() throws Exception {
          return clazz.getDeclaredMethod(name,types);
        }
      }
);
    }
 catch (    PrivilegedActionException e) {
      if (e.getCause() instanceof NoSuchMethodException)       throw (NoSuchMethodException)e.getCause();
      throw new RuntimeException(e.getCause());
    }
  }
}
 

Example 35

From project mina-sshd, under directory /sshd-core/src/main/java/org/apache/sshd/server/auth/gss/.

Source file: CredentialHelper.java

  19 
vote

public static GSSCredential creds(GSSManager mgr,String spn,String keytab) throws LoginException, GSSException {
  LoginContext lc=new LoginContext("x",null,null,new FixedLoginConfiguration(spn,keytab));
  lc.login();
  try {
    return (GSSCredential)Subject.doAs(lc.getSubject(),new G(mgr));
  }
 catch (  PrivilegedActionException e) {
    throw (GSSException)e.getCause();
  }
}
 

Example 36

From project narya, under directory /core/src/main/java/com/threerings/io/.

Source file: Streamer.java

  19 
vote

/** 
 * Obtains a  {@link Streamer} that can be used to read and write objects of the specifiedtarget class.  {@link Streamer} instances are shared among all {@link ObjectInputStream}s and {@link ObjectOutputStream}s.
 * @param target the class that is desired to be streamed. This should be the result of a callto  {@link #getStreamerClass} if the caller has an instance they wish to stream.
 * @throws IOException when a streamer is requested for an object that does not implement{@link Streamable} and is not one of the basic object types (@see {@link ObjectOutputStream}).
 */
public synchronized static Streamer getStreamer(final Class<?> target) throws IOException {
  maybeInit();
  Streamer stream=_streamers.get(target);
  if (stream == null) {
    Class<?> collClass=getCollectionClass(target);
    if (collClass != null) {
      stream=getStreamer(collClass);
    }
 else     if (!isStreamable(target)) {
      throw new IOException("Requested to stream invalid class '" + target.getName() + "'");
    }
 else {
      if (ObjectInputStream.STREAM_DEBUG) {
        log.info("Creating a streamer for '" + target.getName() + "'.");
      }
      try {
        stream=AccessController.doPrivileged(new PrivilegedExceptionAction<Streamer>(){
          public Streamer run() throws IOException {
            return create(target);
          }
        }
);
      }
 catch (      PrivilegedActionException pae) {
        throw (IOException)pae.getCause();
      }
    }
    _streamers.put(target,stream);
  }
  return stream;
}
 

Example 37

From project netty, under directory /common/src/main/java/io/netty/util/internal/.

Source file: DetectionUtil.java

  19 
vote

private static boolean hasUnsafeField(final Class<?> unsafeClass) throws PrivilegedActionException {
  return AccessController.doPrivileged(new PrivilegedExceptionAction<Boolean>(){
    @Override public Boolean run() throws Exception {
      unsafeClass.getDeclaredField("theUnsafe");
      return true;
    }
  }
);
}
 

Example 38

From project nuxeo-tycho-osgi, under directory /nuxeo-runtime/nuxeo-runtime/src/main/java/org/nuxeo/runtime/api/login/.

Source file: LoginComponent.java

  19 
vote

@Override public LoginContext loginAs(final String username) throws LoginException {
  try {
    return AccessController.doPrivileged(new PrivilegedExceptionAction<LoginContext>(){
      @Override public LoginContext run() throws LoginException {
        SecurityManager sm=System.getSecurityManager();
        if (sm != null) {
          sm.checkPermission(new SystemLoginPermission());
        }
        return systemLogin(username);
      }
    }
);
  }
 catch (  PrivilegedActionException e) {
    throw (LoginException)e.getException();
  }
}
 

Example 39

From project openwebbeans, under directory /webbeans-impl/src/main/java/org/apache/webbeans/util/.

Source file: ClassUtil.java

  19 
vote

public static Object newInstance(WebBeansContext webBeansContext,Class<?> clazz){
  try {
    if (System.getSecurityManager() != null) {
      return webBeansContext.getSecurityService().doPrivilegedObjectCreate(clazz);
    }
    return clazz.newInstance();
  }
 catch (  Exception e) {
    Throwable cause=e;
    if (e instanceof PrivilegedActionException) {
      cause=e.getCause();
    }
    String error="Error occurred while creating an instance of class : " + clazz.getName();
    logger.log(Level.SEVERE,error,cause);
    throw new WebBeansException(error,cause);
  }
}
 

Example 40

From project org.ops4j.pax.swissbox, under directory /pax-swissbox-converter/src/main/java/org/ops4j/pax/swissbox/converter/internal/.

Source file: Reflection.java

  19 
vote

public static <T>T newInstance(final AccessControlContext acc,final Class<T> clazz) throws Exception {
  if (acc == null) {
    return clazz.newInstance();
  }
 else {
    try {
      return AccessController.doPrivileged(new PrivilegedExceptionAction<T>(){
        public T run() throws Exception {
          return clazz.newInstance();
        }
      }
,acc);
    }
 catch (    PrivilegedActionException e) {
      throw e.getException();
    }
  }
}
 

Example 41

From project org.ops4j.pax.web, under directory /pax-web-jetty/src/main/java/org/ops4j/pax/web/service/jetty/internal/.

Source file: HttpServiceContext.java

  19 
vote

@Override public URL getResource(final String path){
  if (LOG.isDebugEnabled()) {
    LOG.debug("getting resource: [" + path + "]");
  }
  URL resource=null;
  try {
    resource=new URL(path);
    LOG.debug("resource: [" + path + "] is already a URL, returning");
    return resource;
  }
 catch (  MalformedURLException e) {
    LOG.debug("not a URL or invalid URL: [" + path + "], treating as a file path");
  }
  final String p;
  if (path != null && path.endsWith("/") && path.length() > 1) {
    p=path.substring(0,path.length() - 1);
  }
 else {
    p=path;
  }
  try {
    resource=AccessController.doPrivileged(new PrivilegedExceptionAction<URL>(){
      public URL run() throws Exception {
        return m_httpContext.getResource(p);
      }
    }
,m_accessControllerContext);
    if (LOG.isDebugEnabled()) {
      LOG.debug("found resource: " + resource);
    }
  }
 catch (  PrivilegedActionException e) {
    LOG.warn("Unauthorized access: " + e.getMessage());
  }
  return resource;
}