Skip to content

Commit

Permalink
Merge pull request #3106 from Vojtech-Sassmann/generalSponsorship
Browse files Browse the repository at this point in the history
Core - general sponsorship
  • Loading branch information
Vojtech-Sassmann committed Mar 3, 2021
2 parents 81099ae + ac7e5af commit f7f36e0
Show file tree
Hide file tree
Showing 17 changed files with 707 additions and 258 deletions.
Expand Up @@ -6,11 +6,13 @@
public class NamespaceRules {

private String namespaceName;
private String defaultEmail;
private Set<String> requiredAttributes;
private Set<String> optionalAttributes;

public NamespaceRules(String namespaceName, Set<String> requiredAttributes, Set<String> optionalAttributes) {
public NamespaceRules(String namespaceName, String defaultEmail, Set<String> requiredAttributes, Set<String> optionalAttributes) {
this.namespaceName = namespaceName;
this.defaultEmail = defaultEmail;
this.requiredAttributes = requiredAttributes;
this.optionalAttributes = optionalAttributes;
}
Expand Down Expand Up @@ -60,4 +62,12 @@ public String toString() {
", optionalAttributes=" + optionalAttributes +
'}';
}

public String getDefaultEmail() {
return defaultEmail;
}

public void setDefaultEmail(String defaultEmail) {
this.defaultEmail = defaultEmail;
}
}
@@ -0,0 +1,102 @@
package cz.metacentrum.perun.core.api;

/**
* @author Vojtech Sassmann <vojtech.sassmann@gmail.com>
*/
public class SponsoredUserData {

private String guestName;
private String firstName;
private String lastName;
private String titleBefore;
private String titleAfter;
private String namespace;
private String email;
private String password;
private String login;

public SponsoredUserData() {}
public SponsoredUserData(String guestName, String firstName, String lastName, String titleBefore, String titleAfter, String namespace, String email, String password, String login) {
this.guestName = guestName;
this.firstName = firstName;
this.lastName = lastName;
this.titleBefore = titleBefore;
this.titleAfter = titleAfter;
this.namespace = namespace;
this.email = email;
this.password = password;
this.login = login;
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String firstName) {
this.firstName = firstName;
}

public String getLastName() {
return lastName;
}

public void setLastName(String lastName) {
this.lastName = lastName;
}

public String getTitleBefore() {
return titleBefore;
}

public void setTitleBefore(String titleBefore) {
this.titleBefore = titleBefore;
}

public String getTitleAfter() {
return titleAfter;
}

public void setTitleAfter(String titleAfter) {
this.titleAfter = titleAfter;
}

public String getLogin() {
return login;
}

public void setLogin(String login) {
this.login = login;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public String getNamespace() {
return namespace;
}

public void setNamespace(String namespace) {
this.namespace = namespace;
}

public String getGuestName() {
return guestName;
}

public void setGuestName(String guestName) {
this.guestName = guestName;
}
}
@@ -0,0 +1,29 @@
package cz.metacentrum.perun.core.api.exceptions;

/**
* @author Vojtech Sassmann <vojtech.sassmann@gmail.com>
*/
public class InvalidSponsoredUserDataException extends PerunException {

static final long serialVersionUID = 0;

public InvalidSponsoredUserDataException() {
}

public InvalidSponsoredUserDataException(String message) {
super(message);
}

public InvalidSponsoredUserDataException(String message, Throwable cause) {
super(message, cause);
}

public InvalidSponsoredUserDataException(Throwable cause) {
super(cause);
}

@Override
public String getFriendlyMessageTemplate() {
return "Invalid data provided for the creation of a sponsored user.";
}
}
45 changes: 44 additions & 1 deletion perun-base/src/test/resources/sponsored-accounts-config.yml
@@ -1,7 +1,50 @@
---
# Namespace rules which are used to determine, which information is needed
# for each namespace during sponsorship of a new user. These information are generally
# used to create an external account.
#
#
# default_email - this field determines, which email will be set as a preferred attribute, for the generated sponsored
# user. If this value is not specified, it fallbacks to 'no-reply@perun-aai.org'
# required_attributes - fields from the SponsoredUserData class, which are required for the given namespace during the
# creation of a sponsorship. Allowed values are fields of the SponsoredUserData class. This
# should be mainly used in GUI to determine, which items should be visible in the dialog. But, it
# is also used in the backend to validate the RPC input data. The value of these fields has to
# be provided and only these fields should be used in the namespace's implementation. The only
# exception is the 'password' which doesn't have to be provided, if the user will receive an
# activation link.
# optional_attributes - fields from the SponsoredUserData class, which are optional for the given namespace during the
# creation of a sponsorship. Allowed values are fields of the SponsoredUserData class. This is
# used only in GUI! It doesn't affect anything on the backend, since the optional attributes are
# limited by the actual fields of the SponsoredUserData class. These values can be omitted and it
# should be still possible to create a sponsored user.
#
# Currently allowed fields are:
# * guestName
# * firstName
# * lastName
# * titleBefore
# * titleAfter
# * email
# * password
# * login
#
# If some namespace would require an additional information, some steps are needed to be done:
# 1.A new field has to be added to the SponsoredUserData class
# 2 GUI has to edit the dialog accordingly
# 3.This configuration has to be updated for the namespaces which need this new field
# 4.Update the list of the currently allowed fields above.
#
namespaces:

dummy_namespace:
dummy:
default_email: "no-reply@dummy.com"
required_attributes: []
optional_attributes:
- password

dummy_with_login:
default_email: "no-reply@dummy.com"
required_attributes:
- login
optional_attributes:
Expand Down
Expand Up @@ -10,6 +10,7 @@
import cz.metacentrum.perun.core.api.exceptions.GroupResourceMismatchException;
import cz.metacentrum.perun.core.api.exceptions.InternalErrorException;
import cz.metacentrum.perun.core.api.exceptions.InvalidLoginException;
import cz.metacentrum.perun.core.api.exceptions.InvalidSponsoredUserDataException;
import cz.metacentrum.perun.core.api.exceptions.LoginNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.MemberAlreadyRemovedException;
import cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException;
Expand Down Expand Up @@ -1151,12 +1152,9 @@ public interface MembersManager {
* Creates a new sponsored Member and its User.
* @param session actor
* @param vo virtual organization for the member
* @param namespace namespace for selecting password module
* @param name a map containing the full name or its parts (mandatory: firstName, lastName; optionally: titleBefore, titleAfter)
* @param password password, if the password is empty, and the `sendActivationLink` is set to true, this method will
* generate a random password for the created user
* @param email (optional) preferred email that will be set to the created user. If no email
* is provided, "no-reply@muni.cz" is used.
* @param data about the user that should be created, required fields depend on the
* provided namespace. However, it has to contain either `guestName`, or `firstName` and `lastName`.
* Also, if you want to create an external account, specify the `namespace` field.
* @param sponsor sponsoring user or null for the caller
* @param validityTo last day when the sponsorship is active (null means the sponsorship will last forever)
* @param sendActivationLink if true link for manual activation of account will be send to the email
Expand All @@ -1175,7 +1173,7 @@ public interface MembersManager {
* @throws UserNotInRoleException
* @throws AlreadySponsorException
*/
RichMember createSponsoredMember(PerunSession session, Vo vo, String namespace, Map<String, String> name, String password, String email, User sponsor, LocalDate validityTo, boolean sendActivationLink, String url) throws PrivilegeException, AlreadyMemberException, LoginNotExistsException, PasswordCreationFailedException, ExtendMembershipException, WrongAttributeValueException, ExtSourceNotExistsException, WrongReferenceAttributeValueException, UserNotInRoleException, PasswordStrengthException, InvalidLoginException, AlreadySponsorException;
RichMember createSponsoredMember(PerunSession session, SponsoredUserData data, Vo vo, User sponsor, LocalDate validityTo, boolean sendActivationLink, String url) throws PrivilegeException, AlreadyMemberException, LoginNotExistsException, PasswordCreationFailedException, ExtendMembershipException, WrongAttributeValueException, ExtSourceNotExistsException, WrongReferenceAttributeValueException, UserNotInRoleException, PasswordStrengthException, InvalidLoginException, AlreadySponsorException, InvalidSponsoredUserDataException, NamespaceRulesNotExistsException;

/**
* Creates a sponsored membership for the given user.
Expand All @@ -1185,6 +1183,7 @@ public interface MembersManager {
* @param userToBeSponsored user, that will be sponsored by sponsor
* @param namespace namespace for selecting password module
* @param password password
* @param login login
* @param sponsor sponsoring user or null for the caller
* @param validityTo last day when the sponsorship is active (null means the sponsorship will last forever)
*
Expand All @@ -1203,7 +1202,7 @@ public interface MembersManager {
* @throws InvalidLoginException
* @throws AlreadySponsorException
*/
RichMember setSponsoredMember(PerunSession session, Vo vo, User userToBeSponsored, String namespace, String password, User sponsor, LocalDate validityTo) throws PrivilegeException, AlreadyMemberException, LoginNotExistsException, PasswordCreationFailedException, ExtendMembershipException, WrongAttributeValueException, ExtSourceNotExistsException, WrongReferenceAttributeValueException, UserNotInRoleException, PasswordStrengthException, InvalidLoginException, AlreadySponsorException;
RichMember setSponsoredMember(PerunSession session, Vo vo, User userToBeSponsored, String namespace, String password, String login, User sponsor, LocalDate validityTo) throws PrivilegeException, AlreadyMemberException, LoginNotExistsException, PasswordCreationFailedException, ExtendMembershipException, WrongAttributeValueException, ExtSourceNotExistsException, WrongReferenceAttributeValueException, UserNotInRoleException, PasswordStrengthException, InvalidLoginException, AlreadySponsorException, InvalidSponsoredUserDataException, NamespaceRulesNotExistsException;

/**
* Creates new sponsored members using input from CSV file.
Expand Down

0 comments on commit f7f36e0

Please sign in to comment.