Search in sources :

Example 91 with PrivilegedExceptionAction

use of java.security.PrivilegedExceptionAction in project derby by apache.

the class StorageFactoryService method recreateServiceRoot.

/*
	**Recreates service root if required depending on which of the following
	**attribute is specified on the conection URL:
	** Attribute.CREATE_FROM (Create database from backup if it does not exist):
	** When a database not exist, the service(database) root is created
	** and the PersistentService.PROPERTIES_NAME (service.properties) file
	** is restored from the backup.
	** Attribute.RESTORE_FROM (Delete the whole database if it exists and then restore
	** it from backup)
	** Existing database root  is deleted and the new the service(database) root is created.
	** PersistentService.PROPERTIES_NAME (service.properties) file is restored from the backup.
	** Attribute.ROLL_FORWARD_RECOVERY_FROM:(Perform Rollforward Recovery;
	** except for the log directory everthing else is replced  by the copy  from
	** backup. log files in the backup are copied to the existing online log
	** directory.):
	** When a database not exist, the service(database) root is created.
	** PersistentService.PROPERTIES_NAME (service.properties) file is deleted
	** from the service dir and  recreated with the properties from backup.
	*/
protected String recreateServiceRoot(final String serviceName, Properties properties) throws StandardException {
    // if there are no propertues then nothing to do in this routine
    if (properties == null) {
        return null;
    }
    // location where backup copy of service properties available
    String restoreFrom;
    boolean createRoot = false;
    boolean deleteExistingRoot = false;
    // check if user wants to create a database from a backup copy
    restoreFrom = properties.getProperty(Attribute.CREATE_FROM);
    if (restoreFrom != null) {
        // create root dicretory if it  does not exist.
        createRoot = true;
        deleteExistingRoot = false;
    } else {
        // check if user requested a complete restore(version recovery) from backup
        restoreFrom = properties.getProperty(Attribute.RESTORE_FROM);
        // create root dir if it does not exists and  if there exists one already delete and recreate
        if (restoreFrom != null) {
            createRoot = true;
            deleteExistingRoot = true;
        } else {
            // check if user has requested roll forward recovery using a backup
            restoreFrom = properties.getProperty(Attribute.ROLL_FORWARD_RECOVERY_FROM);
            if (restoreFrom != null) {
                // failed and user is trying to restore it some other device.
                try {
                    if (AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

                        public Object run() throws IOException, StandardException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
                            StorageFactory storageFactory = privGetStorageFactoryInstance(true, serviceName, null, null);
                            try {
                                StorageFile serviceDirectory = storageFactory.newStorageFile(null);
                                return serviceDirectory.exists() ? this : null;
                            } finally {
                                storageFactory.shutdown();
                            }
                        }
                    }) == null) {
                        createRoot = true;
                        deleteExistingRoot = false;
                    }
                } catch (PrivilegedActionException pae) {
                    throw Monitor.exceptionStartingModule((IOException) pae.getException());
                }
            }
        }
    }
    // restore the service properties from backup
    if (restoreFrom != null) {
        // First make sure backup service directory exists in the specified path
        File backupRoot = new File(restoreFrom);
        if (fileExists(backupRoot)) {
            // First make sure backup have service.properties
            File bserviceProp = new File(restoreFrom, PersistentService.PROPERTIES_NAME);
            if (fileExists(bserviceProp)) {
                // create service root if required
                if (createRoot)
                    createServiceRoot(serviceName, deleteExistingRoot);
                try {
                    AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {

                        public Object run() throws IOException, StandardException, InstantiationException, IllegalAccessException, NoSuchMethodException, InvocationTargetException {
                            WritableStorageFactory storageFactory = (WritableStorageFactory) privGetStorageFactoryInstance(true, serviceName, null, null);
                            try {
                                StorageFile cserviceProp = storageFactory.newStorageFile(PersistentService.PROPERTIES_NAME);
                                if (cserviceProp.exists())
                                    if (!cserviceProp.delete())
                                        throw StandardException.newException(SQLState.UNABLE_TO_DELETE_FILE, cserviceProp);
                                return null;
                            } finally {
                                storageFactory.shutdown();
                            }
                        }
                    });
                } catch (PrivilegedActionException pae) {
                    throw Monitor.exceptionStartingModule((IOException) pae.getException());
                }
            } else
                throw StandardException.newException(SQLState.PROPERTY_FILE_NOT_FOUND_IN_BACKUP, bserviceProp);
        } else
            throw StandardException.newException(SQLState.SERVICE_DIRECTORY_NOT_IN_BACKUP, backupRoot);
        properties.put(Property.IN_RESTORE_FROM_BACKUP, "True");
        if (createRoot)
            properties.put(Property.DELETE_ROOT_ON_ERROR, "True");
    }
    return restoreFrom;
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) WritableStorageFactory(org.apache.derby.io.WritableStorageFactory) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) StandardException(org.apache.derby.shared.common.error.StandardException) WritableStorageFactory(org.apache.derby.io.WritableStorageFactory) StorageFactory(org.apache.derby.io.StorageFactory) StorageFile(org.apache.derby.io.StorageFile) StorageFile(org.apache.derby.io.StorageFile) StorageRandomAccessFile(org.apache.derby.io.StorageRandomAccessFile) File(java.io.File)

Example 92 with PrivilegedExceptionAction

use of java.security.PrivilegedExceptionAction in project derby by apache.

the class GClass method writeClassFile.

protected void writeClassFile(String dir, boolean logMessage, Throwable t) throws StandardException {
    if (SanityManager.DEBUG) {
        // not recursing...
        if (bytecode == null)
            getClassBytecode();
        if (dir == null)
            dir = "";
        // leave off package
        String filename = getName();
        filename = filename + ".class";
        final File classFile = new File(dir, filename);
        FileOutputStream fos = null;
        try {
            try {
                fos = AccessController.doPrivileged(new PrivilegedExceptionAction<FileOutputStream>() {

                    public FileOutputStream run() throws FileNotFoundException {
                        return new FileOutputStream(classFile);
                    }
                });
            } catch (PrivilegedActionException pae) {
                throw (FileNotFoundException) pae.getCause();
            }
            fos.write(bytecode.getArray(), bytecode.getOffset(), bytecode.getLength());
            fos.flush();
            if (logMessage) {
                // find the error stream
                HeaderPrintWriter errorStream = Monitor.getStream();
                errorStream.printlnWithHeader("Wrote class " + getFullName() + " to file " + classFile.toString() + ". Please provide support with the file and the following exception message: " + t);
            }
            fos.close();
        } catch (IOException e) {
            if (SanityManager.DEBUG)
                SanityManager.THROWASSERT("Unable to write .class file", e);
        }
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) HeaderPrintWriter(org.apache.derby.shared.common.stream.HeaderPrintWriter) FileOutputStream(java.io.FileOutputStream) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) IOException(java.io.IOException) File(java.io.File)

Example 93 with PrivilegedExceptionAction

use of java.security.PrivilegedExceptionAction in project narayana by jbosstm.

the class InterpositionServerRequestInterceptorImpl method receive_request_service_contexts.

public void receive_request_service_contexts(ServerRequestInfo request_info) throws SystemException {
    if (jtsLogger.logger.isTraceEnabled()) {
        trace_request("receive_request_service_contexts", request_info);
    }
    try {
        try {
            if (!InterceptorInfo.getAlwaysPropagate()) {
                if (!request_info.target_is_a(TransactionalObjectHelper.id()))
                    throw new BAD_PARAM();
            }
        } catch (Exception ex) {
        // just in case the object isn't in the IR.
        }
        try {
            ServiceContext serviceContext = null;
            try {
                serviceContext = request_info.get_request_service_context(OTSManager.serviceId);
            } catch (BAD_PARAM bp) {
                // no context, so nothing shipped!
                serviceContext = null;
            }
            if (serviceContext != null) {
                Any receivedData;
                try {
                    final ServiceContext finalServiceContext = serviceContext;
                    receivedData = doPrivileged(new PrivilegedExceptionAction<Any>() {

                        @Override
                        public Any run() throws org.omg.CORBA.UserException {
                            return _codec.decode_value(finalServiceContext.context_data, PropagationContextHelper.type());
                        }
                    });
                } catch (PrivilegedActionException pex) {
                    throw pex.getException();
                }
                /*
		     * Set the slot information for the "current" thread. When
		     * the real invocation thread actually needs to get its
		     * transaction context it must check this slot (if it does
		     * not have a transaction context already) and then do
		     * a resume.
		     */
                request_info.set_slot(_dataSlot, receivedData);
            } else {
                if (InterceptorInfo.getNeedTranContext())
                    throw new TRANSACTION_REQUIRED();
            }
        } catch (TRANSACTION_REQUIRED ex) {
            throw ex;
        } catch (Exception e) {
        }
    } catch (BAD_PARAM ex) {
    }
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) ServiceContext(org.omg.IOP.ServiceContext) BAD_PARAM(org.omg.CORBA.BAD_PARAM) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) TRANSACTION_REQUIRED(org.omg.CORBA.TRANSACTION_REQUIRED) Any(org.omg.CORBA.Any) PrivilegedActionException(java.security.PrivilegedActionException) SystemException(org.omg.CORBA.SystemException)

Example 94 with PrivilegedExceptionAction

use of java.security.PrivilegedExceptionAction in project ecf by eclipse.

the class SharedObjectMsg method doInvoke.

// package scope for security
Object doInvoke(// package scope for security
final Object target) throws Exception {
    if (target == null)
        throw new NoSuchMethodException(Messages.SharedObjectMsg_EXCEPTION_NULL_TARGET);
    Method meth = null;
    if (myClassName == null) {
        // If not specific class is specified by SharedObjectMsg instance,
        // then use the target's class
        meth = findMethodRecursive(target.getClass());
    } else {
        // If it is specified, then load the specified class, using the
        // target object's classloader
        meth = findMethod(getClass(target.getClass().getClassLoader(), myClassName));
    }
    // If no method was found, then throw
    if (meth == null)
        throw new NoSuchMethodException(getMethodName());
    final Method toCall = meth;
    // Make priveleged call to set the method as accessible
    AccessController.doPrivileged(new PrivilegedExceptionAction() {

        public Object run() throws Exception {
            if (!toCall.isAccessible())
                toCall.setAccessible(true);
            return null;
        }
    });
    // Actually invoke method
    return toCall.invoke(target, getArgs());
}
Also used : Method(java.lang.reflect.Method) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction) PrivilegedActionException(java.security.PrivilegedActionException) NotSerializableException(java.io.NotSerializableException)

Example 95 with PrivilegedExceptionAction

use of java.security.PrivilegedExceptionAction in project ecf by eclipse.

the class SOManager method createSharedObjectInstance.

protected ISharedObject createSharedObjectInstance(final Class newClass, final Class[] argTypes, final Object[] args) throws Exception {
    Object newObject = null;
    try {
        newObject = AccessController.doPrivileged(new PrivilegedExceptionAction() {

            public Object run() throws Exception {
                Constructor aConstructor = newClass.getConstructor(argTypes);
                aConstructor.setAccessible(true);
                return aConstructor.newInstance(args);
            }
        });
    } catch (java.security.PrivilegedActionException e) {
        throw e.getException();
    }
    return verifySharedObject(newObject);
}
Also used : Constructor(java.lang.reflect.Constructor) PrivilegedExceptionAction(java.security.PrivilegedExceptionAction)

Aggregations

PrivilegedExceptionAction (java.security.PrivilegedExceptionAction)387 IOException (java.io.IOException)199 PrivilegedActionException (java.security.PrivilegedActionException)135 Test (org.junit.Test)104 Connection (org.apache.hadoop.hbase.client.Connection)81 UserGroupInformation (org.apache.hadoop.security.UserGroupInformation)76 Table (org.apache.hadoop.hbase.client.Table)62 TableName (org.apache.hadoop.hbase.TableName)57 Result (org.apache.hadoop.hbase.client.Result)56 Scan (org.apache.hadoop.hbase.client.Scan)55 ResultScanner (org.apache.hadoop.hbase.client.ResultScanner)53 Delete (org.apache.hadoop.hbase.client.Delete)48 InterruptedIOException (java.io.InterruptedIOException)47 Cell (org.apache.hadoop.hbase.Cell)38 CellScanner (org.apache.hadoop.hbase.CellScanner)38 Configuration (org.apache.hadoop.conf.Configuration)36 File (java.io.File)33 AuthorizationException (org.apache.hadoop.security.authorize.AuthorizationException)33 Path (org.apache.hadoop.fs.Path)23 ArrayList (java.util.ArrayList)22