Search in sources :

Example 1 with SQLPermission

use of java.sql.SQLPermission in project mssql-jdbc by Microsoft.

the class SQLServerConnectionSecurityManager method abort.

public void abort(Executor executor) throws SQLException {
    loggerExternal.entering(getClassNameLogging(), "abort", executor);
    // nop if connection is closed
    if (isClosed())
        return;
    if (null == executor) {
        MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidArgument"));
        Object[] msgArgs = { "executor" };
        SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false);
    }
    // check for callAbort permission
    SecurityManager secMgr = System.getSecurityManager();
    if (secMgr != null) {
        try {
            SQLPermission perm = new SQLPermission(callAbortPerm);
            secMgr.checkPermission(perm);
        } catch (SecurityException ex) {
            MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_permissionDenied"));
            Object[] msgArgs = { callAbortPerm };
            SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, true);
        }
    }
    setState(State.Closed);
    executor.execute(new Runnable() {

        public void run() {
            if (null != tdsChannel) {
                tdsChannel.close();
            }
        }
    });
    loggerExternal.exiting(getClassNameLogging(), "abort");
}
Also used : SQLPermission(java.sql.SQLPermission) MessageFormat(java.text.MessageFormat)

Example 2 with SQLPermission

use of java.sql.SQLPermission in project derby by apache.

the class ClientConnection method abort.

public void abort(Executor executor) throws SQLException {
    // NOP if called on a closed connection.
    if (!open_) {
        return;
    }
    // Null executor not allowed.
    if (executor == null) {
        ClientMessageId cmi = new ClientMessageId(SQLState.UU_INVALID_PARAMETER);
        SqlException se = new SqlException(agent_.logWriter_, cmi, "executor", "null");
        throw se.getSQLException();
    }
    // 
    // Must have privilege to invoke this method.
    // 
    // The derby jars should be granted this permission. We deliberately
    // do not wrap this check in an AccessController.doPrivileged() block.
    // If we did so, that would absolve outer code blocks of the need to
    // have this permission granted to them too. It is critical that the
    // outer code blocks enjoy this privilege. That is what allows
    // connection pools to prevent ordinary code from calling abort()
    // and restrict its usage to privileged tools.
    // 
    SecurityManager securityManager = System.getSecurityManager();
    if (securityManager != null) {
        securityManager.checkPermission(new SQLPermission("callAbort"));
    }
    // Mark the Connection as closed. Set the "aborting" flag to allow internal
    // processing in close() to proceed.
    beginAborting();
    // 
    // Now pass the Executor a Runnable which does the real work.
    // 
    executor.execute(new Runnable() {

        public void run() {
            try {
                rollback();
                close();
            } catch (SQLException se) {
                se.printStackTrace(agent_.getLogWriter());
            }
        }
    });
}
Also used : SQLPermission(java.sql.SQLPermission) SQLException(java.sql.SQLException)

Example 3 with SQLPermission

use of java.sql.SQLPermission in project derby by apache.

the class EmbedConnection method abort.

// //////////////////////////////////////////////////////////////////
// 
// INTRODUCED BY JDBC 4.1 IN JAVA 7
// 
// //////////////////////////////////////////////////////////////////
public void abort(Executor executor) throws SQLException {
    // NOP if called on a closed connection.
    if (isClosed()) {
        return;
    }
    // Null executor not allowed.
    if (executor == null) {
        throw newSQLException(SQLState.UU_INVALID_PARAMETER, "executor", "null");
    }
    // 
    // Must have privilege to invoke this method.
    // 
    // The derby jars should be granted this permission. We deliberately
    // do not wrap this check in an AccessController.doPrivileged() block.
    // If we did so, that would absolve outer code blocks of the need to
    // have this permission granted to them too. It is critical that the
    // outer code blocks enjoy this privilege. That is what allows
    // connection pools to prevent ordinary code from calling abort()
    // and restrict its usage to privileged tools.
    // 
    SecurityManager securityManager = System.getSecurityManager();
    if (securityManager != null) {
        securityManager.checkPermission(new SQLPermission("callAbort"));
    }
    // Mark the Connection as closed. Set the "aborting" flag to allow internal
    // processing in close() to proceed.
    beginAborting();
    // 
    // Now pass the Executor a Runnable which does the real work.
    // 
    executor.execute(new Runnable() {

        public void run() {
            try {
                rollback();
                close(exceptionClose);
            } catch (SQLException se) {
                Util.logSQLException(se);
            }
        }
    });
}
Also used : SQLPermission(java.sql.SQLPermission) SQLException(java.sql.SQLException)

Example 4 with SQLPermission

use of java.sql.SQLPermission in project mssql-jdbc by Microsoft.

the class SQLServerConnectionSecurityManager method setNetworkTimeout.

public void setNetworkTimeout(Executor executor, int timeout) throws SQLException {
    loggerExternal.entering(getClassNameLogging(), "setNetworkTimeout", timeout);
    if (timeout < 0) {
        MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidSocketTimeout"));
        Object[] msgArgs = { timeout };
        SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, false);
    }
    checkClosed();
    // check for setNetworkTimeout permission
    SecurityManager secMgr = System.getSecurityManager();
    if (secMgr != null) {
        try {
            SQLPermission perm = new SQLPermission(SET_NETWORK_TIMEOUT_PERM);
            secMgr.checkPermission(perm);
        } catch (SecurityException ex) {
            MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_permissionDenied"));
            Object[] msgArgs = { SET_NETWORK_TIMEOUT_PERM };
            SQLServerException.makeFromDriverError(this, this, form.format(msgArgs), null, true);
        }
    }
    try {
        tdsChannel.setNetworkTimeout(timeout);
    } catch (IOException ioe) {
        terminate(SQLServerException.DRIVER_ERROR_IO_FAILED, ioe.getMessage(), ioe);
    }
    loggerExternal.exiting(getClassNameLogging(), "setNetworkTimeout");
}
Also used : SQLPermission(java.sql.SQLPermission) MessageFormat(java.text.MessageFormat) IOException(java.io.IOException)

Example 5 with SQLPermission

use of java.sql.SQLPermission in project mssql-jdbc by Microsoft.

the class SQLServerConnectionPoolProxy method abort.

public void abort(Executor executor) throws SQLException {
    if (!bIsOpen || (null == wrappedConnection))
        return;
    if (null == executor) {
        MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_invalidArgument"));
        Object[] msgArgs = { "executor" };
        SQLServerException.makeFromDriverError(null, null, form.format(msgArgs), null, false);
    }
    // check for callAbort permission
    SecurityManager secMgr = System.getSecurityManager();
    if (secMgr != null) {
        try {
            SQLPermission perm = new SQLPermission(callAbortPerm);
            secMgr.checkPermission(perm);
        } catch (SecurityException ex) {
            MessageFormat form = new MessageFormat(SQLServerException.getErrString("R_permissionDenied"));
            Object[] msgArgs = { callAbortPerm };
            throw new SQLServerException(form.format(msgArgs), null, 0, ex);
        }
    }
    bIsOpen = false;
    executor.execute(new Runnable() {

        public void run() {
            if (wrappedConnection.getConnectionLogger().isLoggable(Level.FINER))
                wrappedConnection.getConnectionLogger().finer(toString() + " Connection proxy aborted ");
            try {
                wrappedConnection.poolCloseEventNotify();
                wrappedConnection = null;
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
    });
}
Also used : SQLPermission(java.sql.SQLPermission) MessageFormat(java.text.MessageFormat) SQLException(java.sql.SQLException)

Aggregations

SQLPermission (java.sql.SQLPermission)5 SQLException (java.sql.SQLException)3 MessageFormat (java.text.MessageFormat)3 IOException (java.io.IOException)1