Search in sources :

Example 1 with Authorizer

use of org.apache.derby.iapi.sql.conn.Authorizer in project derby by apache.

the class SystemProcedures method setDatabaseProperty.

private static void setDatabaseProperty(String key, String value, Securable authorizationCheck) throws SQLException {
    LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
    try {
        if (authorizationCheck != null) {
            SecurityUtil.authorize(authorizationCheck);
        }
        Authorizer a = lcc.getAuthorizer();
        a.authorize((Activation) null, Authorizer.PROPERTY_WRITE_OP);
        // Get the current transaction controller
        TransactionController tc = lcc.getTransactionExecute();
        tc.setProperty(key, value, false);
    } catch (StandardException se) {
        throw PublicAPI.wrapStandardException(se);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Authorizer(org.apache.derby.iapi.sql.conn.Authorizer) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 2 with Authorizer

use of org.apache.derby.iapi.sql.conn.Authorizer in project derby by apache.

the class PropertyInfo method setDatabaseProperty.

/**
 *		Set or delete the value of a property of the database on the current connection.
 *        For security reasons (see DERBY-6616), this code is duplicated in SystemProcedures.
 *
 *		@param key the property key
 *		@param value the new value, if null the property is deleted.
 *
 *		@exception SQLException on error
 */
public static void setDatabaseProperty(String key, String value) throws SQLException {
    LanguageConnectionContext lcc = ConnectionUtil.getCurrentLCC();
    try {
        SecurityUtil.authorize(Securable.SET_DATABASE_PROPERTY);
        Authorizer a = lcc.getAuthorizer();
        a.authorize((Activation) null, Authorizer.PROPERTY_WRITE_OP);
        // Get the current transaction controller
        TransactionController tc = lcc.getTransactionExecute();
        tc.setProperty(key, value, false);
    } catch (StandardException se) {
        throw PublicAPI.wrapStandardException(se);
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Authorizer(org.apache.derby.iapi.sql.conn.Authorizer) TransactionController(org.apache.derby.iapi.store.access.TransactionController)

Example 3 with Authorizer

use of org.apache.derby.iapi.sql.conn.Authorizer in project derby by apache.

the class SecurityUtil method authorize.

/**
 * Raise an exception if the current user does not have permission
 * to perform the indicated operation.
 */
public static void authorize(Securable operation) throws StandardException {
    LanguageConnectionContext lcc = (LanguageConnectionContext) getContextOrNull(LanguageConnectionContext.CONTEXT_ID);
    if (lcc.usesSqlAuthorization()) {
        Authorizer authorizer = lcc.getAuthorizer();
        DataDictionary dd = lcc.getDataDictionary();
        AliasDescriptor ad = dd.getRoutineList(operation.routineSchemaID, operation.routineName, operation.routineType).get(0);
        ArrayList<StatementPermission> requiredPermissions = new ArrayList<StatementPermission>();
        StatementRoutinePermission executePermission = new StatementRoutinePermission(ad.getObjectID());
        requiredPermissions.add(executePermission);
        authorizer.authorize(requiredPermissions, lcc.getLastActivation());
    }
}
Also used : StatementPermission(org.apache.derby.iapi.sql.dictionary.StatementPermission) LanguageConnectionContext(org.apache.derby.iapi.sql.conn.LanguageConnectionContext) Authorizer(org.apache.derby.iapi.sql.conn.Authorizer) AliasDescriptor(org.apache.derby.iapi.sql.dictionary.AliasDescriptor) ArrayList(java.util.ArrayList) DataDictionary(org.apache.derby.iapi.sql.dictionary.DataDictionary) StatementRoutinePermission(org.apache.derby.iapi.sql.dictionary.StatementRoutinePermission)

Aggregations

Authorizer (org.apache.derby.iapi.sql.conn.Authorizer)3 LanguageConnectionContext (org.apache.derby.iapi.sql.conn.LanguageConnectionContext)3 TransactionController (org.apache.derby.iapi.store.access.TransactionController)2 StandardException (org.apache.derby.shared.common.error.StandardException)2 ArrayList (java.util.ArrayList)1 AliasDescriptor (org.apache.derby.iapi.sql.dictionary.AliasDescriptor)1 DataDictionary (org.apache.derby.iapi.sql.dictionary.DataDictionary)1 StatementPermission (org.apache.derby.iapi.sql.dictionary.StatementPermission)1 StatementRoutinePermission (org.apache.derby.iapi.sql.dictionary.StatementRoutinePermission)1