Search in sources :

Example 11 with InternalWikiException

use of org.apache.wiki.InternalWikiException in project jspwiki by apache.

the class CommentLinkTag method doWikiStartTag.

/**
 *  {@inheritDoc}
 */
@Override
public final int doWikiStartTag() throws IOException {
    WikiPage page = null;
    String pageName = null;
    // 
    if (m_pageName == null) {
        page = m_wikiContext.getPage();
        if (page == null) {
            // You can't call this on the page itself anyways.
            return SKIP_BODY;
        }
        pageName = page.getName();
    } else {
        pageName = m_pageName;
    }
    // 
    // Finally, print out the correct link, according to what
    // user commanded.
    // 
    JspWriter out = pageContext.getOut();
    switch(m_format) {
        case ANCHOR:
            out.print("<a href=\"" + getCommentURL(pageName) + "\">");
            break;
        case URL:
            out.print(getCommentURL(pageName));
            break;
        default:
            throw new InternalWikiException("Impossible format " + m_format);
    }
    return EVAL_BODY_INCLUDE;
}
Also used : WikiPage(org.apache.wiki.WikiPage) JspWriter(javax.servlet.jsp.JspWriter) InternalWikiException(org.apache.wiki.InternalWikiException)

Example 12 with InternalWikiException

use of org.apache.wiki.InternalWikiException in project jspwiki by apache.

the class SecurityVerifier method containerRoleTable.

/**
 * Formats and returns an HTML table containing the roles the web container
 * is aware of, and whether each role maps to particular JSPs. This method
 * throws an {@link IllegalStateException} if the authorizer is not of type
 * {@link org.apache.wiki.auth.authorize.WebContainerAuthorizer}
 * @return the formatted HTML table containing the result of the tests
 * @throws WikiException if tests fail for unexpected reasons
 */
public String containerRoleTable() throws WikiException {
    AuthorizationManager authorizationManager = m_engine.getAuthorizationManager();
    Authorizer authorizer = authorizationManager.getAuthorizer();
    // If authorizer not WebContainerAuthorizer, print error message
    if (!(authorizer instanceof WebContainerAuthorizer)) {
        throw new IllegalStateException("Authorizer should be WebContainerAuthorizer");
    }
    // Now, print a table with JSP pages listed on the left, and
    // an evaluation of each pages' constraints for each role
    // we discovered
    StringBuilder s = new StringBuilder();
    Principal[] roles = authorizer.getRoles();
    s.append("<table class=\"wikitable\" border=\"1\">\n");
    s.append("<thead>\n");
    s.append("  <tr>\n");
    s.append("    <th rowspan=\"2\">Action</th>\n");
    s.append("    <th rowspan=\"2\">Page</th>\n");
    s.append("    <th colspan=\"" + roles.length + 1 + "\">Roles</th>\n");
    s.append("  </tr>\n");
    s.append("  <tr>\n");
    s.append("    <th>Anonymous</th>\n");
    for (Principal role : roles) {
        s.append("    <th>" + role.getName() + "</th>\n");
    }
    s.append("</tr>\n");
    s.append("</thead>\n");
    s.append("<tbody>\n");
    try {
        WebContainerAuthorizer wca = (WebContainerAuthorizer) authorizer;
        for (int i = 0; i < CONTAINER_ACTIONS.length; i++) {
            String action = CONTAINER_ACTIONS[i];
            String jsp = CONTAINER_JSPS[i];
            // Print whether the page is constrained for each role
            boolean allowsAnonymous = !wca.isConstrained(jsp, Role.ALL);
            s.append("  <tr>\n");
            s.append("    <td>" + action + "</td>\n");
            s.append("    <td>" + jsp + "</td>\n");
            s.append("    <td title=\"");
            s.append(allowsAnonymous ? "ALLOW: " : "DENY: ");
            s.append(jsp);
            s.append(" Anonymous");
            s.append("\"");
            s.append(allowsAnonymous ? BG_GREEN + ">" : BG_RED + ">");
            s.append("&nbsp;</td>\n");
            for (Principal role : roles) {
                boolean allowed = allowsAnonymous || wca.isConstrained(jsp, (Role) role);
                s.append("    <td title=\"");
                s.append(allowed ? "ALLOW: " : "DENY: ");
                s.append(jsp);
                s.append(" ");
                s.append(role.getClass().getName());
                s.append(" &quot;");
                s.append(role.getName());
                s.append("&quot;");
                s.append("\"");
                s.append(allowed ? BG_GREEN + ">" : BG_RED + ">");
                s.append("&nbsp;</td>\n");
            }
            s.append("  </tr>\n");
        }
    } catch (JDOMException e) {
        // If we couldn't evaluate constraints it means
        // there's some sort of IO mess or parsing issue
        LOG.error("Malformed XML in web.xml", e);
        throw new InternalWikiException(e.getClass().getName() + ": " + e.getMessage(), e);
    }
    s.append("</tbody>\n");
    s.append("</table>\n");
    return s.toString();
}
Also used : JDOMException(org.jdom2.JDOMException) InternalWikiException(org.apache.wiki.InternalWikiException) Role(org.apache.wiki.auth.authorize.Role) WebContainerAuthorizer(org.apache.wiki.auth.authorize.WebContainerAuthorizer) WebContainerAuthorizer(org.apache.wiki.auth.authorize.WebContainerAuthorizer) Principal(java.security.Principal)

Aggregations

InternalWikiException (org.apache.wiki.InternalWikiException)12 WikiPage (org.apache.wiki.WikiPage)4 IOException (java.io.IOException)3 MalformedPatternException (org.apache.oro.text.regex.MalformedPatternException)2 WikiEngine (org.apache.wiki.WikiEngine)2 JDOMException (org.jdom2.JDOMException)2 File (java.io.File)1 StringReader (java.io.StringReader)1 Principal (java.security.Principal)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Locale (java.util.Locale)1 MissingResourceException (java.util.MissingResourceException)1 NoSuchElementException (java.util.NoSuchElementException)1 Properties (java.util.Properties)1 TimeZone (java.util.TimeZone)1 JspWriter (javax.servlet.jsp.JspWriter)1 MatchResult (org.apache.oro.text.regex.MatchResult)1 PatternMatcher (org.apache.oro.text.regex.PatternMatcher)1 Perl5Matcher (org.apache.oro.text.regex.Perl5Matcher)1