Search in sources :

Example 1 with PasswordResetMailNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.PasswordResetMailNotExistsException in project perun by CESNET.

the class MembersManagerEntry method sendAccountActivationLinkEmail.

@Override
public void sendAccountActivationLinkEmail(PerunSession sess, Member member, String namespace, String url, String mailAttributeUrn, String language) throws PrivilegeException, MemberNotExistsException, UserNotExistsException, AttributeNotExistsException, PasswordResetMailNotExistsException {
    Utils.checkPerunSession(sess);
    getMembersManagerBl().checkMemberExists(sess, member);
    // Authorization
    if (!AuthzResolver.authorizedInternal(sess, "sendAccountActivationLinkEmail_Member_String_String_String_String_policy", member)) {
        throw new PrivilegeException(sess, "sendAccountActivationLinkEmail");
    }
    // check if attribute exists, throws AttributeNotExistsException
    Attribute mailAttribute = null;
    AttributeDefinition attributeDefinition = getPerunBl().getAttributesManager().getAttributeDefinition(sess, mailAttributeUrn);
    try {
        if (attributeDefinition.getEntity().equals("user")) {
            User user = perunBl.getUsersManagerBl().getUserByMember(sess, member);
            mailAttribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, mailAttributeUrn);
        }
        if (attributeDefinition.getEntity().equals("member")) {
            mailAttribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, member, mailAttributeUrn);
        }
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    }
    if (mailAttribute == null) {
        throw new InternalErrorException("MailAttribute should not be null.");
    }
    String mailAddress = mailAttribute.valueAsString();
    if (mailAddress == null) {
        throw new PasswordResetMailNotExistsException("Member " + member.getId() + " doesn't have the attribute " + mailAttributeUrn + " set.");
    }
    getMembersManagerBl().sendAccountActivationLinkEmail(sess, member, namespace, url, mailAddress, language);
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) PasswordResetMailNotExistsException(cz.metacentrum.perun.core.api.exceptions.PasswordResetMailNotExistsException)

Example 2 with PasswordResetMailNotExistsException

use of cz.metacentrum.perun.core.api.exceptions.PasswordResetMailNotExistsException in project perun by CESNET.

the class MembersManagerEntry method sendPasswordResetLinkEmail.

@Override
public void sendPasswordResetLinkEmail(PerunSession sess, Member member, String namespace, String url, String mailAttributeUrn, String language) throws PrivilegeException, MemberNotExistsException, UserNotExistsException, AttributeNotExistsException, PasswordResetMailNotExistsException {
    Utils.checkPerunSession(sess);
    getMembersManagerBl().checkMemberExists(sess, member);
    // Authorization
    if (!AuthzResolver.authorizedInternal(sess, "sendPasswordResetLinkEmail_Member_String_String_String_String_policy", member)) {
        throw new PrivilegeException(sess, "sendPasswordResetLinkEmail");
    }
    // check if attribute exists, throws AttributeNotExistsException
    Attribute mailAttribute = null;
    AttributeDefinition ad = getPerunBl().getAttributesManager().getAttributeDefinition(sess, mailAttributeUrn);
    try {
        if (ad.getEntity().equals("user")) {
            User user = perunBl.getUsersManagerBl().getUserByMember(sess, member);
            mailAttribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, user, mailAttributeUrn);
        }
        if (ad.getEntity().equals("member")) {
            mailAttribute = getPerunBl().getAttributesManagerBl().getAttribute(sess, member, mailAttributeUrn);
        }
    } catch (WrongAttributeAssignmentException ex) {
        throw new InternalErrorException(ex);
    }
    if (mailAttribute == null) {
        throw new InternalErrorException("MailAttribute should not be null.");
    }
    String mailAddress = mailAttribute.valueAsString();
    if (mailAddress == null) {
        throw new PasswordResetMailNotExistsException("Member " + member.getId() + " doesn't have the attribute " + mailAttributeUrn + " set.");
    }
    getMembersManagerBl().sendPasswordResetLinkEmail(sess, member, namespace, url, mailAddress, language);
}
Also used : User(cz.metacentrum.perun.core.api.User) Attribute(cz.metacentrum.perun.core.api.Attribute) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) AttributeDefinition(cz.metacentrum.perun.core.api.AttributeDefinition) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) PasswordResetMailNotExistsException(cz.metacentrum.perun.core.api.exceptions.PasswordResetMailNotExistsException)

Aggregations

Attribute (cz.metacentrum.perun.core.api.Attribute)2 AttributeDefinition (cz.metacentrum.perun.core.api.AttributeDefinition)2 User (cz.metacentrum.perun.core.api.User)2 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 PasswordResetMailNotExistsException (cz.metacentrum.perun.core.api.exceptions.PasswordResetMailNotExistsException)2 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)2 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)2