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);
}
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);
}
}
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);
}
Aggregations