use of org.apache.wiki.WikiSession in project jspwiki by apache.
the class WikiServletFilter method doFilter.
/**
* Checks that the WikiEngine is running ok, wraps the current
* HTTP request, and sets the correct authentication state for the users's
* WikiSession. First, the method {@link org.apache.wiki.auth.AuthenticationManager#login(HttpServletRequest)}
* executes, which sets the authentication state. Then, the request is wrapped with a
* {@link WikiRequestWrapper}.
* @param request the current HTTP request object
* @param response the current HTTP response object
* @param chain The Filter chain passed down.
* @throws ServletException if {@link org.apache.wiki.auth.AuthenticationManager#login(HttpServletRequest)} fails for any reason
* @throws IOException If writing to the servlet response fails.
*/
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//
if (chain == null) {
throw new ServletException("FilterChain is null, even if it should not be. Please report this to the jspwiki development team.");
}
if (m_engine == null) {
PrintWriter out = response.getWriter();
out.print("<html><head><title>Fatal problem with JSPWiki</title></head>");
out.print("<body>");
out.print("<h1>JSPWiki has not been started</h1>");
out.print("<p>JSPWiki is not running. This is probably due to a configuration error in your jspwiki.properties file, ");
out.print("or a problem with your servlet container. Please double-check everything before issuing a bug report ");
out.print("at jspwiki.apache.org.</p>");
out.print("<p>We apologize for the inconvenience. No, really, we do. We're trying to ");
out.print("JSPWiki as easy as we can, but there is only so much we have time to test ");
out.print("platforms.</p>");
out.print("<p>Please go to the <a href='Install.jsp'>installer</a> to continue.</p>");
out.print("</body></html>");
return;
}
// If we haven't done so, wrap the request
HttpServletRequest httpRequest = (HttpServletRequest) request;
// Set the character encoding
httpRequest.setCharacterEncoding(m_engine.getContentEncoding());
if (!isWrapped(request)) {
// Prepare the WikiSession
try {
m_engine.getAuthenticationManager().login(httpRequest);
WikiSession wikiSession = SessionMonitor.getInstance(m_engine).find(httpRequest.getSession());
httpRequest = new WikiRequestWrapper(m_engine, httpRequest);
if (log.isDebugEnabled()) {
log.debug("Executed security filters for user=" + wikiSession.getLoginPrincipal().getName() + ", path=" + httpRequest.getRequestURI());
}
} catch (WikiSecurityException e) {
throw new ServletException(e);
}
}
try {
NDC.push(m_engine.getApplicationName() + ":" + httpRequest.getRequestURL());
chain.doFilter(httpRequest, response);
} finally {
NDC.pop();
NDC.remove();
}
}
use of org.apache.wiki.WikiSession in project jspwiki by apache.
the class UserNameTag method doWikiStartTag.
public final int doWikiStartTag() throws IOException {
WikiEngine engine = this.m_wikiContext.getEngine();
WikiSession wikiSession = WikiSession.getWikiSession(engine, (HttpServletRequest) pageContext.getRequest());
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;
}
use of org.apache.wiki.WikiSession in project jspwiki by apache.
the class UserProfileTag method doWikiStartTag.
public final int doWikiStartTag() throws IOException, WikiSecurityException {
UserManager manager = m_wikiContext.getEngine().getUserManager();
UserProfile profile = manager.getUserProfile(m_wikiContext.getWikiSession());
String result = null;
if (EXISTS.equals(m_prop) || NOT_NEW.equals(m_prop)) {
return profile.isNew() ? SKIP_BODY : EVAL_BODY_INCLUDE;
} else if (NEW.equals(m_prop) || NOT_EXISTS.equals(m_prop)) {
return profile.isNew() ? EVAL_BODY_INCLUDE : SKIP_BODY;
} else if (CREATED.equals(m_prop) && profile.getCreated() != null) {
result = profile.getCreated().toString();
} else if (EMAIL.equals(m_prop)) {
result = profile.getEmail();
} else if (FULLNAME.equals(m_prop)) {
result = profile.getFullname();
} else if (GROUPS.equals(m_prop)) {
result = printGroups(m_wikiContext);
} else if (LOGINNAME.equals(m_prop)) {
result = profile.getLoginName();
} else if (MODIFIED.equals(m_prop) && profile.getLastModified() != null) {
result = profile.getLastModified().toString();
} else if (ROLES.equals(m_prop)) {
result = printRoles(m_wikiContext);
} else if (WIKINAME.equals(m_prop)) {
result = profile.getWikiName();
if (result == null) {
//
// Default back to the declared user name
//
WikiEngine engine = this.m_wikiContext.getEngine();
WikiSession wikiSession = WikiSession.getWikiSession(engine, (HttpServletRequest) pageContext.getRequest());
Principal user = wikiSession.getUserPrincipal();
if (user != null) {
result = user.getName();
}
}
} else if (CHANGE_PASSWORD.equals(m_prop) || CHANGE_LOGIN_NAME.equals(m_prop)) {
AuthenticationManager authMgr = m_wikiContext.getEngine().getAuthenticationManager();
if (!authMgr.isContainerAuthenticated()) {
return EVAL_BODY_INCLUDE;
}
} else if (NOT_CHANGE_PASSWORD.equals(m_prop) || NOT_CHANGE_LOGIN_NAME.equals(m_prop)) {
AuthenticationManager authMgr = m_wikiContext.getEngine().getAuthenticationManager();
if (authMgr.isContainerAuthenticated()) {
return EVAL_BODY_INCLUDE;
}
}
if (result != null) {
pageContext.getOut().print(TextUtil.replaceEntities(result));
}
return SKIP_BODY;
}
use of org.apache.wiki.WikiSession in project jspwiki by apache.
the class MessagesTag method doWikiStartTag.
public final int doWikiStartTag() throws IOException {
WikiSession session = m_wikiContext.getWikiSession();
if (CLEAR.equals(m_action)) {
if (m_topic == null) {
session.clearMessages();
} else {
session.clearMessages(m_topic);
}
} else {
String[] messages = (m_topic == null) ? session.getMessages() : session.getMessages(m_topic);
if (messages.length > 0) {
StringBuilder sb = new StringBuilder();
if (messages.length == 1) {
sb.append("<div class=\"" + m_div + "\">" + m_prefix + TextUtil.replaceEntities(messages[0]) + "</div>");
} else {
sb.append("<div class=\"" + m_div + "\">" + m_prefix);
sb.append("<ul>");
for (int i = 0; i < messages.length; i++) {
sb.append("<li>" + TextUtil.replaceEntities(messages[i]) + "</li>");
}
sb.append("</ul></div>");
}
pageContext.getOut().println(sb.toString());
}
}
return SKIP_BODY;
}
use of org.apache.wiki.WikiSession in project jspwiki by apache.
the class RSSGenerator method generateFullWikiRSS.
/**
* Generates an RSS feed for the entire wiki. Each item should be an instance of the RSSItem class.
*
* @param wikiContext A WikiContext
* @param feed A Feed to generate the feed to.
* @return feed.getString().
*/
protected String generateFullWikiRSS(WikiContext wikiContext, Feed feed) {
feed.setChannelTitle(m_engine.getApplicationName());
feed.setFeedURL(m_engine.getBaseURL());
feed.setChannelLanguage(m_channelLanguage);
feed.setChannelDescription(m_channelDescription);
Collection changed = m_engine.getRecentChanges();
WikiSession session = WikiSession.guestSession(m_engine);
int items = 0;
for (Iterator i = changed.iterator(); i.hasNext() && items < 15; items++) {
WikiPage page = (WikiPage) i.next();
if (!m_engine.getAuthorizationManager().checkPermission(session, new PagePermission(page, PagePermission.VIEW_ACTION))) {
// No permission, skip to the next one.
continue;
}
Entry e = new Entry();
e.setPage(page);
String url;
if (page instanceof Attachment) {
url = m_engine.getURL(WikiContext.ATTACH, page.getName(), null, true);
} else {
url = m_engine.getURL(WikiContext.VIEW, page.getName(), null, true);
}
e.setURL(url);
e.setTitle(page.getName());
e.setContent(getEntryDescription(page));
e.setAuthor(getAuthor(page));
feed.addEntry(e);
}
return feed.getString();
}
Aggregations