/** * 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); } }
@Override public List<Application> getApplicationsForUser(PerunSession sess) { try { PerunPrincipal pp = sess.getPerunPrincipal(); if (pp.getUser() != null) { return jdbc.query(APP_SELECT + " where user_id=? or (a.created_by=? and extsourcename=?) order by a.id desc", APP_MAPPER, pp.getUserId(), pp.getActor(), pp.getExtSourceName()); } else { // sort by ID which respect latest applications return jdbc.query(APP_SELECT + " where a.created_by=? and extsourcename=? order by a.id desc", APP_MAPPER, pp.getActor(), pp.getExtSourceName()); } } catch (EmptyResultDataAccessException ex) { return new ArrayList<Application>(); } }
@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; }
perun.getUsersManager().getUserByExtSourceNameAndExtLogin(registrarSession, sess.getPerunPrincipal().getExtSourceName(), sess.getPerunPrincipal().getActor()); return new ArrayList<Identity>(); } catch (Exception ex) {
params.put("delegatedLogin", perunPrincipal.getActor()); params.put("delegatedExtSourceName", perunPrincipal.getExtSourceName()); params.put("delegatedExtSourceType", perunPrincipal.getExtSourceType());
@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 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 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); }
public void updateApplicationUser(PerunSession sess, Application app) throws InternalErrorException { jdbc.update("update application set user_id=?, modified_at=" + Compatibility.getSysdate() + ", modified_by=? where id=?", (app.getUser() != null) ? app.getUser().getId() : null, sess.getPerunPrincipal().getActor(), app.getId()); }
@Override public Publication updatePublication(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 try { getAuthorsByPublicationId(sess, publication.getId()); } catch (PrivilegeException ex) { throw new PrivilegeException("You are not allowed to update publications you didn't created."); } } return getPublicationManagerBl().updatePublication(sess, publication); }
/** * 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; } }
ex.setSource2((String) originalIdentity.get("extSourceName")); ex.setSourceType2((String) originalIdentity.get("extSourceType")); ex.setLogin2(sess.getPerunPrincipal().getActor()); ex.setSource2(sess.getPerunPrincipal().getExtSourceName()); ex.setSourceType2(sess.getPerunPrincipal().getExtSourceType()); originalIdentity.get("actor").equals(sess.getPerunPrincipal().getActor()) && originalIdentity.get("extSourceType").equals(sess.getPerunPrincipal().getExtSourceType())) { IdentityIsSameException ex = new IdentityIsSameException("You tried to join same identity with itself. Please try again but select different identity."); ex.setLogin(sess.getPerunPrincipal().getActor()); ex.setSource(sess.getPerunPrincipal().getExtSourceName()); ex.setSourceType(sess.getPerunPrincipal().getExtSourceType()); UserExtSource ues = createExtSourceAndUserExtSource(originalUser, sess.getPerunPrincipal().getActor(), sess.getPerunPrincipal().getExtSourceName(), sess.getPerunPrincipal().getExtSourceType(), sess.getPerunPrincipal().getExtSourceLoa());
} else { if (!sess.getPerunPrincipal().getExtSourceName().equals(app.getExtSourceName()) && !sess.getPerunPrincipal().getActor().equals(app.getCreatedBy())) throw new PrivilegeException("checkForSimilarUsers"); } else { if (!sess.getPerunPrincipal().getExtSourceName().equals(app.getExtSourceName()) && !sess.getPerunPrincipal().getActor().equals(app.getCreatedBy())) throw new PrivilegeException("checkForSimilarUsers");
@Override public List<Author> getAuthorsByPublicationId(PerunSession session, int id) throws InternalErrorException, PrivilegeException, CabinetException { List<Author> authors = getAuthorshipManagerBl().getAuthorsByPublicationId(id); boolean oneOfAuthors = false; for (Author author : authors) { if (author.getId() == session.getPerunPrincipal().getUserId()) { oneOfAuthors = true; break; } } if (AuthzResolver.isAuthorized(session, Role.PERUNADMIN)) oneOfAuthors = true; if (!oneOfAuthors) { // not author, but check if user created publication, then he can list current authors Publication publication = getPublicationManagerBl().getPublicationById(id); if ((publication.getCreatedByUid() != session.getPerunPrincipal().getUserId()) && !(Objects.equals(publication.getCreatedBy(), session.getPerunPrincipal().getActor()))) { throw new PrivilegeException("You are not allowed to see authors of publications you didn't created."); } } return authors; }
@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; }
@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; }
&& !AuthzResolver.isAuthorized(sess, Role.VOOBSERVER, app.getVo()) && !AuthzResolver.hasRole(sess.getPerunPrincipal(), Role.RPC) && !(app.getCreatedBy().equals(sess.getPerunPrincipal().getActor()) && app.getExtSourceName().equals(sess.getPerunPrincipal().getExtSourceName()))) { throw new PrivilegeException(sess, "getApplicationById"); && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, app.getGroup()) && !AuthzResolver.hasRole(sess.getPerunPrincipal(), Role.RPC) && !(app.getCreatedBy().equals(sess.getPerunPrincipal().getActor()) && app.getExtSourceName().equals(sess.getPerunPrincipal().getExtSourceName()))) { throw new PrivilegeException(sess, "getApplicationById");
@Override public Publication createPublication(PerunSession sess, Publication publication) throws InternalErrorException { try { // Set the new Category id int newId = Utils.getNewId(jdbc, "cabinet_publications_id_seq"); jdbc.update("insert into cabinet_publications (id, externalId, publicationSystemId, title, year, main," + " isbn, categoryId, createdBy, createdDate, rank, doi, locked, created_by_uid, modified_by_uid)" + " values (?,?,?,?,?,?,?,?,?,"+ Compatibility.getSysdate()+",?,?,?,?,?)", newId, (publication.getExternalId() == 0) ? newId : publication.getExternalId(), publication.getPublicationSystemId(), publication.getTitle(), publication.getYear(), publication.getMain(), publication.getIsbn(), publication.getCategoryId(), sess.getPerunPrincipal().getActor(), publication.getRank(), publication.getDoi(), (publication.getLocked()) ? 1 : 0, sess.getPerunPrincipal().getUserId(), sess.getPerunPrincipal().getUserId()); publication.setId(newId); } catch (RuntimeException e) { throw new InternalErrorException(e); } return publication; }
int result = jdbc.update("update application set state=?, modified_by=?, modified_at=? where id=?", AppState.REJECTED.toString(), sess.getPerunPrincipal().getActor(), new Date(), appId); if (result == 0) { throw new RegistrarException("Application with ID="+appId+" not found.");
pass = true; } else { if (Objects.equals(app.getCreatedBy(), sess.getPerunPrincipal().getActor()) && Objects.equals(app.getExtSourceName(), sess.getPerunPrincipal().getExtSourceName()) && Objects.equals(app.getExtSourceType(), sess.getPerunPrincipal().getExtSourceType())