Search in sources :

Example 91 with Page

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

the class ParentPageNameTag method doWikiStartTag.

/**
 * {@inheritDoc}
 */
@Override
public final int doWikiStartTag() throws IOException {
    final Engine engine = m_wikiContext.getEngine();
    final Page page = m_wikiContext.getPage();
    if (page != null) {
        if (page instanceof Attachment) {
            pageContext.getOut().print(engine.getManager(RenderingManager.class).beautifyTitle(((Attachment) page).getParentName()));
        } else {
            String name = page.getName();
            final int entrystart = name.indexOf("_blogentry_");
            if (entrystart != -1) {
                name = name.substring(0, entrystart);
            }
            final int commentstart = name.indexOf("_comments_");
            if (commentstart != -1) {
                name = name.substring(0, commentstart);
            }
            pageContext.getOut().print(engine.getManager(RenderingManager.class).beautifyTitle(name));
        }
    }
    return SKIP_BODY;
}
Also used : Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment) Engine(org.apache.wiki.api.core.Engine)

Example 92 with Page

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

the class PreSaveWikiPageTask method execute.

/**
 * {@inheritDoc}
 */
@Override
public Outcome execute(final Context context) throws WikiException {
    // Get the wiki page
    final Page page = context.getPage();
    // Figure out who the author was. Prefer the author set programmatically; otherwise get from the current logged in user
    if (context.getPage().getAuthor() == null && context.getCurrentUser() != null) {
        page.setAuthor(context.getCurrentUser().getName());
    }
    // Run the pre-save filters. If any exceptions, add error to list, abort, and redirect
    final String saveText = context.getEngine().getManager(FilterManager.class).doPreSaveFiltering(context, m_proposedText);
    // Stash the wiki context, old and new text as workflow attributes
    getWorkflowContext().put(WorkflowManager.WF_WP_SAVE_FACT_PROPOSED_TEXT, saveText);
    return Outcome.STEP_COMPLETE;
}
Also used : Page(org.apache.wiki.api.core.Page) FilterManager(org.apache.wiki.filters.FilterManager)

Example 93 with Page

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

the class PreviousVersionTag method doWikiStartTag.

/**
 *  {@inheritDoc}
 */
@Override
public final int doWikiStartTag() throws IOException {
    final Page page = m_wikiContext.getPage();
    int version = page.getVersion();
    version--;
    if (version > 0) {
        pageContext.getOut().print(version);
    }
    return SKIP_BODY;
}
Also used : Page(org.apache.wiki.api.core.Page)

Example 94 with Page

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

the class DefaultAuthorizationManager method checkPermission.

/**
 * {@inheritDoc}
 */
@Override
public boolean checkPermission(final Session session, final Permission permission) {
    // A slight sanity check.
    if (session == null || permission == null) {
        fireEvent(WikiSecurityEvent.ACCESS_DENIED, null, permission);
        return false;
    }
    final Principal user = session.getLoginPrincipal();
    // Always allow the action if user has AllPermission
    final Permission allPermission = new AllPermission(m_engine.getApplicationName());
    final boolean hasAllPermission = checkStaticPermission(session, allPermission);
    if (hasAllPermission) {
        fireEvent(WikiSecurityEvent.ACCESS_ALLOWED, user, permission);
        return true;
    }
    // If the user doesn't have *at least* the permission granted by policy, return false.
    final boolean hasPolicyPermission = checkStaticPermission(session, permission);
    if (!hasPolicyPermission) {
        fireEvent(WikiSecurityEvent.ACCESS_DENIED, user, permission);
        return false;
    }
    // If this isn't a PagePermission, it's allowed
    if (!(permission instanceof PagePermission)) {
        fireEvent(WikiSecurityEvent.ACCESS_ALLOWED, user, permission);
        return true;
    }
    // If the page or ACL is null, it's allowed.
    final String pageName = ((PagePermission) permission).getPage();
    final Page page = m_engine.getManager(PageManager.class).getPage(pageName);
    final Acl acl = (page == null) ? null : m_engine.getManager(AclManager.class).getPermissions(page);
    if (page == null || acl == null || acl.isEmpty()) {
        fireEvent(WikiSecurityEvent.ACCESS_ALLOWED, user, permission);
        return true;
    }
    // Next, iterate through the Principal objects assigned this permission. If the context's subject possesses
    // any of these, the action is allowed.
    final Principal[] aclPrincipals = acl.findPrincipals(permission);
    log.debug("Checking ACL entries...");
    log.debug("Acl for this page is: " + acl);
    log.debug("Checking for principal: " + Arrays.toString(aclPrincipals));
    log.debug("Permission: " + permission);
    for (Principal aclPrincipal : aclPrincipals) {
        // If the ACL principal we're looking at is unresolved, try to resolve it here & correct the Acl
        if (aclPrincipal instanceof UnresolvedPrincipal) {
            final AclEntry aclEntry = acl.getAclEntry(aclPrincipal);
            aclPrincipal = resolvePrincipal(aclPrincipal.getName());
            if (aclEntry != null && !(aclPrincipal instanceof UnresolvedPrincipal)) {
                aclEntry.setPrincipal(aclPrincipal);
            }
        }
        if (hasRoleOrPrincipal(session, aclPrincipal)) {
            fireEvent(WikiSecurityEvent.ACCESS_ALLOWED, user, permission);
            return true;
        }
    }
    fireEvent(WikiSecurityEvent.ACCESS_DENIED, user, permission);
    return false;
}
Also used : PageManager(org.apache.wiki.pages.PageManager) PagePermission(org.apache.wiki.auth.permissions.PagePermission) AllPermission(org.apache.wiki.auth.permissions.AllPermission) Permission(java.security.Permission) AclEntry(org.apache.wiki.api.core.AclEntry) AllPermission(org.apache.wiki.auth.permissions.AllPermission) Page(org.apache.wiki.api.core.Page) Acl(org.apache.wiki.api.core.Acl) Principal(java.security.Principal) UnresolvedPrincipal(org.apache.wiki.auth.acl.UnresolvedPrincipal) PagePermission(org.apache.wiki.auth.permissions.PagePermission) UnresolvedPrincipal(org.apache.wiki.auth.acl.UnresolvedPrincipal)

Example 95 with Page

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

the class DefaultAttachmentManager method getAttachmentInfo.

/**
 * {@inheritDoc}
 */
@Override
public Attachment getAttachmentInfo(final Context context, String attachmentname, final int version) throws ProviderException {
    if (m_provider == null) {
        return null;
    }
    Page currentPage = null;
    if (context != null) {
        currentPage = context.getPage();
    }
    // Figure out the parent page of this attachment.  If we can't find it, we'll assume this refers directly to the attachment.
    final int cutpt = attachmentname.lastIndexOf('/');
    if (cutpt != -1) {
        String parentPage = attachmentname.substring(0, cutpt);
        parentPage = MarkupParser.cleanLink(parentPage);
        attachmentname = attachmentname.substring(cutpt + 1);
        // If we for some reason have an empty parent page name; this can't be an attachment
        if (parentPage.isEmpty()) {
            return null;
        }
        currentPage = m_engine.getManager(PageManager.class).getPage(parentPage);
        // legacy charset is a subset of the full allowed set.
        if (currentPage == null) {
            currentPage = m_engine.getManager(PageManager.class).getPage(MarkupParser.wikifyLink(parentPage));
        }
    }
    // If the page cannot be determined, we cannot possibly find the attachments.
    if (currentPage == null || currentPage.getName().isEmpty()) {
        return null;
    }
    // Finally, figure out whether this is a real attachment or a generated attachment.
    Attachment att = getDynamicAttachment(currentPage.getName() + "/" + attachmentname);
    if (att == null) {
        att = m_provider.getAttachmentInfo(currentPage, attachmentname, version);
    }
    return att;
}
Also used : Page(org.apache.wiki.api.core.Page) Attachment(org.apache.wiki.api.core.Attachment)

Aggregations

Page (org.apache.wiki.api.core.Page)181 PageManager (org.apache.wiki.pages.PageManager)106 Test (org.junit.jupiter.api.Test)71 Context (org.apache.wiki.api.core.Context)46 Engine (org.apache.wiki.api.core.Engine)30 Attachment (org.apache.wiki.api.core.Attachment)27 ProviderException (org.apache.wiki.api.exceptions.ProviderException)22 Date (java.util.Date)21 WikiPage (org.apache.wiki.WikiPage)18 ReferenceManager (org.apache.wiki.references.ReferenceManager)16 RenderingManager (org.apache.wiki.render.RenderingManager)15 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)14 File (java.io.File)11 ArrayList (java.util.ArrayList)10 Calendar (java.util.Calendar)10 Hashtable (java.util.Hashtable)10 IOException (java.io.IOException)9 Vector (java.util.Vector)9 TestEngine (org.apache.wiki.TestEngine)9 PagePermission (org.apache.wiki.auth.permissions.PagePermission)8