Search in sources :

Example 1 with CantBeApprovedException

use of cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException in project perun by CESNET.

the class BBMRICollections method canBeApproved.

/**
 * Checks whether all collection IDs found in user input really exists in Perun.
 * If not, CantBeApproved exception is thrown.
 *
 * @param session who approves the application
 * @param app     unchanged application
 * @throws CantBeApprovedException if at least one collection ID does not exist in Perun
 */
public void canBeApproved(PerunSession session, Application app) throws PerunException {
    // get perun and beans from session
    PerunBl perun = (PerunBl) session.getPerun();
    Vo vo = app.getVo();
    // get all collection IDs from Perun
    String directoryGroupName = getDirectoryGroupNameFromApplication(session, app);
    Group directoryGroup;
    try {
        directoryGroup = perun.getGroupsManager().getGroupByName(session, vo, directoryGroupName);
    } catch (GroupNotExistsException e) {
        throw new InternalErrorException("Target group does not exist");
    }
    Set<String> collectionIDsInPerun = getCollectionIDs(session, perun, directoryGroup);
    // get the field of application with the collections
    Set<String> collectionIDsInApplication = getCollectionIDsFromApplication(session, app);
    // get non-existing collections
    collectionIDsInApplication.removeAll(collectionIDsInPerun);
    // difference must be empty
    if (!collectionIDsInApplication.isEmpty()) {
        throw new CantBeApprovedException("Collections " + collectionIDsInApplication + " do not exist." + "If you approve the application, these collections will be skipped.", "", "", "", true);
    }
}
Also used : GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) CantBeApprovedException(cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException)

Example 2 with CantBeApprovedException

use of cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException in project perun by CESNET.

the class BBMRINetworks method canBeApproved.

/**
 * Checks whether all network IDs found in user input really exists in Perun.
 * If not, CantBeApproved exception is thrown.
 *
 * @param session who approves the application
 * @param app     unchanged application
 * @throws CantBeApprovedException if at least one network ID does not exist in Perun
 */
public void canBeApproved(PerunSession session, Application app) throws PerunException {
    // get perun and beans from session
    PerunBl perun = (PerunBl) session.getPerun();
    Vo vo = app.getVo();
    // get all network IDs from Perun
    Group networksGroup = perun.getGroupsManagerBl().getGroupByName(session, vo, NETWORKS_GROUP_NAME);
    Set<String> neworksIDsInPerun = getNetworkIDs(session, perun, networksGroup);
    // get the field of application with the collections
    Set<String> networkIDsInApplication = getNetworkIDsFromApplication(session, app);
    // get non-existing collections
    networkIDsInApplication.removeAll(neworksIDsInPerun);
    // difference must be empty
    if (!networkIDsInApplication.isEmpty()) {
        throw new CantBeApprovedException("Networks with IDs: " + networkIDsInApplication + " do not exist." + "If you approve the application, these networks will be skipped.", "", "", "", true);
    }
}
Also used : Group(cz.metacentrum.perun.core.api.Group) CantBeApprovedException(cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) Vo(cz.metacentrum.perun.core.api.Vo)

Example 3 with CantBeApprovedException

use of cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException in project perun by CESNET.

the class DuSoft method canBeApproved.

@Override
public void canBeApproved(PerunSession session, Application app) throws RegistrarException, PrivilegeException, CantBeApprovedException {
    // allow only Education & Research community members
    List<ApplicationFormItemData> data = registrar.getApplicationDataById(session, app.getId());
    String eligibleString = "";
    for (ApplicationFormItemData item : data) {
        if (item.getFormItem() != null && Objects.equals("isCesnetEligibleLastSeen", item.getFormItem().getFederationAttribute())) {
            if (item.getValue() != null && !item.getValue().trim().isEmpty()) {
                eligibleString = item.getValue();
                break;
            }
        }
    }
    if (eligibleString != null && !eligibleString.isEmpty()) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        df.setLenient(false);
        try {
            // get eligible date + 1 year
            Date eligibleDate = df.parse(eligibleString);
            LocalDateTime timeInOneYear = LocalDateTime.ofInstant(eligibleDate.toInstant(), ZoneId.systemDefault()).plusYears(1);
            // compare
            if (LocalDateTime.now().isBefore(timeInOneYear)) {
                return;
            }
        } catch (ParseException e) {
            log.warn("Unable to parse date to determine, if user is eligible for CESNET services.", e);
        }
    }
    throw new CantBeApprovedException("User is not eligible for CESNET services. User must log-in using verified academic identity (at least once a year) in order to access CESNET services.", "NOT_ELIGIBLE", null, null, true);
}
Also used : LocalDateTime(java.time.LocalDateTime) CantBeApprovedException(cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ApplicationFormItemData(cz.metacentrum.perun.registrar.model.ApplicationFormItemData) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date)

Example 4 with CantBeApprovedException

use of cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException in project perun by CESNET.

the class ElixirBonaFideStatus method beforeApprove.

@Override
public Application beforeApprove(PerunSession session, Application app) throws CantBeApprovedException {
    Group group = app.getGroup();
    if (group == null) {
        throw new CantBeApprovedException("This module can be set only for registration to Group.");
    }
    AttributesManagerBl am = ((PerunBl) session.getPerun()).getAttributesManagerBl();
    Attribute attestation;
    try {
        attestation = am.getAttribute(session, group, A_G_D_groupAttestation);
    } catch (Exception e) {
        throw new InternalErrorException(e.getMessage(), e);
    }
    if (attestation == null) {
        throw new CantBeApprovedException("Application cannot be approved: Group does not have attestation attribute set.");
    }
    String newValue = attestation.valueAsString();
    if (newValue == null || newValue.isEmpty()) {
        throw new CantBeApprovedException("Application cannot be approved: Group does not have attestation value set.");
    }
    return app;
}
Also used : Group(cz.metacentrum.perun.core.api.Group) CantBeApprovedException(cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException) Attribute(cz.metacentrum.perun.core.api.Attribute) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) InternalErrorException(cz.metacentrum.perun.core.api.exceptions.InternalErrorException) GroupNotExistsException(cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException) WrongReferenceAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException) AttributeNotExistsException(cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException) WrongAttributeValueException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException) PrivilegeException(cz.metacentrum.perun.core.api.exceptions.PrivilegeException) CantBeSubmittedException(cz.metacentrum.perun.registrar.exceptions.CantBeSubmittedException) UserNotExistsException(cz.metacentrum.perun.core.api.exceptions.UserNotExistsException) WrongAttributeAssignmentException(cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException) PerunException(cz.metacentrum.perun.core.api.exceptions.PerunException) CantBeApprovedException(cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException) AttributesManagerBl(cz.metacentrum.perun.core.bl.AttributesManagerBl)

Example 5 with CantBeApprovedException

use of cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException in project perun by CESNET.

the class WeNMR method canBeApproved.

@Override
public void canBeApproved(PerunSession session, Application app) throws PerunException {
    // check if submitted from trusted IdP
    if (!Objects.equals("https://www.structuralbiology.eu/idp/shibboleth", app.getExtSourceName())) {
        // submitted by untrusted IdP
        PerunBl perun = (PerunBl) session.getPerun();
        User user;
        // check if user is known
        if (app.getUser() != null) {
            user = app.getUser();
        } else {
            try {
                user = perun.getUsersManagerBl().getUserByExtSourceNameAndExtLogin(session, app.getExtSourceName(), app.getCreatedBy());
            } catch (Exception ex) {
                // unable to find user -> untrusted IdP
                throw new CantBeApprovedException("Application can't be approved automatically. User doesn't have identity from \"www.structuralbiology.eu\". Please check users identity before manual/force approval.", "", "", "", true);
            }
        }
        List<UserExtSource> ueses = perun.getUsersManagerBl().getUserExtSources(session, user);
        for (UserExtSource ues : ueses) {
            if (Objects.equals("https://www.structuralbiology.eu/idp/shibboleth", ues.getExtSource().getName())) {
                // user has trusted identity
                return;
            }
        }
        throw new CantBeApprovedException("Application can't be approved automatically. User doesn't have identity from \"www.structuralbiology.eu\". Please check users identity before manual/force approval.", "", "", "", true);
    }
// submitted from trusted IdP
}
Also used : User(cz.metacentrum.perun.core.api.User) CantBeApprovedException(cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException) UserExtSource(cz.metacentrum.perun.core.api.UserExtSource) PerunBl(cz.metacentrum.perun.core.bl.PerunBl) PerunException(cz.metacentrum.perun.core.api.exceptions.PerunException) CantBeApprovedException(cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException)

Aggregations

CantBeApprovedException (cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException)8 PerunBl (cz.metacentrum.perun.core.bl.PerunBl)4 ApplicationFormItemData (cz.metacentrum.perun.registrar.model.ApplicationFormItemData)4 Group (cz.metacentrum.perun.core.api.Group)2 GroupNotExistsException (cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException)2 InternalErrorException (cz.metacentrum.perun.core.api.exceptions.InternalErrorException)2 PerunException (cz.metacentrum.perun.core.api.exceptions.PerunException)2 DateFormat (java.text.DateFormat)2 ParseException (java.text.ParseException)2 SimpleDateFormat (java.text.SimpleDateFormat)2 LocalDateTime (java.time.LocalDateTime)2 Date (java.util.Date)2 Attribute (cz.metacentrum.perun.core.api.Attribute)1 User (cz.metacentrum.perun.core.api.User)1 UserExtSource (cz.metacentrum.perun.core.api.UserExtSource)1 Vo (cz.metacentrum.perun.core.api.Vo)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 PrivilegeException (cz.metacentrum.perun.core.api.exceptions.PrivilegeException)1 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)1 WrongAttributeAssignmentException (cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException)1