@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 List<Identity> checkForSimilarUsers(PerunSession sess, List<ApplicationFormItemData> formItems) throws PerunException { if (sess.getPerunPrincipal().getUser() != null || formItems == null) { return new ArrayList<Identity>(); } Set<RichUser> res = new HashSet<RichUser>(); List<String> attrNames = new ArrayList<String>(); attrNames.add("urn:perun:user:attribute-def:def:preferredMail"); attrNames.add("urn:perun:user:attribute-def:def:organization"); for (ApplicationFormItemData item : formItems) { String value = item.getValue(); if (item.getFormItem().getType().equals(ApplicationFormItem.Type.VALIDATED_EMAIL)) { // search by email if (value != null && !value.isEmpty()) res.addAll(perun.getUsersManager().findRichUsersWithAttributesByExactMatch(registrarSession, value, attrNames)); } if (Objects.equals(item.getFormItem().getPerunDestinationAttribute(), "urn:perun:user:attribute-def:core:displayName")) { // search by name if (value != null && !value.isEmpty()) res.addAll(perun.getUsersManager().findRichUsersWithAttributesByExactMatch(registrarSession, value, attrNames)); } } return convertToIdentities(new ArrayList<RichUser>(res)); }
@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; }
@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); }
/** * 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; } }
if (sess.getPerunPrincipal().getUser() != null) { return new ArrayList<Identity>();
public Response process(PerunSession session, String path, String params) throws SCIMException { if (session.getPerunPrincipal().getUser() == null) { throw new SCIMException("invalid_user");
User user = sess.getPerunPrincipal().getUser(); String actor = sess.getPerunPrincipal().getActor(); String extSourceName = sess.getPerunPrincipal().getExtSourceName();
if (sess.getPerunPrincipal().getUser() != null) { if (!sess.getPerunPrincipal().getUser().equals(app.getUser())) throw new PrivilegeException("checkForSimilarUsers"); } else { if (!sess.getPerunPrincipal().getExtSourceName().equals(app.getExtSourceName()) && if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, app.getVo()) && !AuthzResolver.isAuthorized(sess, Role.GROUPADMIN, app.getGroup())) { if (sess.getPerunPrincipal().getUser() != null) { if (!sess.getPerunPrincipal().getUser().equals(app.getUser())) throw new PrivilegeException("checkForSimilarUsers"); } else { if (!sess.getPerunPrincipal().getExtSourceName().equals(app.getExtSourceName()) &&
User user = session.getPerunPrincipal().getUser(); if (user == null) { throw new CantBeSubmittedException("This module can be set only for registration to Group.");
User user = sess.getPerunPrincipal().getUser(); String actor = sess.getPerunPrincipal().getActor(); String extSourceName = sess.getPerunPrincipal().getExtSourceName();
perun = (PerunBl) session.getPerun(); perunPrincipal = session.getPerunPrincipal(); user = session.getPerunPrincipal().getUser(); if(user == null) throw new VOOTException("invalid_user");
if (Objects.equals(sess.getPerunPrincipal().getUser(), app.getUser())) { pass = true; } else {