use of io.crate.user.Privilege in project crate by crate.
the class UserPrivilegesTest method testMatchPrivilegeDenyResultsInNoMatch.
@Test
public void testMatchPrivilegeDenyResultsInNoMatch() throws Exception {
Collection<Privilege> privileges = Set.of(new Privilege(Privilege.State.DENY, Privilege.Type.DQL, Privilege.Clazz.CLUSTER, null, "crate"));
UserPrivileges userPrivileges = new UserPrivileges(privileges);
assertThat(userPrivileges.matchPrivilege(Privilege.Type.DQL, Privilege.Clazz.CLUSTER, null, "doc"), is(false));
assertThat(userPrivileges.matchPrivilege(Privilege.Type.DQL, Privilege.Clazz.SCHEMA, "doc", "doc"), is(false));
assertThat(userPrivileges.matchPrivilege(Privilege.Type.DQL, Privilege.Clazz.TABLE, "doc.t1", "doc"), is(false));
assertThat(userPrivileges.matchPrivilegeOfAnyType(Privilege.Clazz.CLUSTER, null), is(false));
assertThat(userPrivileges.matchPrivilegeOfAnyType(Privilege.Clazz.SCHEMA, "doc"), is(false));
assertThat(userPrivileges.matchPrivilegeOfAnyType(Privilege.Clazz.TABLE, "doc.t1"), is(false));
}
use of io.crate.user.Privilege in project crate by crate.
the class UserPrivilegesTest method testMatchPrivilegeComplexSetIncludingDeny.
@Test
public void testMatchPrivilegeComplexSetIncludingDeny() throws Exception {
Collection<Privilege> privileges = Set.of(new Privilege(Privilege.State.GRANT, Privilege.Type.DQL, Privilege.Clazz.CLUSTER, null, "crate"), new Privilege(Privilege.State.DENY, Privilege.Type.DQL, Privilege.Clazz.SCHEMA, "doc", "crate"), new Privilege(Privilege.State.GRANT, Privilege.Type.DQL, Privilege.Clazz.TABLE, "doc.t1", "crate"));
UserPrivileges userPrivileges = new UserPrivileges(privileges);
assertThat(userPrivileges.matchPrivilege(Privilege.Type.DQL, Privilege.Clazz.TABLE, "doc.t1", "doc"), is(true));
assertThat(userPrivileges.matchPrivilege(Privilege.Type.DQL, Privilege.Clazz.TABLE, "doc.t2", "doc"), is(false));
assertThat(userPrivileges.matchPrivilege(Privilege.Type.DQL, Privilege.Clazz.SCHEMA, "my_schema", "doc"), is(true));
}
use of io.crate.user.Privilege in project crate by crate.
the class PrivilegesMetadataUpgraderTest method testExistingUserWithPrivilegesDoesntGetMore.
@Test
public void testExistingUserWithPrivilegesDoesntGetMore() throws Exception {
Map<String, Metadata.Custom> customMap = new HashMap<>(1);
customMap.put(UsersMetadata.TYPE, new UsersMetadata(UserDefinitions.SINGLE_USER_ONLY));
customMap.put(UsersPrivilegesMetadata.TYPE, new UsersPrivilegesMetadata(MapBuilder.<String, Set<Privilege>>newMapBuilder().put("Arthur", Set.of(new Privilege(Privilege.State.GRANT, Privilege.Type.DQL, Privilege.Clazz.CLUSTER, null, "crate"))).map()));
Map<String, Metadata.Custom> oldCustomMap = new HashMap<>(customMap);
Map<String, Metadata.Custom> newCustomMap = UPGRADER.apply(Settings.EMPTY, customMap);
assertThat(newCustomMap, is(oldCustomMap));
}
use of io.crate.user.Privilege in project crate by crate.
the class PrivilegesAnalyzer method privilegeTypesToPrivileges.
private static Set<Privilege> privilegeTypesToPrivileges(Collection<Privilege.Type> privilegeTypes, User grantor, State state, List<String> idents, Privilege.Clazz clazz) {
Set<Privilege> privileges = new HashSet<>(privilegeTypes.size());
if (Privilege.Clazz.CLUSTER.equals(clazz)) {
for (Privilege.Type privilegeType : privilegeTypes) {
Privilege privilege = new Privilege(state, privilegeType, clazz, null, grantor.name());
privileges.add(privilege);
}
} else {
for (Privilege.Type privilegeType : privilegeTypes) {
for (String ident : idents) {
Privilege privilege = new Privilege(state, privilegeType, clazz, ident, grantor.name());
privileges.add(privilege);
}
}
}
return privileges;
}
use of io.crate.user.Privilege in project crate by crate.
the class UsersPrivilegesMetadata method writeTo.
@Override
public void writeTo(StreamOutput out) throws IOException {
out.writeVInt(usersPrivileges.size());
for (Map.Entry<String, Set<Privilege>> entry : usersPrivileges.entrySet()) {
out.writeString(entry.getKey());
out.writeVInt(entry.getValue().size());
for (Privilege privilege : entry.getValue()) {
privilege.writeTo(out);
}
}
}
Aggregations