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