Search in sources :

Example 36 with Engine

use of org.apache.wiki.api.core.Engine 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 37 with Engine

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

the class UserNameTag method doWikiStartTag.

@Override
public final int doWikiStartTag() throws IOException {
    final Engine engine = m_wikiContext.getEngine();
    final Session wikiSession = Wiki.session().find(engine, (HttpServletRequest) pageContext.getRequest());
    final Principal user = wikiSession.getUserPrincipal();
    if (user != null) {
        if (VALID_USER_NAME_PATTERN.matcher(user.getName()).matches()) {
            pageContext.getOut().print(TextUtil.replaceEntities(user.getName()));
        } else {
            pageContext.getOut().print(Preferences.getBundle(m_wikiContext, InternationalizationManager.CORE_BUNDLE).getString("security.user.fullname.invalid"));
        }
    }
    return SKIP_BODY;
}
Also used : Engine(org.apache.wiki.api.core.Engine) Principal(java.security.Principal) Session(org.apache.wiki.api.core.Session)

Example 38 with Engine

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

the class VariableTag method doWikiStartTag.

@Override
public final int doWikiStartTag() throws JspException, IOException {
    final Engine engine = m_wikiContext.getEngine();
    final JspWriter out = pageContext.getOut();
    String msg = null;
    String value = null;
    try {
        value = engine.getManager(VariableManager.class).getValue(m_wikiContext, getVar());
    } catch (final NoSuchVariableException e) {
        msg = "No such variable: " + e.getMessage();
    } catch (final IllegalArgumentException e) {
        msg = "Incorrect variable name: " + e.getMessage();
    }
    if (value == null) {
        value = m_default;
    }
    if (value == null) {
        value = msg;
    }
    out.write(TextUtil.replaceEntities(value));
    return SKIP_BODY;
}
Also used : NoSuchVariableException(org.apache.wiki.api.exceptions.NoSuchVariableException) JspWriter(javax.servlet.jsp.JspWriter) Engine(org.apache.wiki.api.core.Engine)

Example 39 with Engine

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

the class CookieAuthenticationLoginModule method login.

/**
 * {@inheritDoc}
 *
 * @see javax.security.auth.spi.LoginModule#login()
 */
@Override
public boolean login() throws LoginException {
    // Otherwise, let's go and look for the cookie!
    final HttpRequestCallback hcb = new HttpRequestCallback();
    final WikiEngineCallback wcb = new WikiEngineCallback();
    final Callback[] callbacks = new Callback[] { hcb, wcb };
    try {
        m_handler.handle(callbacks);
        final HttpServletRequest request = hcb.getRequest();
        final String uid = getLoginCookie(request);
        if (uid != null) {
            final Engine engine = wcb.getEngine();
            final File cookieFile = getCookieFile(engine, uid);
            if (cookieFile != null && cookieFile.exists() && cookieFile.canRead()) {
                try (final Reader in = new BufferedReader(new InputStreamReader(Files.newInputStream(cookieFile.toPath()), StandardCharsets.UTF_8))) {
                    final String username = FileUtil.readContents(in);
                    log.debug("Logged in cookie authenticated name={}", username);
                    // If login succeeds, commit these principals/roles
                    m_principals.add(new WikiPrincipal(username, WikiPrincipal.LOGIN_NAME));
                    // Tag the file so that we know that it has been accessed recently.
                    return cookieFile.setLastModified(System.currentTimeMillis());
                } catch (final IOException e) {
                    return false;
                }
            }
        }
    } catch (final IOException e) {
        final String message = "IO exception; disallowing login.";
        log.error(message, e);
        throw new LoginException(message);
    } catch (final UnsupportedCallbackException e) {
        final String message = "Unable to handle callback; disallowing login.";
        log.error(message, e);
        throw new LoginException(message);
    }
    return false;
}
Also used : InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) Callback(javax.security.auth.callback.Callback) WikiPrincipal(org.apache.wiki.auth.WikiPrincipal) BufferedReader(java.io.BufferedReader) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) File(java.io.File) Engine(org.apache.wiki.api.core.Engine)

Example 40 with Engine

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

the class MetaWeblogHandler method editPost.

/**
 *  Allows the user to edit a post.  It does not allow general editability of wiki pages, because of the limitations of the metaWeblog API.
 */
boolean editPost(final String postid, final String username, final String password, final Hashtable<String, Object> content, final boolean publish) throws XmlRpcException {
    final Engine engine = m_context.getEngine();
    log.info("metaWeblog.editPost(" + postid + ") called");
    // FIXME: Is postid correct?  Should we determine it from the page name?
    final Page page = engine.getManager(PageManager.class).getPage(postid);
    checkPermissions(page, username, password, "edit");
    try {
        final Page entryPage = page.clone();
        entryPage.setAuthor(username);
        final Context context = Wiki.context().create(engine, entryPage);
        final StringBuilder text = new StringBuilder();
        text.append("!").append(content.get("title"));
        text.append("\n\n");
        text.append(content.get("description"));
        log.debug("Updating entry: " + text);
        engine.getManager(PageManager.class).saveText(context, text.toString());
    } catch (final Exception e) {
        log.error("Failed to create weblog entry", e);
        throw new XmlRpcException(0, "Failed to update weblog entry: " + e.getMessage());
    }
    return true;
}
Also used : Context(org.apache.wiki.api.core.Context) PageManager(org.apache.wiki.pages.PageManager) Page(org.apache.wiki.api.core.Page) Engine(org.apache.wiki.api.core.Engine) XmlRpcException(org.apache.xmlrpc.XmlRpcException) WikiSecurityException(org.apache.wiki.auth.WikiSecurityException) XmlRpcException(org.apache.xmlrpc.XmlRpcException)

Aggregations

Engine (org.apache.wiki.api.core.Engine)60 Page (org.apache.wiki.api.core.Page)30 PageManager (org.apache.wiki.pages.PageManager)20 ProviderException (org.apache.wiki.api.exceptions.ProviderException)11 Attachment (org.apache.wiki.api.core.Attachment)10 JspWriter (javax.servlet.jsp.JspWriter)9 Context (org.apache.wiki.api.core.Context)9 AttachmentManager (org.apache.wiki.attachment.AttachmentManager)8 Element (org.jdom2.Element)7 IOException (java.io.IOException)6 Calendar (java.util.Calendar)6 ResourceBundle (java.util.ResourceBundle)6 SimpleDateFormat (java.text.SimpleDateFormat)5 Date (java.util.Date)5 PageContext (javax.servlet.jsp.PageContext)5 Principal (java.security.Principal)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 PluginException (org.apache.wiki.api.exceptions.PluginException)4 RenderingManager (org.apache.wiki.render.RenderingManager)4 ArrayList (java.util.ArrayList)3