use of cz.metacentrum.perun.core.api.exceptions.InvalidSponsoredUserDataException in project perun by CESNET.
the class MembersManagerBlImpl method createSponsoredMember.
@Override
public Member createSponsoredMember(PerunSession sess, SponsoredUserData data, Vo vo, User sponsor, LocalDate validityTo, boolean sendActivationLink, String url, Validation validation) throws AlreadyMemberException, LoginNotExistsException, PasswordCreationFailedException, ExtendMembershipException, WrongAttributeValueException, ExtSourceNotExistsException, WrongReferenceAttributeValueException, UserNotInRoleException, InvalidLoginException, AlreadySponsorException, InvalidSponsoredUserDataException, NamespaceRulesNotExistsException, PasswordStrengthException {
User createdUser = createUser(sess, data);
String email = setEmailForUser(sess, createdUser, data.getEmail(), data.getNamespace());
if (isBlank(data.getPassword()) && isNotBlank(data.getNamespace())) {
NamespaceRules rules = getNamespaceRules(data.getNamespace());
if (rules.getRequiredAttributes().contains("password")) {
if (!sendActivationLink) {
throw new InvalidSponsoredUserDataException("Password is required but not provided.");
}
var module = perunBl.getUsersManagerBl().getPasswordManagerModule(sess, data.getNamespace());
var randomPassword = module.generateRandomPassword(sess, data.getLogin());
data.setPassword(randomPassword);
}
}
Member sponsoredMember = setSponsoredMember(sess, data, vo, createdUser, sponsor, validityTo, validation);
if (sendActivationLink) {
// TODO: at this moment there is missing way how to specify if email should be in different language than english
String defaultLanguage = "en";
sendAccountActivationLinkEmail(sess, sponsoredMember, data.getNamespace(), url, email, defaultLanguage);
}
return sponsoredMember;
}
Aggregations