org.molgenis.data.security.auth.UserValidator Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of molgenis-data-security Show documentation
Show all versions of molgenis-data-security Show documentation
Security data model and data layer security.
package org.molgenis.data.security.auth;
import static org.molgenis.security.core.utils.SecurityUtils.currentUserIsSuOrSystem;
import org.springframework.stereotype.Component;
@Component
class UserValidator {
void validate(User user) {
validateAddOrUpdate(user);
}
void validate(User user, User updatedUser) {
validateAddOrUpdate(user);
validateUpdate(user, updatedUser);
}
private void validateAddOrUpdate(User user) {
if (user.isSuperuser() && !currentUserIsSuOrSystem()) {
throw new UserSuModificationException(user);
}
}
private void validateUpdate(User user, User updatedUser) {
if (!user.isSuperuser() && updatedUser.isSuperuser() && !currentUserIsSuOrSystem()) {
throw new UserSuModificationException(user);
}
}
}