Search in sources :

Example 1 with Permission

use of org.voltdb.common.Permission in project voltdb by VoltDB.

the class CatalogSchemaTools method toSchema.

/**
     * Convert a Group (Role) into a DDL string.
     * sb The ddl
     * @param grp The group
     */
public static void toSchema(StringBuilder sb, Group grp) {
    // Don't output the default roles because user cannot change them.
    if (grp.getTypeName().equalsIgnoreCase("ADMINISTRATOR") || grp.getTypeName().equalsIgnoreCase("USER")) {
        return;
    }
    final EnumSet<Permission> permissions = Permission.getPermissionSetForGroup(grp);
    sb.append("CREATE ROLE ").append(grp.getTypeName());
    String delimiter = " WITH ";
    for (Permission permission : permissions) {
        sb.append(delimiter).append(permission.name());
        delimiter = ", ";
    }
    sb.append(";\n");
}
Also used : Permission(org.voltdb.common.Permission)

Example 2 with Permission

use of org.voltdb.common.Permission in project voltdb by VoltDB.

the class CreateRole method processStatement.

@Override
protected boolean processStatement(DDLStatement ddlStatement, Database db, DdlProceduresToLoad whichProcs) throws VoltCompilerException {
    // matches if it is CREATE ROLE [WITH <permission> [, <permission> ...]]
    // group 1 is role name
    // group 2 is comma-separated permission list or null if there is no WITH clause
    Matcher statementMatcher = SQLParser.matchCreateRole(ddlStatement.statement);
    if (!statementMatcher.matches()) {
        return false;
    }
    String roleName = statementMatcher.group(1).toLowerCase();
    CatalogMap<Group> groupMap = db.getGroups();
    if (groupMap.get(roleName) != null) {
        throw m_compiler.new VoltCompilerException(String.format("Role name \"%s\" in CREATE ROLE statement already exists.", roleName));
    }
    Group catGroup = groupMap.add(roleName);
    if (statementMatcher.group(2) != null) {
        try {
            EnumSet<Permission> permset = Permission.getPermissionsFromAliases(Arrays.asList(StringUtils.split(statementMatcher.group(2), ',')));
            Permission.setPermissionsInGroup(catGroup, permset);
        } catch (IllegalArgumentException iaex) {
            throw m_compiler.new VoltCompilerException(String.format("Invalid permission \"%s\" in CREATE ROLE statement: \"%s\", " + "available permissions: %s", iaex.getMessage(), // remove trailing semicolon
            ddlStatement.statement.substring(0, ddlStatement.statement.length() - 1), Permission.toListString()));
        }
    }
    return true;
}
Also used : Group(org.voltdb.catalog.Group) Matcher(java.util.regex.Matcher) Permission(org.voltdb.common.Permission) VoltCompilerException(org.voltdb.compiler.VoltCompiler.VoltCompilerException)

Aggregations

Permission (org.voltdb.common.Permission)2 Matcher (java.util.regex.Matcher)1 Group (org.voltdb.catalog.Group)1 VoltCompilerException (org.voltdb.compiler.VoltCompiler.VoltCompilerException)1