pl.allegro.tech.hermes.management.domain.group.GroupValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hermes-management Show documentation
Show all versions of hermes-management Show documentation
Fast and reliable message broker built on top of Kafka.
package pl.allegro.tech.hermes.management.domain.group;
import org.springframework.stereotype.Component;
import pl.allegro.tech.hermes.api.Group;
import pl.allegro.tech.hermes.domain.group.GroupAlreadyExistsException;
import pl.allegro.tech.hermes.domain.group.GroupRepository;
import pl.allegro.tech.hermes.management.api.auth.CreatorRights;
import pl.allegro.tech.hermes.management.config.GroupProperties;
import pl.allegro.tech.hermes.management.domain.PermissionDeniedException;
@Component
public class GroupValidator {
private final GroupRepository repository;
private final GroupNameValidator groupNameValidator;
public GroupValidator(GroupRepository repository, GroupProperties groupProperties) {
this.repository = repository;
this.groupNameValidator = new GroupNameValidator(groupProperties.getAllowedGroupNameRegex());
}
public void checkCreation(Group toCheck, CreatorRights creatorRights) {
groupNameValidator.requireValid(toCheck.getGroupName());
if (!creatorRights.allowedToCreate(toCheck)) {
throw new PermissionDeniedException("You are not allowed to create groups");
}
if (repository.groupExists(toCheck.getGroupName())) {
throw new GroupAlreadyExistsException(toCheck.getGroupName());
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy