Search in sources :

Example 1 with PrincipalSpecification

use of io.trino.sql.tree.PrincipalSpecification in project trino by trinodb.

the class TestSqlParser method testRevokeRoles.

@Test
public void testRevokeRoles() {
    assertStatement("REVOKE role1 FROM user1", new RevokeRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1"))), false, Optional.empty(), Optional.empty()));
    assertStatement("REVOKE ADMIN OPTION FOR role1, role2, role3 FROM user1, USER user2, ROLE role4", new RevokeRoles(ImmutableSet.of(new Identifier("role1"), new Identifier("role2"), new Identifier("role3")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1")), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("user2")), new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role4"))), true, Optional.empty(), Optional.empty()));
    assertStatement("REVOKE ADMIN OPTION FOR role1 FROM user1 GRANTED BY admin", new RevokeRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1"))), true, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("admin"))))), Optional.empty()));
    assertStatement("REVOKE ADMIN OPTION FOR role1 FROM USER user1 GRANTED BY USER admin", new RevokeRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("user1"))), true, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("admin"))))), Optional.empty()));
    assertStatement("REVOKE role1 FROM ROLE role2 GRANTED BY ROLE admin", new RevokeRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role2"))), false, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("admin"))))), Optional.empty()));
    assertStatement("REVOKE \"role1\" FROM ROLE \"role2\" GRANTED BY ROLE \"admin\"", new RevokeRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role2"))), false, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("admin"))))), Optional.empty()));
    assertStatement("REVOKE role1 FROM user1 IN my_catalog", new RevokeRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1"))), false, Optional.empty(), Optional.of(new Identifier("my_catalog"))));
}
Also used : RevokeRoles(io.trino.sql.tree.RevokeRoles) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) PrincipalSpecification(io.trino.sql.tree.PrincipalSpecification) GrantorSpecification(io.trino.sql.tree.GrantorSpecification) Test(org.junit.jupiter.api.Test)

Example 2 with PrincipalSpecification

use of io.trino.sql.tree.PrincipalSpecification in project trino by trinodb.

the class TestSqlParser method testAlterTableSetAuthorization.

@Test
public void testAlterTableSetAuthorization() {
    assertStatement("ALTER TABLE foo.bar.baz SET AUTHORIZATION qux", new SetTableAuthorization(QualifiedName.of("foo", "bar", "baz"), new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("qux"))));
    assertStatement("ALTER TABLE foo.bar.baz SET AUTHORIZATION USER qux", new SetTableAuthorization(QualifiedName.of("foo", "bar", "baz"), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("qux"))));
    assertStatement("ALTER TABLE foo.bar.baz SET AUTHORIZATION ROLE qux", new SetTableAuthorization(QualifiedName.of("foo", "bar", "baz"), new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("qux"))));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) PrincipalSpecification(io.trino.sql.tree.PrincipalSpecification) SetTableAuthorization(io.trino.sql.tree.SetTableAuthorization) Test(org.junit.jupiter.api.Test)

Example 3 with PrincipalSpecification

use of io.trino.sql.tree.PrincipalSpecification in project trino by trinodb.

the class TestSqlParser method testGrant.

@Test
public void testGrant() {
    assertStatement("GRANT INSERT, DELETE ON t TO u", new Grant(Optional.of(ImmutableList.of("INSERT", "DELETE")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("u")), false));
    assertStatement("GRANT UPDATE ON t TO u", new Grant(Optional.of(ImmutableList.of("UPDATE")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("u")), false));
    assertStatement("GRANT SELECT ON t TO ROLE PUBLIC WITH GRANT OPTION", new Grant(Optional.of(ImmutableList.of("SELECT")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("PUBLIC")), true));
    assertStatement("GRANT ALL PRIVILEGES ON TABLE t TO USER u", new Grant(Optional.empty(), Optional.of(GrantOnType.TABLE), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("u")), false));
    assertStatement("GRANT DELETE ON \"t\" TO ROLE \"public\" WITH GRANT OPTION", new Grant(Optional.of(ImmutableList.of("DELETE")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("public")), true));
    assertStatement("GRANT SELECT ON SCHEMA s TO USER u", new Grant(Optional.of(ImmutableList.of("SELECT")), Optional.of(GrantOnType.SCHEMA), QualifiedName.of("s"), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("u")), false));
}
Also used : Grant(io.trino.sql.tree.Grant) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) PrincipalSpecification(io.trino.sql.tree.PrincipalSpecification) Test(org.junit.jupiter.api.Test)

Example 4 with PrincipalSpecification

use of io.trino.sql.tree.PrincipalSpecification in project trino by trinodb.

the class TestSqlParser method testGrantRoles.

@Test
public void testGrantRoles() {
    assertStatement("GRANT role1 TO user1", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1"))), false, Optional.empty(), Optional.empty()));
    assertStatement("GRANT role1, role2, role3 TO user1, USER user2, ROLE role4 WITH ADMIN OPTION", new GrantRoles(ImmutableSet.of(new Identifier("role1"), new Identifier("role2"), new Identifier("role3")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1")), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("user2")), new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role4"))), true, Optional.empty(), Optional.empty()));
    assertStatement("GRANT role1 TO user1 WITH ADMIN OPTION GRANTED BY admin", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1"))), true, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("admin"))))), Optional.empty()));
    assertStatement("GRANT role1 TO USER user1 WITH ADMIN OPTION GRANTED BY USER admin", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("user1"))), true, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("admin"))))), Optional.empty()));
    assertStatement("GRANT role1 TO ROLE role2 WITH ADMIN OPTION GRANTED BY ROLE admin", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role2"))), true, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("admin"))))), Optional.empty()));
    assertStatement("GRANT role1 TO ROLE role2 GRANTED BY ROLE admin", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role2"))), false, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("admin"))))), Optional.empty()));
    assertStatement("GRANT \"role1\" TO ROLE \"role2\" GRANTED BY ROLE \"admin\"", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("role2"))), false, Optional.of(new GrantorSpecification(GrantorSpecification.Type.PRINCIPAL, Optional.of(new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("admin"))))), Optional.empty()));
    assertStatement("GRANT role1 TO user1 IN my_catalog", new GrantRoles(ImmutableSet.of(new Identifier("role1")), ImmutableSet.of(new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("user1"))), false, Optional.empty(), Optional.of(new Identifier("my_catalog"))));
}
Also used : GrantRoles(io.trino.sql.tree.GrantRoles) QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) PrincipalSpecification(io.trino.sql.tree.PrincipalSpecification) GrantorSpecification(io.trino.sql.tree.GrantorSpecification) Test(org.junit.jupiter.api.Test)

Example 5 with PrincipalSpecification

use of io.trino.sql.tree.PrincipalSpecification in project trino by trinodb.

the class TestSqlParser method testRevoke.

@Test
public void testRevoke() {
    assertStatement("REVOKE INSERT, DELETE ON t FROM u", new Revoke(false, Optional.of(ImmutableList.of("INSERT", "DELETE")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("u"))));
    assertStatement("REVOKE UPDATE ON t FROM u", new Revoke(false, Optional.of(ImmutableList.of("UPDATE")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("u"))));
    assertStatement("REVOKE GRANT OPTION FOR SELECT ON t FROM ROLE PUBLIC", new Revoke(true, Optional.of(ImmutableList.of("SELECT")), Optional.empty(), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.ROLE, new Identifier("PUBLIC"))));
    assertStatement("REVOKE ALL PRIVILEGES ON TABLE t FROM USER u", new Revoke(false, Optional.empty(), Optional.of(GrantOnType.TABLE), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("u"))));
    assertStatement("REVOKE DELETE ON TABLE \"t\" FROM \"u\"", new Revoke(false, Optional.of(ImmutableList.of("DELETE")), Optional.of(GrantOnType.TABLE), QualifiedName.of("t"), new PrincipalSpecification(PrincipalSpecification.Type.UNSPECIFIED, new Identifier("u"))));
    assertStatement("REVOKE SELECT ON SCHEMA s FROM USER u", new Revoke(false, Optional.of(ImmutableList.of("SELECT")), Optional.of(GrantOnType.SCHEMA), QualifiedName.of("s"), new PrincipalSpecification(PrincipalSpecification.Type.USER, new Identifier("u"))));
}
Also used : QueryUtil.quotedIdentifier(io.trino.sql.QueryUtil.quotedIdentifier) Identifier(io.trino.sql.tree.Identifier) Revoke(io.trino.sql.tree.Revoke) PrincipalSpecification(io.trino.sql.tree.PrincipalSpecification) Test(org.junit.jupiter.api.Test)

Aggregations

QueryUtil.quotedIdentifier (io.trino.sql.QueryUtil.quotedIdentifier)8 Identifier (io.trino.sql.tree.Identifier)8 PrincipalSpecification (io.trino.sql.tree.PrincipalSpecification)8 Test (org.junit.jupiter.api.Test)8 GrantorSpecification (io.trino.sql.tree.GrantorSpecification)3 CreateRole (io.trino.sql.tree.CreateRole)1 Deny (io.trino.sql.tree.Deny)1 Grant (io.trino.sql.tree.Grant)1 GrantRoles (io.trino.sql.tree.GrantRoles)1 Revoke (io.trino.sql.tree.Revoke)1 RevokeRoles (io.trino.sql.tree.RevokeRoles)1 SetTableAuthorization (io.trino.sql.tree.SetTableAuthorization)1 SetViewAuthorization (io.trino.sql.tree.SetViewAuthorization)1