perunSession = perun.getPerunSession(new PerunPrincipal( dispatcherProperties.getProperty("perun.principal.name"), dispatcherProperties.getProperty("perun.principal.extSourceName"), log.debug("Facility found in event. {}.", facility); facilitiesResolvedFromEvent.add(facility); resourcesResolvedFromEvent.addAll(perun.getFacilitiesManager() .getAssignedResources(perunSession, facility)); } catch (FacilityNotExistsException ex) { resourcesResolvedFromEvent = perun.getResourcesManager() .getAssignedResources(perunSession, group); } catch (GroupNotExistsException ex) { resourcesResolvedFromEvent = perun.getUsersManager() .getAllowedResources(perunSession, user); } catch (UserNotExistsException ex) { resourcesResolvedFromEvent = perun.getResourcesManager() .getAllowedResources(perunSession, member); } catch (MemberNotExistsException ex) { try { log.debug("Host found in event.id= {}.", host.getId()); facility = perun.getFacilitiesManager().getFacilityForHost(perunSession, host); facilitiesResolvedFromEvent.add(facility); resourcesResolvedFromEvent.addAll(perun.getFacilitiesManager() .getAssignedResources(perunSession, facility)); } catch (FacilityNotExistsException ex) {
/** * Gets collections as map of collectionID => Group. * * @return Map of collection IDs to group. */ private Map<String, Group> getCollectionIDsToGroupsMap (PerunSession session, Perun perun, Group collectionsGroup) throws GroupNotExistsException, WrongAttributeAssignmentException, InternalErrorException, AttributeNotExistsException, PrivilegeException { Map<String, Group> collectionIDsToGroupMap = new HashMap<>(); for (Group group : perun.getGroupsManager().getSubGroups(session, collectionsGroup)) { for (Group subgroup : perun.getGroupsManager().getSubGroups(session, group)) { if (REPRESENTATIVES_GROUP_NAME.equals(subgroup.getShortName())) { Attribute collectionID = perun.getAttributesManager().getAttribute(session, subgroup, COLLECTION_ID_ATTR_NAME); collectionIDsToGroupMap.put(collectionID.valueAsString(), subgroup); } } } return collectionIDsToGroupMap; }
@Override public Application approveApplication(PerunSession session, Application app) throws PerunException { // Add new member to groups eduroam-admin and eduroam-announce just if its initial application form if (Application.AppType.INITIAL.equals(app.getType())) { // Get perun and beans from session Perun perun = session.getPerun(); Vo vo = app.getVo(); User user = app.getUser(); Member member = perun.getMembersManager().getMemberByUser(session, vo, user); // Get the groups in which the new member of VO will be automatically added Group eduroamAdmin = perun.getGroupsManager().getGroupByName(session, vo, "eduroam-admin"); Group eduroamAnnounce = perun.getGroupsManager().getGroupByName(session, vo, "eduroam-announce"); // Add member to these groups perun.getGroupsManager().addMember(session, eduroamAdmin, member); perun.getGroupsManager().addMember(session, eduroamAnnounce, member); } return app; }
Group group = perun.getGroupsManager().getGroupByName(session, vo, "storage"); Member mem = perun.getMembersManager().getMemberByUser(session, vo, user); perun.getGroupsManager().addMember(session, group, mem); } catch (AlreadyMemberException ex) { Group group; try { group = perun.getGroupsManager().getGroupByName(session, app.getVo(), statisticGroupName); } catch (GroupNotExistsException ex) { Attribute isStatisticGroup = perun.getAttributesManager().getAttribute(session, group, "urn:perun:group:attribute-def:def:statisticGroup"); Attribute isStatisticGroupAutoFill = perun.getAttributesManager().getAttribute(session, group, "urn:perun:group:attribute-def:def:statisticGroupAutoFill"); Member mem = perun.getMembersManager().getMemberByUser(session, app.getVo(), app.getUser()); perun.getGroupsManager().addMember(session, group, mem); } catch (AlreadyMemberException ex) {
@Override public Application approveApplication(PerunSession sess, Application application) throws PerunException { if (application.getType() == Application.AppType.INITIAL) { List<ApplicationFormItemData> applicationData = registrar.getApplicationDataById(sess, application.getId()); String nickName = null; for (ApplicationFormItemData appItem : applicationData) { if (APPLICATION_NICKNAME_ITEM.equals(appItem.getShortname())) { nickName = appItem.getValue(); } } if (nickName != null && !nickName.trim().isEmpty()) { User user = application.getUser(); Attribute loginAttribute; try { loginAttribute = sess.getPerun().getAttributesManager().getAttribute(sess, user, A_U_D_EDUTEAMS_NICKNAME); } catch (AttributeNotExistsException e) { // do not set the login if the attribute does not exist return application; } loginAttribute.setValue(nickName); sess.getPerun().getAttributesManager().setAttribute(sess, user, loginAttribute); } } return application; }
sess = perun.getPerunSession(new PerunPrincipal( dispatcherProperties.getProperty("perun.principal.name"), dispatcherProperties.getProperty("perun.principal.extSourceName"), Service service = perun.getServicesManager().getServiceById(sess, task.getServiceId()); Facility facility = perun.getFacilitiesManager().getFacilityById(sess, task.getFacilityId()); task.setService(service); task.setFacility(facility); List<Destination> destinations = perun.getServicesManager().getDestinations(sess, task.getService(), task.getFacility()); if (destinations != null && !destinations.isEmpty()) { Iterator<Destination> iter = destinations.iterator(); List<Service> assignedServices = perun.getServicesManager().getAssignedServices(sess, task.getFacility()); if (!assignedServices.contains(task.getService())) { log.debug("[{}] Task NOT added to waiting queue, service is not assigned to facility any more: {}.", task.getId(), task);
sess = perun.getPerunSession(new PerunPrincipal( dispatcherProperties.getProperty("perun.principal.name"), dispatcherProperties.getProperty("perun.principal.extSourceName"), List<Destination> destinations = perun.getServicesManager().getDestinations(sess, service, facility); if (destinations != null && !destinations.isEmpty()) { Iterator<Destination> iter = destinations.iterator();
service = perun.getServicesManager().getServiceById(perunSession, service.getId()); facility = perun.getFacilitiesManager().getFacilityById(perunSession, facility.getId()); task.setService(service); task.setFacility(facility); try { initPerunSession(); destinations = perun.getServicesManager().getDestinations(perunSession, task.getService(), task.getFacility()); } catch (ServiceNotExistsException e) { log.error("[{}] No destinations found for task. Service not exists...", task.getId());
/** * 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 Perun perun = session.getPerun(); Vo vo = app.getVo(); // get all collection IDs from Perun Group collectionsGroup = perun.getGroupsManager().getGroupByName(session, vo, COLLECTIONS_GROUP_NAME); Set<String> collectionIDsInPerun = getCollectionIDs(session, perun, collectionsGroup); // 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); } }
protected void initPerunSession() throws InternalErrorException { if (perunSession == null) { perunSession = perun.getPerunSession(new PerunPrincipal( dispatcherProperties.getProperty("perun.principal.name"), dispatcherProperties.getProperty("perun.principal.extSourceName"), dispatcherProperties.getProperty("perun.principal.extSourceType")), new PerunClient()); } }
@Override public Application beforeApprove(PerunSession session, Application app) throws PerunException { Group group = app.getGroup(); if (group == null) { throw new CantBeApprovedException("This module can be set only for registration to Group."); } AttributesManager am = session.getPerun().getAttributesManager(); Attribute attestation = am.getAttribute(session, group, A_G_D_groupAttestation); 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; }
/** * 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 Perun perun = session.getPerun(); Vo vo = app.getVo(); // get all network IDs from Perun Group networksGroup = perun.getGroupsManager().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); } }
perunSession = perun.getPerunSession(new PerunPrincipal( dispatcherProperties.getProperty("perun.principal.name"), dispatcherProperties.getProperty("perun.principal.extSourceName"),
/** * Gets collections as map of collectionID => Group. * * @return Map of collection IDs to group. */ private Map<String, Group> getNetworkIDsToGroupsMap (PerunSession session, Perun perun, Group networksGroup) throws GroupNotExistsException, WrongAttributeAssignmentException, InternalErrorException, AttributeNotExistsException, PrivilegeException { Map<String, Group> networkIDsToGroupMap = new HashMap<>(); for (Group group : perun.getGroupsManager().getSubGroups(session, networksGroup)) { for (Group subgroup : perun.getGroupsManager().getSubGroups(session, group)) { if (REPRESENTATIVES_GROUP_NAME.equals(subgroup.getShortName())) { Attribute networkID = perun.getAttributesManager().getAttribute(session, subgroup, NETWORK_ID_ATTR_NAME); networkIDsToGroupMap.put(networkID.valueAsString(), subgroup); } } } return networkIDsToGroupMap; }
/** * Add new bonaFideStatus to the user attribute. */ @Override public Application approveApplication(PerunSession session, Application app) throws PerunException { User user = app.getUser(); Group group = app.getGroup(); AttributesManager am = session.getPerun().getAttributesManager(); Attribute attestation = am.getAttribute(session, group, A_G_D_groupAttestation); String newValue = attestation.valueAsString(); Attribute bonaFideStatus = am.getAttribute(session, user, A_U_D_userBonaFideStatus); List<String> value = new ArrayList<>(); if (bonaFideStatus.getValue() != null && bonaFideStatus.valueAsList() != null) { value = bonaFideStatus.valueAsList(); } value.add(newValue); bonaFideStatus.setValue(value); am.setAttribute(session, user, bonaFideStatus); return app; }
Vo vo = app.getVo(); User user = app.getUser(); Member member = perun.getMembersManager().getMemberByUser(session, vo, user); Group collectionsGroup = perun.getGroupsManager().getGroupByName(session, vo, COLLECTIONS_GROUP_NAME); Map<String, Group> collectionIDsToGroupsMap = getCollectionIDsToGroupsMap(session, perun, collectionsGroup); } else { perun.getGroupsManager().addMember(session, group, member); perun.getGroupsManager().removeMember(session, app.getGroup(), member);
/** * All new members will be given role VOOBSERVER and TOPGROUPCREATOR */ @Override public Application approveApplication(PerunSession session, Application app) throws PerunException { if (Application.AppType.INITIAL.equals(app.getType())) { Vo vo = app.getVo(); User user = app.getUser(); AuthzResolver.setRole(session, user, vo, Role.TOPGROUPCREATOR); Group membersGroup = session.getPerun().getGroupsManager().getGroupByName(session, vo, "members"); AuthzResolver.setRole(session, user, membersGroup, Role.GROUPADMIN); } return app; }
throw new CantBeSubmittedException("This module can be set only for registration to Group."); AttributesManager am = session.getPerun().getAttributesManager();
Vo vo = app.getVo(); User user = app.getUser(); Member member = perun.getMembersManager().getMemberByUser(session, vo, user); Group networksGroup = perun.getGroupsManager().getGroupByName(session, vo, NETWORKS_GROUP_NAME); Map<String, Group> networkIDsToGroupsMap = getNetworkIDsToGroupsMap(session, perun, networksGroup); log.debug("For network ID: " + networkID + " there is no group in Perun."); } else { perun.getGroupsManager().addMember(session, group, member); perun.getGroupsManager().removeMember(session, app.getGroup(), member);