private int getTotal() { EntityManager em = null; try { em = emf.createEntityManager(); Query q = em.createNamedQuery("findTotal"); q.setParameter("userId", securityService.getUser().getUsername()); return ((Long) q.getSingleResult()).intValue(); } finally { if (em != null) em.close(); } }
private int getTotal(String type, String mediapackageId, EntityManager em) { Query q = em.createNamedQuery("findTotalByTypeAndMediapackageId"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("type", type); q.setParameter("mediapackageId", mediapackageId); return ((Long) q.getSingleResult()).intValue(); }
private int getTotalByMediapackageID(String mediapackageId, EntityManager em) { Query q = em.createNamedQuery("findTotalByMediapackageId"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("mediapackageId", mediapackageId); return ((Long) q.getSingleResult()).intValue(); }
private int getTotal(String type, Calendar calBegin, Calendar calEnd, EntityManager em) { Query q = em.createNamedQuery("findTotalByTypeAndIntervall"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("type", type); q.setParameter("begin", calBegin, TemporalType.TIMESTAMP); q.setParameter("end", calEnd, TemporalType.TIMESTAMP); return ((Long) q.getSingleResult()).intValue(); }
private int getTotal(String type, EntityManager em) { Query q = em.createNamedQuery("findTotalByType"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("type", type); return ((Long) q.getSingleResult()).intValue(); }
private int getTotal(Calendar calBegin, Calendar calEnd, EntityManager em) { Query q = em.createNamedQuery("findTotalByIntervall"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("begin", calBegin, TemporalType.TIMESTAMP); q.setParameter("end", calEnd, TemporalType.TIMESTAMP); return ((Long) q.getSingleResult()).intValue(); } }
protected boolean isUserAllowed(File aclFile) throws SAXException, IOException, XPathExpressionException { Document aclDoc = builder.parse(aclFile); XPath xPath = XPathFactory.newInstance().newXPath(); NodeList roles = (NodeList) xPath.evaluate("//*[local-name() = 'role']", aclDoc, XPathConstants.NODESET); for (int i = 0; i < roles.getLength(); i++) { Node role = roles.item(i); for (Role userRole : securityService.getUser().getRoles()) { if (userRole.getName().equals(role.getTextContent())) { return true; } } } return false; }
public Annotation addAnnotation(Annotation a) { // set the User ID on the annotation a.setUserId(securityService.getUser().getUsername()); EntityManager em = null; EntityTransaction tx = null; try { em = emf.createEntityManager(); tx = em.getTransaction(); tx.begin(); em.persist(a); tx.commit(); return a; } finally { if (tx.isActive()) { tx.rollback(); } if (em != null) em.close(); } }
User currentUser = securityService.getUser(); for (Role role : currentUser.getRoles()) { if (welcomePages.containsKey(role.getName())) {
q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("begin", calBegin, TemporalType.TIMESTAMP); q.setParameter("end", calEnd, TemporalType.TIMESTAMP);
q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("type", type); q.setParameter("begin", calBegin, TemporalType.TIMESTAMP);
public AnnotationList getAnnotationsByTypeAndMediapackageId(String type, String mediapackageId, int offset, int limit) { AnnotationListImpl result = new AnnotationListImpl(); EntityManager em = null; try { em = emf.createEntityManager(); result.setTotal(getTotal(type, mediapackageId, em)); result.setOffset(offset); result.setLimit(limit); Query q = em.createNamedQuery("findAnnotationsByTypeAndMediapackageId"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("type", type); q.setParameter("mediapackageId", mediapackageId); q.setFirstResult(offset); q.setMaxResults(limit); @SuppressWarnings("unchecked") Collection<Annotation> annotations = q.getResultList(); for (Annotation a : annotations) { result.add(a); } return result; } finally { if (em != null) em.close(); } }
public AnnotationList getAnnotationsByMediapackageId(String mediapackageId, int offset, int limit) { AnnotationListImpl result = new AnnotationListImpl(); EntityManager em = null; try { em = emf.createEntityManager(); result.setTotal(getTotalByMediapackageID(mediapackageId, em)); result.setOffset(offset); result.setLimit(limit); Query q = em.createNamedQuery("findAnnotationsByMediapackageId"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("mediapackageId", mediapackageId); q.setFirstResult(offset); q.setMaxResults(limit); @SuppressWarnings("unchecked") Collection<Annotation> annotations = q.getResultList(); for (Annotation a : annotations) { result.add(a); } return result; } finally { em.close(); } }
@SuppressWarnings("unchecked") public AnnotationList getAnnotationsByType(String type, int offset, int limit) { AnnotationListImpl result = new AnnotationListImpl(); result.setOffset(offset); result.setLimit(limit); EntityManager em = null; try { em = emf.createEntityManager(); result.setTotal(getTotal(type, em)); Query q = em.createNamedQuery("findAnnotationsByType"); q.setParameter("userId", securityService.getUser().getUsername()); q.setParameter("type", type); q.setFirstResult(offset); q.setMaxResults(limit); Collection<Annotation> annotations = q.getResultList(); for (Annotation a : annotations) { result.add(a); } return result; } finally { if (em != null) em.close(); } }
@SuppressWarnings("unchecked") public AnnotationList getAnnotations(int offset, int limit) { AnnotationListImpl result = new AnnotationListImpl(); result.setTotal(getTotal()); result.setOffset(offset); result.setLimit(limit); EntityManager em = null; try { em = emf.createEntityManager(); Query q = em.createNamedQuery("findAnnotations"); q.setParameter("userId", securityService.getUser().getUsername()); q.setFirstResult(offset); q.setMaxResults(limit); Collection<Annotation> annotations = q.getResultList(); for (Annotation a : annotations) { result.add(a); } return result; } finally { if (em != null) em.close(); } }
/** Run function <code>f</code> within the context. */ public <A> A runInContext(Supplier<A> f) { final Organization prevOrg = sec.getOrganization(); // workaround: if no organization is bound to the current thread sec.getUser() will throw a NPE final User prevUser = prevOrg != null ? sec.getUser() : null; sec.setOrganization(org); sec.setUser(user); try { return f.get(); } finally { sec.setOrganization(prevOrg); sec.setUser(prevUser); } }
/** * Run function <code>f</code> in the context described by the given organization and user. * * @param sec * Security service to use for getting data * @param org * Organization to switch to * @param user * User to switch to * @param fn * Function to execute */ public static void runAs(SecurityService sec, Organization org, User user, Runnable fn) { final Organization prevOrg = sec.getOrganization(); final User prevUser = prevOrg != null ? sec.getUser() : null; sec.setOrganization(org); sec.setUser(user); try { fn.run(); } finally { sec.setOrganization(prevOrg); sec.setUser(prevUser); } }
/** * Check if the current user has access to the capture agent with the given id. * @param agentId * The agent id to check. * @throws UnauthorizedException * If the user doesn't have access. */ public static void checkAgentAccess(final SecurityService securityService, final String agentId) throws UnauthorizedException { if (isBlank(agentId)) { return; } final User user = securityService.getUser(); if (user.hasRole(SecurityConstants.GLOBAL_ADMIN_ROLE) || user.hasRole(user.getOrganization().getAdminRole())) { return; } if (!user.hasRole(SecurityUtil.getCaptureAgentRole(agentId))) { throw new UnauthorizedException(user, "schedule"); } }
if (organization != null) { httpUriRequest.setHeader(SecurityConstants.ORGANIZATION_HEADER, organization.getId()); final User currentUser = securityService.getUser(); if (currentUser != null) { httpUriRequest.setHeader(SecurityConstants.USER_HEADER, currentUser.getUsername());
job = new JobImpl(idCounter.addAndGet(1)); if (securityService != null) { job.setCreator(securityService.getUser().getUsername()); job.setOrganization(securityService.getOrganization().getId());