Search in sources :

Example 1 with Command

use of org.apache.wiki.ui.Command in project jspwiki by apache.

the class SearchResultIteratorTag method nextResult.

private int nextResult() {
    if (m_iterator != null && m_iterator.hasNext() && m_count++ < m_maxItems) {
        SearchResult r = (SearchResult) m_iterator.next();
        // Create a wiki context for the result
        WikiEngine engine = m_wikiContext.getEngine();
        HttpServletRequest request = m_wikiContext.getHttpRequest();
        Command command = PageCommand.VIEW.targetedCommand(r.getPage());
        WikiContext context = new WikiContext(engine, request, command);
        // Stash it in the page context
        pageContext.setAttribute(WikiTagBase.ATTR_CONTEXT, context, PageContext.REQUEST_SCOPE);
        pageContext.setAttribute(getId(), r);
        return EVAL_BODY_BUFFERED;
    }
    return SKIP_BODY;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) WikiContext(org.apache.wiki.WikiContext) Command(org.apache.wiki.ui.Command) PageCommand(org.apache.wiki.ui.PageCommand) SearchResult(org.apache.wiki.search.SearchResult) WikiEngine(org.apache.wiki.WikiEngine)

Example 2 with Command

use of org.apache.wiki.ui.Command in project jspwiki by apache.

the class PermissionTag method checkPermission.

/**
 *  Checks a single permission.
 *
 *  @param permission
 *  @return true if granted, false if not
 */
private boolean checkPermission(String permission) {
    WikiSession session = m_wikiContext.getWikiSession();
    WikiPage page = m_wikiContext.getPage();
    AuthorizationManager mgr = m_wikiContext.getEngine().getAuthorizationManager();
    boolean gotPermission = false;
    if (CREATE_GROUPS.equals(permission) || CREATE_PAGES.equals(permission) || EDIT_PREFERENCES.equals(permission) || EDIT_PROFILE.equals(permission) || LOGIN.equals(permission)) {
        gotPermission = mgr.checkPermission(session, new WikiPermission(page.getWiki(), permission));
    } else if (VIEW_GROUP.equals(permission) || EDIT_GROUP.equals(permission) || DELETE_GROUP.equals(permission)) {
        Command command = m_wikiContext.getCommand();
        gotPermission = false;
        if (command instanceof GroupCommand && command.getTarget() != null) {
            GroupPrincipal group = (GroupPrincipal) command.getTarget();
            String groupName = group.getName();
            String action = "view";
            if (EDIT_GROUP.equals(permission)) {
                action = "edit";
            } else if (DELETE_GROUP.equals(permission)) {
                action = "delete";
            }
            gotPermission = mgr.checkPermission(session, new GroupPermission(groupName, action));
        }
    } else if (ALL_PERMISSION.equals(permission)) {
        gotPermission = mgr.checkPermission(session, new AllPermission(m_wikiContext.getEngine().getApplicationName()));
    } else if (page != null) {
        // 
        if (EDIT.equals(permission)) {
            WikiPage latest = m_wikiContext.getEngine().getPage(page.getName());
            if (page.getVersion() != WikiProvider.LATEST_VERSION && latest.getVersion() != page.getVersion()) {
                return false;
            }
        }
        Permission p = PermissionFactory.getPagePermission(page, permission);
        gotPermission = mgr.checkPermission(session, p);
    }
    return gotPermission;
}
Also used : WikiSession(org.apache.wiki.WikiSession) GroupCommand(org.apache.wiki.ui.GroupCommand) Command(org.apache.wiki.ui.Command) GroupCommand(org.apache.wiki.ui.GroupCommand) GroupPrincipal(org.apache.wiki.auth.GroupPrincipal) WikiPage(org.apache.wiki.WikiPage) WikiPermission(org.apache.wiki.auth.permissions.WikiPermission) AllPermission(org.apache.wiki.auth.permissions.AllPermission) Permission(java.security.Permission) GroupPermission(org.apache.wiki.auth.permissions.GroupPermission) AllPermission(org.apache.wiki.auth.permissions.AllPermission) GroupPermission(org.apache.wiki.auth.permissions.GroupPermission) AuthorizationManager(org.apache.wiki.auth.AuthorizationManager) WikiPermission(org.apache.wiki.auth.permissions.WikiPermission)

Example 3 with Command

use of org.apache.wiki.ui.Command in project jspwiki by apache.

the class WikiContext method findCommand.

/**
 * Looks up and returns a PageCommand based on a supplied WikiPage and HTTP
 * request. First, the appropriate Command is obtained by examining the HTTP
 * request; the default is {@link PageCommand#VIEW}. If the Command is a
 * PageCommand (and it should be, in most cases), a targeted Command is
 * created using the (non-<code>null</code>) WikiPage as target.
 * @param engine the wiki engine
 * @param request the HTTP request
 * @param page the wiki page
 * @return the correct command
 */
protected static Command findCommand(WikiEngine engine, HttpServletRequest request, WikiPage page) {
    String defaultContext = PageCommand.VIEW.getRequestContext();
    Command command = engine.getCommandResolver().findCommand(request, defaultContext);
    if (command instanceof PageCommand && page != null) {
        command = command.targetedCommand(page);
    }
    return command;
}
Also used : Command(org.apache.wiki.ui.Command) GroupCommand(org.apache.wiki.ui.GroupCommand) PageCommand(org.apache.wiki.ui.PageCommand) WikiCommand(org.apache.wiki.ui.WikiCommand) PageCommand(org.apache.wiki.ui.PageCommand)

Aggregations

Command (org.apache.wiki.ui.Command)3 GroupCommand (org.apache.wiki.ui.GroupCommand)2 PageCommand (org.apache.wiki.ui.PageCommand)2 Permission (java.security.Permission)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 WikiContext (org.apache.wiki.WikiContext)1 WikiEngine (org.apache.wiki.WikiEngine)1 WikiPage (org.apache.wiki.WikiPage)1 WikiSession (org.apache.wiki.WikiSession)1 AuthorizationManager (org.apache.wiki.auth.AuthorizationManager)1 GroupPrincipal (org.apache.wiki.auth.GroupPrincipal)1 AllPermission (org.apache.wiki.auth.permissions.AllPermission)1 GroupPermission (org.apache.wiki.auth.permissions.GroupPermission)1 WikiPermission (org.apache.wiki.auth.permissions.WikiPermission)1 SearchResult (org.apache.wiki.search.SearchResult)1 WikiCommand (org.apache.wiki.ui.WikiCommand)1