All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.molgenis.data.security.auth.UserValidator Maven / Gradle / Ivy

There is a newer version: 8.4.5
Show newest version
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);
    }
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy