use of com.bakdata.conquery.models.auth.permissions.ConqueryPermission in project conquery by bakdata.
the class TokenScopedUser method authorize.
@Override
public void authorize(@NonNull Authorized object, @NonNull Ability ability) {
final ConqueryPermission permission = object.createPermission(EnumSet.of(ability));
if (!tokenContext.isCoveredByScopes(permission)) {
throw new UnauthorizedException("The scopes of the token do not support handling the permission: " + permission);
}
delegate.authorize(object, ability);
}
use of com.bakdata.conquery.models.auth.permissions.ConqueryPermission in project conquery by bakdata.
the class User method getEffectivePermissions.
@Override
public Set<ConqueryPermission> getEffectivePermissions() {
Set<ConqueryPermission> permissions = getPermissions();
for (RoleId roleId : roles) {
Role role = storage.getRole(roleId);
if (role == null) {
log.warn("Could not find role {} to gather permissions", roleId);
continue;
}
permissions = Sets.union(permissions, role.getEffectivePermissions());
}
for (Group group : storage.getAllGroups()) {
if (!group.containsMember(this)) {
continue;
}
permissions = Sets.union(permissions, group.getEffectivePermissions());
}
return permissions;
}
use of com.bakdata.conquery.models.auth.permissions.ConqueryPermission in project conquery by bakdata.
the class AuthorizationController method flatCopyUser.
/**
* Creates a copy of an existing user. The copied user has the same effective permissions as the original user
* at the time of copying, but these are flatted. This means that the original user might hold certain permissions
* through inheritance from roles or groups, the copy will hold the permissions directly.
* @param originUser The user to make a flat copy of
* @param namePrefix The prefix for the id of the new copied user
* @return A flat copy of the referenced user
*/
public static User flatCopyUser(@NonNull User originUser, String namePrefix, @NonNull MetaStorage storage) {
final UserId originUserId = originUser.getId();
if (Strings.isNullOrEmpty(namePrefix)) {
throw new IllegalArgumentException("There must be a prefix");
}
// Find a new user id that is not used yet
String name = null;
do {
name = namePrefix + UUID.randomUUID() + originUserId.getName();
} while (storage.getUser(new UserId(name)) != null);
// Retrieve original user and its effective permissions
// Copy inherited permissions
Set<ConqueryPermission> copiedPermission = new HashSet<>();
copiedPermission.addAll(originUser.getEffectivePermissions());
// Give read permission to all executions the original user owned
copiedPermission.addAll(storage.getAllExecutions().stream().filter(originUser::isOwner).map(exc -> exc.createPermission(Ability.READ.asSet())).collect(Collectors.toSet()));
// Give read permission to all form configs the original user owned
copiedPermission.addAll(storage.getAllFormConfigs().stream().filter(originUser::isOwner).map(conf -> conf.createPermission(Ability.READ.asSet())).collect(Collectors.toSet()));
// Create copied user
User copy = new User(name, originUser.getLabel(), storage);
storage.addUser(copy);
copy.updatePermissions(copiedPermission);
return copy;
}
use of com.bakdata.conquery.models.auth.permissions.ConqueryPermission in project conquery by bakdata.
the class AuthorizationHelper method getEffectiveUserPermissions.
/**
* Returns a list of the effective permissions. These are the permissions of the owner and
* the permission of the roles it inherits. The query can be filtered by the Permission domain.
* @return Owned and inherited permissions.
*/
public static Multimap<String, ConqueryPermission> getEffectiveUserPermissions(User user, List<String> domainSpecifier, MetaStorage storage) {
Set<ConqueryPermission> permissions = user.getEffectivePermissions();
Multimap<String, ConqueryPermission> mappedPerms = ArrayListMultimap.create();
for (ConqueryPermission perm : permissions) {
Set<String> domains = perm.getDomains();
if (!Collections.disjoint(domainSpecifier, perm.getDomains())) {
for (String domain : domains) {
mappedPerms.put(domain, perm);
}
}
}
return mappedPerms;
}
Aggregations