private void verifyTicketInCollection(Collection tickets, String name) { for (Iterator it = tickets.iterator(); it.hasNext(); ) { Ticket ticket = (Ticket) it.next(); if (ticket.getKey().equals(name)) return; } Assert.fail("could not find ticket: " + name); }
public void testInvalidEntryNoType() throws Exception { CollectionItem collection = helper.makeAndStoreDummyCollection(); Ticket ticket = new HibTicket(); ticket.setKey("invalidEntryNoTypeTicket"); ticket.setKey("foo"); RequestContext req = createRequestContext(collection, ticket); ResponseContext res = adapter.postEntry(req); assertNotNull("Null response context", res); assertEquals("Incorrect response status", 400, res.getStatus()); }
private void verifyTicket(Ticket ticket1, Ticket ticket2) { Assert.assertEquals(ticket1.getKey(), ticket2.getKey()); Assert.assertEquals(ticket1.getTimeout(), ticket2.getTimeout()); Assert.assertEquals(ticket1.getOwner().getUsername(), ticket2.getOwner().getUsername()); Iterator it1 = ticket1.getPrivileges().iterator(); Iterator it2 = ticket2.getPrivileges().iterator(); Assert.assertEquals(ticket1.getPrivileges().size(), ticket1.getPrivileges().size()); while (it1.hasNext()) Assert.assertEquals(it1.next(), it2.next()); }
public void testGenerationError() throws Exception { CollectionItem collection = helper.makeAndStoreDummyCollection(); Ticket ticket = helper.makeDummyTicket(); ticket.setKey("generationTicket"); RequestContext req = createRequestContext(collection, ticket); helper.enableGeneratorFailure(); ResponseContext res = adapter.postEntry(req); assertNotNull("Null response context", res); assertEquals("Incorrect response status", 500, res.getStatus()); }
public ModelAndView handleRequestInternal( HttpServletRequest request, HttpServletResponse response) throws Exception { String path = request.getPathInfo(); String collectionUid = path.substring(path.lastIndexOf('/') + 1); // Get the collection and make sure it's valid. CollectionItem collection = null; try { collection = (CollectionItem) contentService.findItemByUid(collectionUid); } catch (ClassCastException e) { // This isn't quite the right thing to do, but is a good idea for now. return new ModelAndView("error_notfound"); } catch (CosmoSecurityException e) { new ModelAndView("error_forbidden"); } if (collection == null) { return new ModelAndView("error_notfound"); } Map<String, Object> model = new HashMap<String, Object>(); model.put("collection", collection); CosmoSecurityContext csc = securityManager.getSecurityContext(); Map<String, String> relationLinks; Ticket ticket = findTicket(csc); if (ticket != null) relationLinks = serviceLocatorFactory .createServiceLocator(request, ticket, false) .getCollectionUrls(collection); else relationLinks = serviceLocatorFactory.createServiceLocator(request, false).getCollectionUrls(collection); model.put("relationLinks", relationLinks); model.put("properties", propertyPlaceholderConfigurer.getProperties()); if (ticket != null) { model.put("ticketKey", ticket.getKey()); return new ModelAndView(pimView, model); } else { // If we can't find a ticket principal, use the current user. User authUser = csc.getUser(); if (authUser != null) { return new ModelAndView(pimView, model); } } // when all else fails... return new ModelAndView("error_forbidden"); }
/* (non-Javadoc) * @see org.osaf.cosmo.model.copy.InterfaceTicket#isGranted(org.osaf.cosmo.model.copy.Item) */ public boolean isGranted(Item item) { if (item == null) return false; for (Ticket ticket : item.getTickets()) { if (ticket.equals(this)) return true; } for (Item parent : item.getParents()) { if (isGranted(parent)) return true; } return false; }
@Override public boolean equals(Object obj) { if (!super.equals(obj)) { return false; } if (!(obj instanceof TicketAuthenticationToken)) { return false; } TicketAuthenticationToken test = (TicketAuthenticationToken) obj; return ticket.equals(test.getPrincipal()); }
public void testCreateEntry() throws Exception { CollectionItem collection = helper.makeAndStoreDummyCollection(); Ticket ticket = helper.makeDummyTicket(); ticket.setKey("createEntryTicket"); RequestContext req = createRequestContext(collection, ticket); ResponseContext res = adapter.postEntry(req); assertNotNull("Null response context", res); assertEquals("Incorrect response status", 201, res.getStatus()); assertNotNull("Null etag", res.getEntityTag()); // disable last modified check til mock dao bumps modified date // assertNotNull("Null last modified", res.getLastModified()); assertNotNull("Null Location header", res.getHeader("Location")); assertNotNull("Null Content-Location header", res.getHeader("Content-Location")); String username = helper.getUser().getUsername(); Ticket saved = helper.getContentService().getTicket(collection, ticket.getKey()); assertNotNull("Ticket not saved", saved); assertEquals("Wrong key", ticket.getKey(), saved.getKey()); assertEquals("Wrong type", ticket.getType(), saved.getType()); }
public void testTickets() throws Exception { User testuser = getUser(userDao, "testuser"); String name = "ticketable:" + System.currentTimeMillis(); ContentItem item = generateTestContent(name, "testuser"); CollectionItem root = (CollectionItem) contentDao.getRootItem(testuser); ContentItem newItem = contentDao.createContent(root, item); clearSession(); newItem = contentDao.findContentByUid(newItem.getUid()); Ticket ticket1 = new HibTicket(); ticket1.setKey("ticket1"); ticket1.setTimeout(10); ticket1.setOwner(testuser); HashSet privs = new HashSet(); privs.add("priv1"); privs.add("privs2"); ticket1.setPrivileges(privs); contentDao.createTicket(newItem, ticket1); Ticket ticket2 = new HibTicket(); ticket2.setKey("ticket2"); ticket2.setTimeout(100); ticket2.setOwner(testuser); privs = new HashSet(); privs.add("priv3"); privs.add("priv4"); ticket2.setPrivileges(privs); contentDao.createTicket(newItem, ticket2); clearSession(); newItem = contentDao.findContentByUid(newItem.getUid()); Ticket queryTicket1 = contentDao.getTicket(newItem, "ticket1"); Assert.assertNotNull(queryTicket1); verifyTicket(queryTicket1, ticket1); Collection tickets = contentDao.getTickets(newItem); Assert.assertEquals(2, tickets.size()); verifyTicketInCollection(tickets, ticket1.getKey()); verifyTicketInCollection(tickets, ticket2.getKey()); contentDao.removeTicket(newItem, ticket1); clearSession(); newItem = contentDao.findContentByUid(newItem.getUid()); tickets = contentDao.getTickets(newItem); Assert.assertEquals(1, tickets.size()); verifyTicketInCollection(tickets, ticket2.getKey()); queryTicket1 = contentDao.getTicket(newItem, "ticket1"); Assert.assertNull(queryTicket1); Ticket queryTicket2 = contentDao.getTicket(newItem, "ticket2"); Assert.assertNotNull(queryTicket2); verifyTicket(queryTicket2, ticket2); contentDao.removeTicket(newItem, ticket2); clearSession(); newItem = contentDao.findContentByUid(newItem.getUid()); tickets = contentDao.getTickets(newItem); Assert.assertEquals(0, tickets.size()); }
/* (non-Javadoc) * @see org.osaf.cosmo.model.copy.InterfaceTicket#compareTo(org.osaf.cosmo.model.copy.Ticket) */ public int compareTo(Ticket t) { return key.compareTo(t.getKey()); }