Search in sources :

Example 1 with User

use of org.hsqldb_voltpatches.rights.User in project voltdb by VoltDB.

the class Database method connect.

/**
     *  Constructs a new Session that operates within (is connected to) the
     *  context of this Database object. <p>
     *
     *  If successful, the new Session object initially operates on behalf of
     *  the user specified by the supplied user name.
     *
     * Throws if username or password is invalid.
     */
synchronized Session connect(String username, String password, int timeZoneSeconds) {
    if (username.equalsIgnoreCase("SA")) {
        username = "SA";
    }
    User user = userManager.getUser(username, password);
    Session session = sessionManager.newSession(this, user, databaseReadOnly, false, timeZoneSeconds);
    return session;
}
Also used : User(org.hsqldb_voltpatches.rights.User)

Example 2 with User

use of org.hsqldb_voltpatches.rights.User in project voltdb by VoltDB.

the class ParserDDL method compileAlterUser.

Statement compileAlterUser() {
    String password;
    User userObject;
    HsqlName userName = readNewUserIdentifier();
    userObject = database.getUserManager().get(userName.name);
    if (userName.name.equals(Tokens.T_PUBLIC)) {
        throw Error.error(ErrorCode.X_42503);
    }
    readThis(Tokens.SET);
    if (token.tokenType == Tokens.PASSWORD) {
        read();
        password = readPassword();
        Object[] args = new Object[] { userObject, password };
        return new StatementCommand(StatementTypes.SET_USER_PASSWORD, args, null, null);
    } else if (token.tokenType == Tokens.INITIAL) {
        read();
        readThis(Tokens.SCHEMA);
        HsqlName schemaName;
        if (token.tokenType == Tokens.DEFAULT) {
            schemaName = null;
        } else {
            schemaName = database.schemaManager.getSchemaHsqlName(token.tokenString);
        }
        read();
        Object[] args = new Object[] { userObject, schemaName };
        return new StatementCommand(StatementTypes.SET_USER_INITIAL_SCHEMA, args, null, null);
    } else {
        throw unexpectedToken();
    }
}
Also used : User(org.hsqldb_voltpatches.rights.User) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName)

Example 3 with User

use of org.hsqldb_voltpatches.rights.User in project voltdb by VoltDB.

the class DatabaseInformationMain method SYSTEM_USERS.

/**
     * Retrieves a <code>Table</code> object describing the
     * visible <code>Users</code> defined within this database.
     * @return table containing information about the users defined within
     *      this database
     */
Table SYSTEM_USERS() {
    Table t = sysTables[SYSTEM_USERS];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[SYSTEM_USERS]);
        addColumn(t, "USER_NAME", SQL_IDENTIFIER);
        addColumn(t, "ADMIN", Type.SQL_BOOLEAN);
        addColumn(t, "INITIAL_SCHEMA", SQL_IDENTIFIER);
        // order: USER
        // true PK
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[SYSTEM_USERS].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 0 }, true);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // Intermediate holders
    HsqlArrayList users;
    User user;
    Object[] row;
    HsqlName initialSchema;
    // Initialization
    users = database.getUserManager().listVisibleUsers(session);
    // Do it.
    for (int i = 0; i < users.size(); i++) {
        row = t.getEmptyRowData();
        user = (User) users.get(i);
        initialSchema = user.getInitialSchema();
        row[0] = user.getNameString();
        row[1] = ValuePool.getBoolean(user.isAdmin());
        row[2] = ((initialSchema == null) ? null : initialSchema.name);
        t.insertSys(store, row);
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) User(org.hsqldb_voltpatches.rights.User) HsqlArrayList(org.hsqldb_voltpatches.lib.HsqlArrayList) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) Constraint(org.hsqldb_voltpatches.Constraint)

Example 4 with User

use of org.hsqldb_voltpatches.rights.User in project voltdb by VoltDB.

the class DatabaseInformationMain method COLUMN_PRIVILEGES.

// -----------------------------------------------------------------------------
// SQL SCHEMATA VIEWS
// limited to views used in JDBC DatabaseMetaData
/**
     * Retrieves a <code>Table</code> object describing the visible
     * access rights for all visible columns of all accessible
     * tables defined within this database.<p>
     *
     * Each row is a column privilege description with the following
     * columns: <p>
     *
     * <pre class="SqlCodeExample">
     * TABLE_CAT    VARCHAR   table catalog
     * TABLE_SCHEM  VARCHAR   table schema
     * TABLE_NAME   VARCHAR   table name
     * COLUMN_NAME  VARCHAR   column name
     * GRANTOR      VARCHAR   grantor of access
     * GRANTEE      VARCHAR   grantee of access
     * PRIVILEGE    VARCHAR   name of access
     * IS_GRANTABLE VARCHAR   grantable?: "YES" - grant to others, else "NO"
     * </pre>
     *
     * <b>Note:</b> From 1.9.0, HSQLDB supports column level
     * privileges. <p>
     *
     * @return a <code>Table</code> object describing the visible
     *        access rights for all visible columns of
     *        all accessible tables defined within this
     *        database
     */
final Table COLUMN_PRIVILEGES() {
    Table t = sysTables[COLUMN_PRIVILEGES];
    if (t == null) {
        t = createBlankTable(sysTableHsqlNames[COLUMN_PRIVILEGES]);
        // not null
        addColumn(t, "GRANTOR", SQL_IDENTIFIER);
        // not null
        addColumn(t, "GRANTEE", SQL_IDENTIFIER);
        addColumn(t, "TABLE_CATALOG", SQL_IDENTIFIER);
        addColumn(t, "TABLE_SCHEMA", SQL_IDENTIFIER);
        // not null
        addColumn(t, "TABLE_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "COLUMN_NAME", SQL_IDENTIFIER);
        // not null
        addColumn(t, "PRIVILEGE_TYPE", CHARACTER_DATA);
        // not null
        addColumn(t, "IS_GRANTABLE", YES_OR_NO);
        HsqlName name = HsqlNameManager.newInfoSchemaObjectName(sysTableHsqlNames[COLUMN_PRIVILEGES].name, false, SchemaObject.INDEX);
        t.createPrimaryKey(name, new int[] { 2, 3, 4, 5, 6, 1, 0 }, false);
        return t;
    }
    PersistentStore store = database.persistentStoreCollection.getStore(t);
    // calculated column values
    String tableCatalog;
    String tableSchema;
    String tableName;
    Grantee granteeObject;
    // intermediate holders
    User user;
    Iterator tables;
    Table table;
    Object[] row;
    // column number mappings
    final int grantor = 0;
    final int grantee = 1;
    final int table_catalog = 2;
    final int table_schema = 3;
    final int table_name = 4;
    final int column_name = 5;
    final int privilege_type = 6;
    final int is_grantable = 7;
    // enumerations
    OrderedHashSet grantees = session.getGrantee().getGranteeAndAllRolesWithPublic();
    // Initialization
    tables = allTables();
    while (tables.hasNext()) {
        table = (Table) tables.next();
        tableName = table.getName().name;
        tableCatalog = database.getCatalogName().name;
        tableSchema = table.getSchemaName().name;
        for (int i = 0; i < grantees.size(); i++) {
            granteeObject = (Grantee) grantees.get(i);
            OrderedHashSet rights = granteeObject.getAllDirectPrivileges(table);
            OrderedHashSet grants = granteeObject.getAllGrantedPrivileges(table);
            if (!grants.isEmpty()) {
                grants.addAll(rights);
                rights = grants;
            }
            for (int j = 0; j < rights.size(); j++) {
                Right right = (Right) rights.get(j);
                Right grantableRight = right.getGrantableRights();
                for (int k = 0; k < Right.privilegeTypes.length; k++) {
                    OrderedHashSet columnList = right.getColumnsForPrivilege(table, Right.privilegeTypes[k]);
                    OrderedHashSet grantableList = grantableRight.getColumnsForPrivilege(table, Right.privilegeTypes[k]);
                    for (int l = 0; l < columnList.size(); l++) {
                        HsqlName fullName = ((HsqlName) columnList.get(l));
                        row = t.getEmptyRowData();
                        row[grantor] = right.getGrantor().getName().name;
                        row[grantee] = right.getGrantee().getName().name;
                        row[table_catalog] = tableCatalog;
                        row[table_schema] = tableSchema;
                        row[table_name] = tableName;
                        row[column_name] = fullName.name;
                        row[privilege_type] = Right.privilegeNames[k];
                        row[is_grantable] = right.getGrantee() == table.getOwner() || grantableList.contains(fullName) ? "YES" : "NO";
                        try {
                            t.insertSys(store, row);
                        } catch (HsqlException e) {
                        }
                    }
                }
            }
        }
    }
    return t;
}
Also used : Table(org.hsqldb_voltpatches.Table) User(org.hsqldb_voltpatches.rights.User) Right(org.hsqldb_voltpatches.rights.Right) PersistentStore(org.hsqldb_voltpatches.persist.PersistentStore) Constraint(org.hsqldb_voltpatches.Constraint) Grantee(org.hsqldb_voltpatches.rights.Grantee) Iterator(org.hsqldb_voltpatches.lib.Iterator) WrapperIterator(org.hsqldb_voltpatches.lib.WrapperIterator) OrderedHashSet(org.hsqldb_voltpatches.lib.OrderedHashSet) HsqlName(org.hsqldb_voltpatches.HsqlNameManager.HsqlName) SchemaObject(org.hsqldb_voltpatches.SchemaObject) HsqlException(org.hsqldb_voltpatches.HsqlException)

Aggregations

User (org.hsqldb_voltpatches.rights.User)4 HsqlName (org.hsqldb_voltpatches.HsqlNameManager.HsqlName)3 Constraint (org.hsqldb_voltpatches.Constraint)2 SchemaObject (org.hsqldb_voltpatches.SchemaObject)2 Table (org.hsqldb_voltpatches.Table)2 PersistentStore (org.hsqldb_voltpatches.persist.PersistentStore)2 HsqlException (org.hsqldb_voltpatches.HsqlException)1 HsqlArrayList (org.hsqldb_voltpatches.lib.HsqlArrayList)1 Iterator (org.hsqldb_voltpatches.lib.Iterator)1 OrderedHashSet (org.hsqldb_voltpatches.lib.OrderedHashSet)1 WrapperIterator (org.hsqldb_voltpatches.lib.WrapperIterator)1 Grantee (org.hsqldb_voltpatches.rights.Grantee)1 Right (org.hsqldb_voltpatches.rights.Right)1