Search in sources :

Example 6 with CantBeApprovedException

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

the class Metacentrum method canBeApproved.

@Override
public void canBeApproved(PerunSession session, Application app) throws PerunException {
    // allow hostel with loa=2
    if (Objects.equals(app.getExtSourceName(), "https://idp.hostel.eduid.cz/idp/shibboleth") && app.getExtSourceLoa() == 2)
        return;
    List<ApplicationFormItemData> data = registrar.getApplicationDataById(session, app.getId());
    String category = "";
    String affiliation = "";
    for (ApplicationFormItemData item : data) {
        if (item.getFormItem() != null && Objects.equals("md_entityCategory", item.getFormItem().getFederationAttribute())) {
            if (item.getValue() != null && !item.getValue().trim().isEmpty()) {
                category = item.getValue();
                break;
            }
        }
    }
    for (ApplicationFormItemData item : data) {
        if (item.getFormItem() != null && Objects.equals("affiliation", item.getFormItem().getFederationAttribute())) {
            if (item.getValue() != null && !item.getValue().trim().isEmpty()) {
                affiliation = item.getValue();
                break;
            }
        }
    }
    if (category.contains("http://eduid.cz/uri/idp-group/university")) {
        if (affiliation.contains("employee@") || affiliation.contains("faculty@") || affiliation.contains("member@") || affiliation.contains("student@") || affiliation.contains("staff@"))
            return;
    } else if (category.contains("http://eduid.cz/uri/idp-group/avcr")) {
        if (affiliation.contains("member@"))
            return;
    } else if (category.contains("http://eduid.cz/uri/idp-group/library")) {
        if (affiliation.contains("employee@"))
            return;
    } else if (category.contains("http://eduid.cz/uri/idp-group/hospital")) {
        if (affiliation.contains("employee@"))
            return;
    } else if (category.contains("http://eduid.cz/uri/idp-group/other")) {
        if (affiliation.contains("employee@") || affiliation.contains("member@"))
            return;
    }
    throw new CantBeApprovedException("User is not active academia member", "NOT_ACADEMIC", category, affiliation, true);
}
Also used : CantBeApprovedException(cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException) ApplicationFormItemData(cz.metacentrum.perun.registrar.model.ApplicationFormItemData)

Example 7 with CantBeApprovedException

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

the class Ceitec method canBeApproved.

@Override
public void canBeApproved(PerunSession session, Application app) throws PerunException {
    List<ApplicationFormItemData> data = registrar.getApplicationDataById(session, app.getId());
    String name = "";
    String fed_name = "";
    for (ApplicationFormItemData item : data) {
        if (Objects.equals(item.getShortname(), "jmeno")) {
            name = item.getValue();
        }
        if (Objects.equals(item.getShortname(), "jmeno_fed")) {
            fed_name = item.getValue();
        }
    }
    if (!Objects.equals(name, fed_name)) {
        throw new CantBeApprovedException("Users name provided by IdP and User differ. Please check for correct name before approval.", "", "", "", true);
    }
}
Also used : CantBeApprovedException(cz.metacentrum.perun.registrar.exceptions.CantBeApprovedException) ApplicationFormItemData(cz.metacentrum.perun.registrar.model.ApplicationFormItemData)

Example 8 with CantBeApprovedException

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

the class Du method beforeApprove.

@Override
public Application beforeApprove(PerunSession session, Application app) throws CantBeApprovedException, RegistrarException, PrivilegeException {
    // 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 app;
            }
        } 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.", "NOT_ELIGIBLE", null, null);
}
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)

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