Skip to content

Commit

Permalink
Merge pull request #3034 from zlamalp/meta2
Browse files Browse the repository at this point in the history
REGISTRAR: Modified Metacentrum workflow
  • Loading branch information
zlamalp committed Jan 4, 2021
1 parent b4217e3 commit 3179849
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cz.metacentrum.perun.registrar.modules;

import cz.metacentrum.perun.core.api.Attribute;
import cz.metacentrum.perun.core.api.PerunSession;
import cz.metacentrum.perun.core.api.User;
import cz.metacentrum.perun.core.api.exceptions.AlreadyAdminException;
import cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException;
import cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.ExtSourceNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException;
import cz.metacentrum.perun.core.api.exceptions.ExternallyManagedException;
import cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.NotGroupMemberException;
import cz.metacentrum.perun.core.api.exceptions.PrivilegeException;
import cz.metacentrum.perun.core.api.exceptions.UserNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.VoNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException;
import cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException;
import cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException;
import cz.metacentrum.perun.core.bl.PerunBl;
import cz.metacentrum.perun.registrar.exceptions.RegistrarException;
import cz.metacentrum.perun.registrar.impl.RegistrarManagerImpl;
import cz.metacentrum.perun.registrar.model.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

import static cz.metacentrum.perun.registrar.modules.Metacentrum.A_USER_IS_CESNET_ELIGIBLE_LAST_SEEN;

public class EinfraVerified extends DefaultRegistrarModule {

private final static Logger log = LoggerFactory.getLogger(EinfraVerified.class);

@Override
public Application approveApplication(PerunSession session, Application app) throws UserNotExistsException, PrivilegeException, AlreadyAdminException, GroupNotExistsException, VoNotExistsException, MemberNotExistsException, AlreadyMemberException, ExternallyManagedException, WrongAttributeValueException, WrongAttributeAssignmentException, AttributeNotExistsException, WrongReferenceAttributeValueException, RegistrarException, ExtendMembershipException, ExtSourceNotExistsException, NotGroupMemberException {

PerunBl perun = (PerunBl) session.getPerun();
User user = app.getUser();

// format now
LocalDateTime now = LocalDateTime.now();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
String eligibleValue = now.format(formatter);

// set attribute
Attribute attribute = perun.getAttributesManagerBl().getAttribute(session, user, A_USER_IS_CESNET_ELIGIBLE_LAST_SEEN);
attribute.setValue(eligibleValue);
perun.getAttributesManagerBl().setAttribute(session, user, attribute);

return app;

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@
import cz.metacentrum.perun.core.api.*;
import cz.metacentrum.perun.core.api.exceptions.AlreadyMemberException;
import cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.ExtendMembershipException;
import cz.metacentrum.perun.core.api.exceptions.ExternallyManagedException;
import cz.metacentrum.perun.core.api.exceptions.GroupNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.InternalErrorException;
import cz.metacentrum.perun.core.api.exceptions.MemberNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.PerunException;
import cz.metacentrum.perun.core.api.exceptions.PrivilegeException;
import cz.metacentrum.perun.core.api.exceptions.VoNotExistsException;
import cz.metacentrum.perun.core.api.exceptions.WrongAttributeAssignmentException;
import cz.metacentrum.perun.core.api.exceptions.WrongAttributeValueException;
import cz.metacentrum.perun.core.api.exceptions.WrongReferenceAttributeValueException;
Expand Down Expand Up @@ -51,7 +53,7 @@ public class Metacentrum extends DefaultRegistrarModule {
private final static String A_USER_RESEARCH_GROUP_STATISTICS = AttributesManager.NS_USER_ATTR_DEF+":researchGroupStatistic";
private final static String A_GROUP_STATISTIC_GROUP = AttributesManager.NS_GROUP_ATTR_DEF+":statisticGroup";
private final static String A_GROUP_STATISTIC_GROUP_AUTOFILL = AttributesManager.NS_GROUP_ATTR_DEF+":statisticGroupAutoFill";
private final static String A_USER_IS_CESNET_ELIGIBLE_LAST_SEEN = AttributesManager.NS_USER_ATTR_DEF+":isCesnetEligibleLastSeen";
protected final static String A_USER_IS_CESNET_ELIGIBLE_LAST_SEEN = AttributesManager.NS_USER_ATTR_DEF+":isCesnetEligibleLastSeen";
private final static String A_MEMBER_MEMBERSHIP_EXPIRATION = AttributesManager.NS_MEMBER_ATTR_DEF+":membershipExpiration";
protected final static String METACENTRUM_IDP = "https://login.ics.muni.cz/idp/shibboleth";

Expand Down Expand Up @@ -104,6 +106,21 @@ public Application approveApplication(PerunSession session, Application app) thr

}

if (Application.AppType.INITIAL.equals(app.getType())) {
try {
Vo einfraVo = perun.getVosManagerBl().getVoByShortName(session, "einfra");
Member einfraMember = perun.getMembersManagerBl().createMember(session, einfraVo, user);
log.debug("Metacentrum member added to einfra {}", einfraMember);
} catch (VoNotExistsException e) {
log.warn("Einfra VO not exists, can't add Metacentrum member into it.");
} catch (AlreadyMemberException ignore) {
// user is already in einfra
} catch (ExtendMembershipException e) {
// can't be member of einfra, shouldn't happen
log.error("Metacentrum member can't be added to EINFRA VO.", e);
}
}

// Support statistic groups
String statisticGroupName = "";

Expand Down Expand Up @@ -162,20 +179,17 @@ public void canBeSubmitted(PerunSession session, Application.AppType appType, Ma
if (METACENTRUM_IDP.equals(session.getPerunPrincipal().getExtSourceName())) {
throw new CantBeSubmittedException("You are currently logged-in using Metacentrum IdP." +
"It can't be used to register or extend membership in Metacentrum. Please close browser and log-in using different identity provider.",
"NOT_ELIGIBLE", null, null);
"NOT_ELIGIBLE_METAIDP", null, null);
}

if (Application.AppType.EXTENSION.equals(appType)) {
User user = session.getPerunPrincipal().getUser();
boolean eligibleUser = isCesnetEligibleLastSeen(getIsCesnetEligibleLastSeenFromUser(session, user));
boolean eligibleFromFederation = isCesnetEligibleLastSeen(params.get("isCesnetEligibleLastSeen"));

User user = session.getPerunPrincipal().getUser();
boolean eligibleUser = isCesnetEligibleLastSeen(getIsCesnetEligibleLastSeenFromUser(session, user));
boolean eligibleFromFederation = isCesnetEligibleLastSeen(params.get("isCesnetEligibleLastSeen"));
if (!eligibleUser && !eligibleFromFederation) {

if (!eligibleUser && !eligibleFromFederation) {
// TODO - We must have much better info in GUI!
throw new CantBeSubmittedException("Your membership in VO Metacentrum can't be extended right now. Your account is not verified." +
" Please visit your profile and add verified academic identity to your account (from identity federation eduID.cz) " +
" or verify your academia status by letter signed by the head of your institution.", "NOT_ELIGIBLE", null, null);
if (Application.AppType.EXTENSION.equals(appType)) {
throw new CantBeSubmittedException("Your membership in VO Metacentrum can't be extended.", "NOT_ELIGIBLE_EINFRA_EXTENSION", null, null);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void canBeSubmitted(PerunSession session, Application.AppType appType, Ma
if (METACENTRUM_IDP.equals(session.getPerunPrincipal().getExtSourceName())) {
throw new CantBeSubmittedException("You are currently logged-in using Metacentrum IdP." +
"It can't be used to register or extend membership in Metacentrum. Please close browser and log-in using different identity provider.",
"NOT_ELIGIBLE", null, null);
"NOT_ELIGIBLE_METAIDP", null, null);
}

}
Expand Down

0 comments on commit 3179849

Please sign in to comment.