Search in sources :

Example 41 with Attachment

use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.

the class WikiEngineTest method testAttachmentRefs.

/**
 *  Checks, if ReferenceManager is informed of new attachments.
 */
@Test
public void testAttachmentRefs() throws Exception {
    final ReferenceManager refMgr = m_engine.getManager(ReferenceManager.class);
    final AttachmentManager attMgr = m_engine.getManager(AttachmentManager.class);
    m_engine.saveText(NAME1, "fooBar");
    final Attachment att = Wiki.contents().attachment(m_engine, NAME1, "TestAtt.txt");
    att.setAuthor("FirstPost");
    attMgr.storeAttachment(att, m_engine.makeAttachmentFile());
    // and check post-conditions
    Collection<String> c = refMgr.findUncreated();
    Assertions.assertTrue(c == null || c.size() == 0, "attachment exists: " + c);
    c = refMgr.findUnreferenced();
    Assertions.assertEquals(2, c.size(), "unreferenced count");
    final Iterator<String> i = c.iterator();
    final String first = i.next();
    final String second = i.next();
    Assertions.assertTrue((first.equals(NAME1) && second.equals(NAME1 + "/TestAtt.txt")) || (first.equals(NAME1 + "/TestAtt.txt") && second.equals(NAME1)), "unreferenced");
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) ReferenceManager(org.apache.wiki.references.ReferenceManager) Test(org.junit.jupiter.api.Test)

Example 42 with Attachment

use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.

the class RPCHandler method getRecentChanges.

/**
 * {@inheritDoc}
 */
@Override
public Vector<Hashtable<String, Object>> getRecentChanges(Date since) {
    checkPermission(PagePermission.VIEW);
    final Set<Page> pages = m_engine.getManager(PageManager.class).getRecentChanges();
    final Vector<Hashtable<String, Object>> result = new Vector<>();
    final Calendar cal = Calendar.getInstance();
    cal.setTime(since);
    // 
    // Convert UTC to our time.
    // 
    cal.add(Calendar.MILLISECOND, (cal.get(Calendar.ZONE_OFFSET) + (cal.getTimeZone().inDaylightTime(since) ? cal.get(Calendar.DST_OFFSET) : 0)));
    since = cal.getTime();
    for (final Page page : pages) {
        if (page.getLastModified().after(since) && !(page instanceof Attachment)) {
            result.add(encodeWikiPage(page));
        }
    }
    return result;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) Hashtable(java.util.Hashtable) Calendar(java.util.Calendar) Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) Vector(java.util.Vector)

Example 43 with Attachment

use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.

the class AuthorizationManagerTest method testInheritedPermissions.

@Test
public void testInheritedPermissions() throws Exception {
    // Create test page & attachment
    final String src = "[{ALLOW edit Alice}] ";
    m_engine.saveText("Test", src);
    final File f = m_engine.makeAttachmentFile();
    final Attachment att = Wiki.contents().attachment(m_engine, "Test", "test1.txt");
    att.setAuthor("FirstPost");
    m_engine.getManager(AttachmentManager.class).storeAttachment(att, f);
    final Attachment p = (Attachment) m_engine.getManager(PageManager.class).getPage("Test/test1.txt");
    final Permission view = PermissionFactory.getPagePermission(p, "view");
    final Permission edit = PermissionFactory.getPagePermission(p, "edit");
    // Create authenticated session with user 'Alice', who can read & edit (in ACL)
    Session session = WikiSessionTest.authenticatedSession(m_engine, Users.ALICE, Users.ALICE_PASS);
    Assertions.assertTrue(m_auth.checkPermission(session, view), "Alice view Test/test1.txt");
    Assertions.assertTrue(m_auth.checkPermission(session, edit), "Alice view Test/test1.txt");
    // Create authenticated session with user 'Bob', who can't read or edit (not in ACL)
    session = WikiSessionTest.authenticatedSession(m_engine, Users.BOB, Users.BOB_PASS);
    Assertions.assertFalse(m_auth.checkPermission(session, view), "Bob !view Test/test1.txt");
    Assertions.assertFalse(m_auth.checkPermission(session, edit), "Bob !view Test/test1.txt");
    // Delete test page & attachment
    m_engine.getManager(AttachmentManager.class).deleteAttachment(att);
    m_engine.getManager(PageManager.class).deletePage("Test");
}
Also used : PageManager(org.apache.wiki.pages.PageManager) WikiPermission(org.apache.wiki.auth.permissions.WikiPermission) PagePermission(org.apache.wiki.auth.permissions.PagePermission) AllPermission(org.apache.wiki.auth.permissions.AllPermission) Permission(java.security.Permission) Attachment(org.apache.wiki.api.core.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) File(java.io.File) Session(org.apache.wiki.api.core.Session) WikiSessionTest(org.apache.wiki.WikiSessionTest) Test(org.junit.jupiter.api.Test)

Example 44 with Attachment

use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.

the class AuthorizationManagerTest method testInheritedAclPermissions.

@Test
public void testInheritedAclPermissions() throws Exception {
    // Create test page & attachment
    final String src = "[{ALLOW view Alice}] ";
    m_engine.saveText("Test", src);
    final File f = m_engine.makeAttachmentFile();
    final Attachment att = Wiki.contents().attachment(m_engine, "Test", "test1.txt");
    att.setAuthor("FirstPost");
    m_engine.getManager(AttachmentManager.class).storeAttachment(att, f);
    final Attachment p = (Attachment) m_engine.getManager(PageManager.class).getPage("Test/test1.txt");
    final Permission view = PermissionFactory.getPagePermission(p, "view");
    final Permission edit = PermissionFactory.getPagePermission(p, "edit");
    // Create session with user 'Alice', who can read (in ACL)
    Session session = WikiSessionTest.authenticatedSession(m_engine, Users.ALICE, Users.ALICE_PASS);
    Assertions.assertTrue(m_auth.checkPermission(session, view), "Foo view Test");
    Assertions.assertFalse(m_auth.checkPermission(session, edit), "Foo !edit Test");
    // Create session with user 'Bob', who can't read or edit (not in ACL)
    session = WikiSessionTest.authenticatedSession(m_engine, Users.BOB, Users.BOB_PASS);
    Assertions.assertFalse(m_auth.checkPermission(session, view), "Bar !view Test");
    Assertions.assertFalse(m_auth.checkPermission(session, view), "Bar !edit Test");
    // Delete test page & attachment
    m_engine.getManager(AttachmentManager.class).deleteAttachment(att);
    m_engine.getManager(PageManager.class).deletePage("Test");
}
Also used : PageManager(org.apache.wiki.pages.PageManager) WikiPermission(org.apache.wiki.auth.permissions.WikiPermission) PagePermission(org.apache.wiki.auth.permissions.PagePermission) AllPermission(org.apache.wiki.auth.permissions.AllPermission) Permission(java.security.Permission) Attachment(org.apache.wiki.api.core.Attachment) AttachmentManager(org.apache.wiki.attachment.AttachmentManager) File(java.io.File) Session(org.apache.wiki.api.core.Session) WikiSessionTest(org.apache.wiki.WikiSessionTest) Test(org.junit.jupiter.api.Test)

Example 45 with Attachment

use of org.apache.wiki.api.core.Attachment in project jspwiki by apache.

the class AttachmentManagerTest method testExistsUTF2.

@Test
public void testExistsUTF2() throws Exception {
    final Attachment att = Wiki.contents().attachment(m_engine, NAMEU, "test\u00e4.bin");
    att.setAuthor("FirstPost");
    m_manager.storeAttachment(att, makeAttachmentFile());
    Assertions.assertTrue(m_engine.getManager(PageManager.class).wikiPageExists(att.getName()), "attachment disappeared");
}
Also used : Attachment(org.apache.wiki.api.core.Attachment) Test(org.junit.jupiter.api.Test)

Aggregations

Attachment (org.apache.wiki.api.core.Attachment)76 Test (org.junit.jupiter.api.Test)37 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)35 Page (org.apache.wiki.api.core.Page)27 ProviderException (org.apache.wiki.api.exceptions.ProviderException)20 PageManager (org.apache.wiki.pages.PageManager)19 File (java.io.File)15 Date (java.util.Date)10 Engine (org.apache.wiki.api.core.Engine)10 ReferenceManager (org.apache.wiki.references.ReferenceManager)9 InputStream (java.io.InputStream)8 FileInputStream (java.io.FileInputStream)6 IOException (java.io.IOException)6 InputStreamReader (java.io.InputStreamReader)6 StringWriter (java.io.StringWriter)6 Vector (java.util.Vector)6 WikiContext (org.apache.wiki.WikiContext)6 Permission (java.security.Permission)4 ArrayList (java.util.ArrayList)4 Hashtable (java.util.Hashtable)4