@Override public String getConsolidatorToken(PerunSession sess) throws PerunException { Map<String, Object> value = new HashMap<String, Object>(); String actor = sess.getPerunPrincipal().getActor(); String extSourceName = sess.getPerunPrincipal().getExtSourceName(); String extSourceType = sess.getPerunPrincipal().getExtSourceType(); Integer extSourceLoa = sess.getPerunPrincipal().getExtSourceLoa(); User user = sess.getPerunPrincipal().getUser(); value.put("actor", actor); value.put("extSourceName", extSourceName); value.put("extSourceType", extSourceType); value.put("extSourceLoa", extSourceLoa); value.put("user", user); value.put("additionalInformation", sess.getPerunPrincipal().getAdditionalInformations()); // create token from actual properties String token = registrarManager.getMailManager().getMessageAuthenticationCode(System.currentTimeMillis() + actor + extSourceName + extSourceType + extSourceLoa); requestCache.putIfAbsent(token, value); return token; }
public GroupResourceEndpointController(PerunSession session) { this.session = session; this.perunBl = (PerunBl) session.getPerun(); }
User user = session.getPerunPrincipal().getUser(); if (user == null) { throw new CantBeSubmittedException("This module can be set only for registration to Group."); AttributesManager am = session.getPerun().getAttributesManager();
perun = (PerunBl) session.getPerun(); perunPrincipal = session.getPerunPrincipal(); user = session.getPerunPrincipal().getUser(); if(user == null) throw new VOOTException("invalid_user");
/** * Forcefully marks application as VERIFIED * (only if was in NEW state before) * * @param sess session info to use for modified_by * @param appId ID of application to verify. */ private void markApplicationVerified(PerunSession sess, int appId) { try { if (jdbc.update("update application set state=?, modified_at=" + Compatibility.getSysdate() + ", modified_by=? where id=? and state=?", AppState.VERIFIED.toString(), sess.getPerunPrincipal().getActor(), appId, AppState.NEW.toString()) > 0) { log.info("Application {} marked as VERIFIED", appId); } else { log.info("Application {} not marked VERIFIED, was not in state NEW", appId); } } catch (InternalErrorException ex) { log.error("Application {} NOT marked as VERIFIED due to error {}", appId, ex); } }
public UserResourceEndpointController(PerunSession session) { this.session = session; this.perunBl = (PerunBl) session.getPerun(); }
@Override public void deleteAuthorship(PerunSession sess, Authorship authorship) throws InternalErrorException, CabinetException, PrivilegeException { if (!AuthzResolver.isAuthorized(sess, Role.PERUNADMIN) && !authorship.getCreatedBy().equalsIgnoreCase(sess.getPerunPrincipal().getActor()) && !authorship.getUserId().equals(sess.getPerunPrincipal().getUser().getId()) && authorship.getCreatedByUid() != sess.getPerunPrincipal().getUserId()) { throw new PrivilegeException("You are not allowed to delete authorships you didn't created or which doesn't concern you."); } getAuthorshipManagerBl().deleteAuthorship(sess, authorship); }
/** * 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); } }
if (sess.getPerunPrincipal().getUser() != null) { return new ArrayList<Identity>(); perun.getUsersManager().getUserByExtSourceNameAndExtLogin(registrarSession, sess.getPerunPrincipal().getExtSourceName(), sess.getPerunPrincipal().getActor()); return new ArrayList<Identity>(); } catch (Exception ex) { attrNames.add("urn:perun:user:attribute-def:def:organization"); mail = sess.getPerunPrincipal().getAdditionalInformations().get("mail"); name = sess.getPerunPrincipal().getAdditionalInformations().get("cn"); name = sess.getPerunPrincipal().getAdditionalInformations().get("displayName");
/** * 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); } }
/** * Retrieves whole application object from DB * (authz in parent methods) * * @param sess PerunSession for Authz and to resolve User * @param vo VO to get application for * @param group Group * * @return application object / null if not exists */ private Application getLatestApplication(PerunSession sess, Vo vo, Group group, Application.AppType type) { try { if (sess.getPerunPrincipal().getUser() != null) { if (group != null) { return jdbc.queryForObject(RegistrarManagerImpl.APP_SELECT + " where a.id=(select max(id) from application where vo_id=? and group_id=? and apptype=? and user_id=? )", RegistrarManagerImpl.APP_MAPPER, vo.getId(), group.getId(), String.valueOf(type), sess.getPerunPrincipal().getUserId()); } else { return jdbc.queryForObject(RegistrarManagerImpl.APP_SELECT + " where a.id=(select max(id) from application where vo_id=? and apptype=? and user_id=? )", RegistrarManagerImpl.APP_MAPPER, vo.getId(), String.valueOf(type), sess.getPerunPrincipal().getUserId()); } } else { if (group != null) { return jdbc.queryForObject(RegistrarManagerImpl.APP_SELECT + " where a.id=(select max(id) from application where vo_id=? and group_id=? and apptype=? and created_by=? and extsourcename=? )", RegistrarManagerImpl.APP_MAPPER, vo.getId(), group.getId(), String.valueOf(type), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getExtSourceName()); } else { return jdbc.queryForObject(RegistrarManagerImpl.APP_SELECT + " where a.id=(select max(id) from application where vo_id=? and apptype=? and created_by=? and extsourcename=? )", RegistrarManagerImpl.APP_MAPPER, vo.getId(), String.valueOf(type), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getExtSourceName()); } } } catch (EmptyResultDataAccessException ex) { return null; } }
@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; }
@Override public void deleteThanks(PerunSession sess, Thanks thanks) throws InternalErrorException, CabinetException, PrivilegeException { if (!AuthzResolver.isAuthorized(sess, Role.PERUNADMIN) && (!thanks.getCreatedBy().equalsIgnoreCase(sess.getPerunPrincipal().getActor())) && (thanks.getCreatedByUid() !=(sess.getPerunPrincipal().getUserId()))) { throw new PrivilegeException("deleteThanks"); } getThanksManagerBl().deleteThanks(sess, thanks); }
@Override public List<ApplicationFormItemData> createApplication(PerunSession session, Application application, List<ApplicationFormItemData> data) throws PerunException { if (application.getUser() == null) { for (ApplicationFormItemData item : data) { if (item.getFormItem() != null && Objects.equals(AttributesManager.NS_USER_ATTR_DEF+":birthNumber", item.getFormItem().getPerunDestinationAttribute())) { // if application contains birth number, try to map to existing user String rc = item.getValue(); if (rc != null && !rc.isEmpty()) { try { User user = ((PerunBl) session.getPerun()).getUsersManagerBl().getUserByExtSourceNameAndExtLogin(session, "RC", rc); application.setUser(user); registrar.updateApplicationUser(session, application); } catch (Exception ex) { log.warn("Couldn't find or set user to application {} by RC: {}", application, ex); } } break; } } } return data; }
@Override public void deletePublication(PerunSession sess, Publication publication) throws CabinetException, InternalErrorException, PrivilegeException { if (!AuthzResolver.isAuthorized(sess, Role.PERUNADMIN) && !publication.getCreatedBy().equalsIgnoreCase(sess.getPerunPrincipal().getActor()) && publication.getCreatedByUid() != sess.getPerunPrincipal().getUserId()) { // not perun admin or author of record throw new PrivilegeException("You are not allowed to delete publications you didn't created. If you wish, you can remove yourself from authors instead."); } getPublicationManagerBl().deletePublication(sess, publication); }
@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; }
@Override public Authorship createAuthorship(PerunSession sess, Authorship authorship) throws InternalErrorException { try { // Set the new Authorship id int newId = Utils.getNewId(jdbc, "cabinet_authorships_id_seq"); jdbc.update("insert into cabinet_authorships (id, userId, publicationId, createdBy, createdDate, created_by_uid, modified_by_uid)" + " values (?,?,?,?," + Compatibility.getSysdate() + ",?,?)", newId, authorship.getUserId(), authorship.getPublicationId(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), sess.getPerunPrincipal().getUserId()); authorship.setId(newId); } catch (RuntimeException e) { throw new InternalErrorException(e); } return authorship; }
public Application approveApplication(PerunSession session, Application app) throws PerunException { PerunBl perun = (PerunBl)session.getPerun();
@Override public Thanks createThanks(PerunSession sess, Thanks thanks) throws InternalErrorException, CabinetException { try { // Set the new Thanks id int newId = Utils.getNewId(jdbc, "cabinet_thanks_id_seq"); jdbc.update("insert into cabinet_thanks (id, ownerId, publicationId, createdBy, createdDate, created_by_uid, modified_by_uid)" + " values (?,?,?,?,"+ Compatibility.getSysdate()+",?,?)", newId, thanks.getOwnerId(), thanks.getPublicationId(), sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getUserId(), sess.getPerunPrincipal().getUserId()); thanks.setId(newId); } catch (RuntimeException e) { throw new InternalErrorException(e); } return thanks; }
PerunBl perun = (PerunBl) session.getPerun();