This is an automated email from the ASF dual-hosted git repository. juanpablo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/jspwiki.git
commit 4eecb64c96ac679d7322528ab112c3dc9593d110 Author: Juan Pablo Santos RodrÃguez <[email protected]> AuthorDate: Thu Dec 2 17:55:47 2021 +0100 remove unneeded log enabled guards --- .../src/main/java/org/apache/wiki/WatchDog.java | 40 +++++------ .../src/main/java/org/apache/wiki/WikiContext.java | 26 ++++--- .../src/main/java/org/apache/wiki/WikiSession.java | 4 +- .../apache/wiki/attachment/AttachmentServlet.java | 45 ++++-------- .../wiki/auth/DefaultAuthenticationManager.java | 12 +--- .../java/org/apache/wiki/auth/SessionMonitor.java | 8 +-- .../wiki/auth/login/AbstractLoginModule.java | 10 +-- .../wiki/auth/login/AnonymousLoginModule.java | 28 +++----- .../auth/login/CookieAssertionLoginModule.java | 8 +-- .../login/CookieAuthenticationLoginModule.java | 8 +-- .../wiki/auth/login/UserDatabaseLoginModule.java | 42 ++++-------- .../wiki/auth/login/WebContainerLoginModule.java | 36 +++------- .../apache/wiki/filters/PingWeblogsComFilter.java | 4 +- .../apache/wiki/parser/JSPWikiMarkupParser.java | 9 +-- .../apache/wiki/plugin/AbstractReferralPlugin.java | 5 +- .../apache/wiki/plugin/ReferringPagesPlugin.java | 4 +- .../org/apache/wiki/rss/DefaultRSSGenerator.java | 4 +- .../apache/wiki/search/DefaultSearchManager.java | 10 +-- .../apache/wiki/search/LuceneSearchProvider.java | 8 +-- .../org/apache/wiki/ui/DefaultTemplateManager.java | 80 +--------------------- .../java/org/apache/wiki/ui/WikiServletFilter.java | 4 +- 21 files changed, 105 insertions(+), 290 deletions(-) diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WatchDog.java b/jspwiki-main/src/main/java/org/apache/wiki/WatchDog.java index 50f486c..ba0dfc8 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/WatchDog.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/WatchDog.java @@ -70,7 +70,7 @@ public final class WatchDog { WeakReference< WatchDog > w = c_kennel.get( t.hashCode() ); WatchDog wd = null; if( w != null ) { - wd = w.get(); + wd = w.get(); } if( w == null || wd == null ) { @@ -116,8 +116,8 @@ public final class WatchDog { private static void scrub() { // During finalization, the object may already be cleared (depending on the finalization order). Therefore, it's // possible that this method is called from another thread after the WatchDog itself has been cleared. - if( c_kennel == null ) { - return; + if( c_kennel.isEmpty() ) { + return; } for( final Map.Entry< Integer, WeakReference< WatchDog > > e : c_kennel.entrySet() ) { @@ -185,11 +185,7 @@ public final class WatchDog { * @param expectedCompletionTime The timeout in seconds. */ public void enterState( final String state, final int expectedCompletionTime ) { - if( log.isDebugEnabled() ){ - log.debug( m_watchable.getName() + ": Entering state " + state + - ", expected completion in " + expectedCompletionTime + " s"); - } - + log.debug( "{}: Entering state {}, expected completion in {} s", m_watchable.getName(), state, expectedCompletionTime ); synchronized( m_stateStack ) { final State st = new State( state, expectedCompletionTime ); m_stateStack.push( st ); @@ -217,9 +213,7 @@ public final class WatchDog { if( state == null || st.getState().equals( state ) ) { m_stateStack.pop(); - if( log.isDebugEnabled() ) { - log.debug( m_watchable.getName() + ": Exiting state " + st.getState() ); - } + log.debug( "{}: Exiting state {}", m_watchable.getName(), st.getState() ); } else { // FIXME: should actually go and fix things for that log.error( "exitState() called before enterState()" ); @@ -236,8 +230,8 @@ public final class WatchDog { * @return {@code true} if not empty, {@code false} otherwise. */ public boolean isStateStackNotEmpty() { - return !m_stateStack.isEmpty(); - } + return !m_stateStack.isEmpty(); + } /** * helper to see if the associated watchable is alive. @@ -245,13 +239,11 @@ public final class WatchDog { * @return {@code true} if it's alive, {@code false} otherwise. */ public boolean isWatchableAlive() { - return m_watchable != null && m_watchable.isAlive(); + return m_watchable != null && m_watchable.isAlive(); } private void check() { - if( log.isDebugEnabled() ) { - log.debug( "Checking watchdog '" + m_watchable.getName() + "'" ); - } + log.debug( "Checking watchdog '{}'", m_watchable.getName() ); synchronized( m_stateStack ) { if( !m_stateStack.empty() ) { @@ -260,14 +252,14 @@ public final class WatchDog { if( now > st.getExpiryTime() ) { log.info( "Watchable '" + m_watchable.getName() + "' exceeded timeout in state '" + st.getState() + - "' by " + (now - st.getExpiryTime()) / 1000 + " seconds" + - ( log.isDebugEnabled() ? "" : "Enable DEBUG-level logging to see stack traces." ) ); + "' by " + (now - st.getExpiryTime()) / 1000 + " seconds" + + ( log.isDebugEnabled() ? "" : "Enable DEBUG-level logging to see stack traces." ) ); dumpStackTraceForWatchable(); m_watchable.timeoutExceeded( st.getState() ); } } else { - log.warn( "Stack for " + m_watchable.getName() + " is empty!" ); + log.warn( "Stack for " + m_watchable.getName() + " is empty!" ); } } } @@ -277,7 +269,7 @@ public final class WatchDog { */ private void dumpStackTraceForWatchable() { if( !log.isDebugEnabled() ) { - return; + return; } final Map< Thread, StackTraceElement[] > stackTraces = Thread.getAllStackTraces(); @@ -345,12 +337,12 @@ public final class WatchDog { /** * Checks if the watchable is alive, and if it is, checks if the stack is finished. * - * If the watchable has been deleted in the mean time, will simply shut down itself. + * If the watchable has been deleted in the meantime, will simply shut down itself. */ @Override public void backgroundTask() { - if( c_kennel == null ) { - return; + if( c_kennel.isEmpty() ) { + return; } for( final Map.Entry< Integer, WeakReference< WatchDog > > entry : c_kennel.entrySet() ) { diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java index ff75b5e..3a632f2 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiContext.java @@ -217,11 +217,9 @@ public class WikiContext implements Context, Command { } // Debugging... - if( log.isDebugEnabled() ) { - final HttpSession session = ( request == null ) ? null : request.getSession( false ); - final String sid = session == null ? "(null)" : session.getId(); - log.debug( "Creating WikiContext for session ID=" + sid + "; target=" + getName() ); - } + final HttpSession session = ( request == null ) ? null : request.getSession( false ); + final String sid = session == null ? "(null)" : session.getId(); + log.debug( "Creating WikiContext for session ID={}; target={}", sid, getName() ); // Figure out what template to use setDefaultTemplate( request ); @@ -461,7 +459,7 @@ public class WikiContext implements Context, Command { /** * This method will safely return any HTTP parameters that might have been defined. You should use this method instead - * of peeking directly into the result of getHttpRequest(), since this method is smart enough to do all of the right things, + * of peeking directly into the result of getHttpRequest(), since this method is smart enough to do all the right things, * figure out UTF-8 encoded parameters, etc. * * @since 2.0.13. @@ -479,8 +477,8 @@ public class WikiContext implements Context, Command { } /** - * If the request did originate from a HTTP request, then the HTTP request can be fetched here. However, it the request - * did NOT originate from a HTTP request, then this method will return null, and YOU SHOULD CHECK FOR IT! + * If the request did originate from an HTTP request, then the HTTP request can be fetched here. However, if the request + * did NOT originate from an HTTP request, then this method will return null, and YOU SHOULD CHECK FOR IT! * * @return Null, if no HTTP request was done. * @since 2.0.13. @@ -554,7 +552,7 @@ public class WikiContext implements Context, Command { * A shortcut to generate a VIEW url. * * @param page The page to which to link. - * @return An URL to the page. This honours the current absolute/relative setting. + * @return A URL to the page. This honours the current absolute/relative setting. */ @Override public String getViewURL( final String page ) { @@ -562,11 +560,11 @@ public class WikiContext implements Context, Command { } /** - * Creates an URL for the given request context. + * Creates a URL for the given request context. * * @param context e.g. WikiContext.EDIT * @param page The page to which to link - * @return An URL to the page, honours the absolute/relative setting in jspwiki.properties + * @return A URL to the page, honours the absolute/relative setting in jspwiki.properties */ @Override public String getURL( final String context, final String page ) { @@ -574,14 +572,14 @@ public class WikiContext implements Context, Command { } /** - * Returns an URL from a page. It this WikiContext instance was constructed with an actual HttpServletRequest, we will attempt to + * Returns a URL from a page. It this WikiContext instance was constructed with an actual HttpServletRequest, we will attempt to * construct the URL using HttpUtil, which preserves the HTTPS portion if it was used. * * @param context The request context (e.g. WikiContext.UPLOAD) * @param page The page to which to link * @param params A list of parameters, separated with "&" * - * @return An URL to the given context and page. + * @return A URL to the given context and page. */ @Override public String getURL( final String context, final String page, final String params ) { @@ -686,7 +684,7 @@ public class WikiContext implements Context, Command { } /** - * Returns the permission required to successfully execute this context. For example, the a wiki context of VIEW for a certain page + * Returns the permission required to successfully execute this context. For example, a wiki context of VIEW for a certain page * means that the PagePermission "view" is required for the page. In some cases, no particular permission is required, in which case * a dummy permission will be returned ({@link java.util.PropertyPermission}<code> "os.name", "read"</code>). This method is guaranteed * to always return a valid, non-null permission. diff --git a/jspwiki-main/src/main/java/org/apache/wiki/WikiSession.java b/jspwiki-main/src/main/java/org/apache/wiki/WikiSession.java index 424f2b2..5be350b 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/WikiSession.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/WikiSession.java @@ -486,9 +486,7 @@ public class WikiSession implements Session { */ public static Session getWikiSession( final Engine engine, final HttpServletRequest request ) { if ( request == null ) { - if ( log.isDebugEnabled() ) { - log.debug( "Looking up WikiSession for NULL HttpRequest: returning guestSession()" ); - } + log.debug( "Looking up WikiSession for NULL HttpRequest: returning guestSession()" ); return staticGuestSession( engine ); } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/attachment/AttachmentServlet.java b/jspwiki-main/src/main/java/org/apache/wiki/attachment/AttachmentServlet.java index 1842239..bbabb1f 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/attachment/AttachmentServlet.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/attachment/AttachmentServlet.java @@ -79,30 +79,18 @@ import java.util.Properties; */ public class AttachmentServlet extends HttpServlet { - private static final int BUFFER_SIZE = 8192; - private static final long serialVersionUID = 3257282552187531320L; + private static final int BUFFER_SIZE = 8192; private Engine m_engine; private static final Logger log = LogManager.getLogger( AttachmentServlet.class ); + private static final String HDR_VERSION = "version"; - private static final String HDR_VERSION = "version"; - // private static final String HDR_NAME = "page"; - - /** Default expiry period is 1 day */ - protected static final long DEFAULT_EXPIRY = 1 * 24 * 60 * 60 * 1000; - - /** - * The maximum size that an attachment can be. - */ - private int m_maxSize = Integer.MAX_VALUE; - - /** - * List of attachment types which are allowed - */ + /** The maximum size that an attachment can be. */ + private int m_maxSize = Integer.MAX_VALUE; + /** List of attachment types which are allowed */ private String[] m_allowedPatterns; - private String[] m_forbiddenPatterns; // @@ -139,10 +127,10 @@ public class AttachmentServlet extends HttpServlet { if( !f.exists() ) { f.mkdirs(); } else if( !f.isDirectory() ) { - log.fatal( "A file already exists where the temporary dir is supposed to be: " + tmpDir + ". Please remove it." ); + log.fatal( "A file already exists where the temporary dir is supposed to be: {}. Please remove it.", tmpDir ); } - log.debug( "UploadServlet initialized. Using " + tmpDir + " for temporary storage." ); + log.debug( "UploadServlet initialized. Using {} for temporary storage.", tmpDir ); } private boolean isTypeAllowed( String name ) @@ -151,15 +139,13 @@ public class AttachmentServlet extends HttpServlet { name = name.toLowerCase(); - for( int i = 0; i < m_forbiddenPatterns.length; i++ ) - { - if( name.endsWith(m_forbiddenPatterns[i]) && !m_forbiddenPatterns[i].isEmpty() ) + for( final String m_forbiddenPattern : m_forbiddenPatterns ) { + if( name.endsWith( m_forbiddenPattern ) && !m_forbiddenPattern.isEmpty() ) return false; } - for( int i = 0; i < m_allowedPatterns.length; i++ ) - { - if( name.endsWith(m_allowedPatterns[i]) && !m_allowedPatterns[i].isEmpty() ) + for( final String m_allowedPattern : m_allowedPatterns ) { + if( name.endsWith( m_allowedPattern ) && !m_allowedPattern.isEmpty() ) return true; } @@ -258,10 +244,7 @@ public class AttachmentServlet extends HttpServlet { out.write( buffer, 0, read ); } } - - if( log.isDebugEnabled() ) { - log.debug( "Attachment "+att.getFileName()+" sent to "+req.getRemoteUser()+" on "+HttpUtil.getRemoteAddress(req) ); - } + log.debug( "Attachment {} sent to {} on {}", att.getFileName(), req.getRemoteUser(), HttpUtil.getRemoteAddress(req) ); if( nextPage != null ) { res.sendRedirect( validateNextPage( @@ -543,8 +526,8 @@ public class AttachmentServlet extends HttpServlet { throw new RedirectException("File could not be opened.", errorPage); } - // Check whether we already have this kind of a page. If the "page" parameter already defines an attachment - // name for an update, then we just use that file. Otherwise we create a new attachment, and use the + // Check whether we already have this kind of page. If the "page" parameter already defines an attachment + // name for an update, then we just use that file. Otherwise, we create a new attachment, and use the // filename given. Incidentally, this will also mean that if the user uploads a file with the exact // same name than some other previous attachment, then that attachment gains a new version. Attachment att = mgr.getAttachmentInfo( context.getPage().getName() ); diff --git a/jspwiki-main/src/main/java/org/apache/wiki/auth/DefaultAuthenticationManager.java b/jspwiki-main/src/main/java/org/apache/wiki/auth/DefaultAuthenticationManager.java index ed817ae..f698a59 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/auth/DefaultAuthenticationManager.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/DefaultAuthenticationManager.java @@ -274,9 +274,7 @@ public class DefaultAuthenticationManager implements AuthenticationManager { final HttpSession session = request.getSession(); final String sid = ( session == null ) ? "(null)" : session.getId(); - if( log.isDebugEnabled() ) { - log.debug( "Invalidating Session for session ID=" + sid ); - } + log.debug( "Invalidating Session for session ID= {}", sid ); // Retrieve the associated Session and clear the Principal set final Session wikiSession = Wiki.session().find( m_engine, request ); final Principal originalPrincipal = wikiSession.getLoginPrincipal(); @@ -411,17 +409,13 @@ public class DefaultAuthenticationManager implements AuthenticationManager { // Test the Authorizer if( authorizer.isUserInRole( session, role ) ) { fireEvent( WikiSecurityEvent.PRINCIPAL_ADD, role, session ); - if( log.isDebugEnabled() ) { - log.debug( "Added authorizer role " + role.getName() + "." ); - } + log.debug( "Added authorizer role {}.", role.getName() ); // If web authorizer, test the request.isInRole() method also } else if ( request != null && authorizer instanceof WebAuthorizer ) { final WebAuthorizer wa = ( WebAuthorizer )authorizer; if ( wa.isUserInRole( request, role ) ) { fireEvent( WikiSecurityEvent.PRINCIPAL_ADD, role, session ); - if ( log.isDebugEnabled() ) { - log.debug( "Added container role " + role.getName() + "." ); - } + log.debug( "Added container role {}.",role.getName() ); } } } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/auth/SessionMonitor.java b/jspwiki-main/src/main/java/org/apache/wiki/auth/SessionMonitor.java index 1f0e672..199eeb8 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/auth/SessionMonitor.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/SessionMonitor.java @@ -114,9 +114,7 @@ public class SessionMonitor implements HttpSessionListener { // If the weak reference returns a wiki session, return it if( storedSession != null ) { - if( log.isDebugEnabled() ) { - log.debug( "Looking up WikiSession for session ID=" + sid + "... found it" ); - } + log.debug( "Looking up WikiSession for session ID={}... found it", sid ); wikiSession = storedSession; } @@ -169,9 +167,7 @@ public class SessionMonitor implements HttpSessionListener { * @return a new guest session */ private Session createGuestSessionFor( final String sessionId ) { - if( log.isDebugEnabled() ) { - log.debug( "Session for session ID=" + sessionId + "... not found. Creating guestSession()" ); - } + log.debug( "Session for session ID={}... not found. Creating guestSession()", sessionId ); final Session wikiSession = Wiki.session().guest( m_engine ); synchronized( m_sessions ) { m_sessions.put( sessionId, wikiSession ); diff --git a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/AbstractLoginModule.java b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/AbstractLoginModule.java index a473283..02ac92d 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/AbstractLoginModule.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/AbstractLoginModule.java @@ -100,9 +100,7 @@ public abstract class AbstractLoginModule implements LoginModule { if ( succeeded() ) { for ( final Principal principal : m_principals ) { m_subject.getPrincipals().add( principal ); - if ( log.isDebugEnabled() ) { - log.debug("Committed Principal " + principal.getName() ); - } + log.debug("Committed Principal {}", principal.getName() ); } return true; } @@ -186,12 +184,10 @@ public abstract class AbstractLoginModule implements LoginModule { * @param principals the principals to remove */ private void removePrincipals( final Collection<Principal> principals ) { - for ( final Principal principal : principals ) { + for( final Principal principal : principals ) { if ( m_subject.getPrincipals().contains( principal ) ) { m_subject.getPrincipals().remove( principal ); - if ( log.isDebugEnabled() ) { - log.debug("Removed Principal " + principal.getName() ); - } + log.debug("Removed Principal {}", principal.getName() ); } } } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/AnonymousLoginModule.java b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/AnonymousLoginModule.java index aa0887e..da7fd50 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/AnonymousLoginModule.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/AnonymousLoginModule.java @@ -62,46 +62,38 @@ public class AnonymousLoginModule extends AbstractLoginModule protected static final Logger log = LogManager.getLogger( AnonymousLoginModule.class ); /** + * {@inheritDoc} + * * Logs in the user by calling back to the registered CallbackHandler with an * HttpRequestCallback. The CallbackHandler must supply the current servlet * HTTP request as its response. * @return the result of the login; this will always be <code>true</code>. * @see javax.security.auth.spi.LoginModule#login() - * @throws {@inheritDoc} + * @throws LoginException if unable to handle callback */ public boolean login() throws LoginException { // Let's go and make a Principal based on the IP address final HttpRequestCallback hcb = new HttpRequestCallback(); - final Callback[] callbacks = new Callback[] - { hcb }; - try - { + final Callback[] callbacks = new Callback[]{ hcb }; + try { m_handler.handle( callbacks ); final HttpServletRequest request = hcb.getRequest(); final WikiPrincipal ipAddr = new WikiPrincipal( HttpUtil.getRemoteAddress(request) ); - if ( log.isDebugEnabled() ) - { - final HttpSession session = request.getSession( false ); - final String sid = (session == null) ? NULL : session.getId(); - log.debug("Logged in session ID=" + sid + "; IP=" + ipAddr); - } + final HttpSession session = request.getSession( false ); + final String sid = (session == null) ? NULL : session.getId(); + log.debug("Logged in session ID={}; IP={}", sid, ipAddr); // If login succeeds, commit these principals/roles m_principals.add( ipAddr ); return true; - } - catch( final IOException e ) - { + } catch( final IOException e ) { log.error("IOException: " + e.getMessage()); return false; - } - catch( final UnsupportedCallbackException e ) - { + } catch( final UnsupportedCallbackException e ) { final String message = "Unable to handle callback, disallowing login."; log.error( message, e ); throw new LoginException( message ); } - } } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/CookieAssertionLoginModule.java b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/CookieAssertionLoginModule.java index 54489b1..7a11150 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/CookieAssertionLoginModule.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/CookieAssertionLoginModule.java @@ -84,15 +84,11 @@ public class CookieAssertionLoginModule extends AbstractLoginModule { final String sid = ( session == null ) ? NULL : session.getId(); final String name = (request != null) ? getUserCookie( request ) : null; if ( name == null ) { - if ( log.isDebugEnabled() ) { - log.debug( "No cookie " + PREFS_COOKIE_NAME + " present in session ID=: " + sid ); - } + log.debug( "No cookie {} present in session ID=: {}", PREFS_COOKIE_NAME, sid ); throw new FailedLoginException( "The user cookie was not found." ); } - if ( log.isDebugEnabled() ) { - log.debug( "Logged in session ID=" + sid + "; asserted=" + name ); - } + log.debug( "Logged in session ID={}; asserted={}", sid, name ); // If login succeeds, commit these principals/roles m_principals.add( new WikiPrincipal( name, WikiPrincipal.FULL_NAME ) ); return true; diff --git a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/CookieAuthenticationLoginModule.java b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/CookieAuthenticationLoginModule.java index 336da6d..82f2382 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/CookieAuthenticationLoginModule.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/CookieAuthenticationLoginModule.java @@ -122,9 +122,7 @@ public class CookieAuthenticationLoginModule extends AbstractLoginModule { 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 ); - if( log.isDebugEnabled() ) { - log.debug( "Logged in cookie authenticated name={}", username ); - } + log.debug( "Logged in cookie authenticated name={}", username ); // If login succeeds, commit these principals/roles m_principals.add( new WikiPrincipal( username, WikiPrincipal.LOGIN_NAME ) ); @@ -220,9 +218,7 @@ public class CookieAuthenticationLoginModule extends AbstractLoginModule { // Write the cookie content to the cookie store file. try( final Writer out = new BufferedWriter( new OutputStreamWriter( Files.newOutputStream( cf.toPath() ), StandardCharsets.UTF_8 ) ) ) { FileUtil.copyContents( new StringReader( username ), out ); - if( log.isDebugEnabled() ) { - log.debug( "Created login cookie for user {} for {} days", username, days ); - } + log.debug( "Created login cookie for user {} for {} days", username, days ); } catch( final IOException ex ) { log.error( "Unable to create cookie file to store user id: {}", uid ); } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/UserDatabaseLoginModule.java b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/UserDatabaseLoginModule.java index 34dbfd6..7053f74 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/UserDatabaseLoginModule.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/UserDatabaseLoginModule.java @@ -18,7 +18,12 @@ */ package org.apache.wiki.auth.login; -import java.io.IOException; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.apache.wiki.auth.NoSuchPrincipalException; +import org.apache.wiki.auth.WikiPrincipal; +import org.apache.wiki.auth.user.UserDatabase; +import org.apache.wiki.auth.user.UserProfile; import javax.security.auth.callback.Callback; import javax.security.auth.callback.NameCallback; @@ -26,14 +31,7 @@ import javax.security.auth.callback.PasswordCallback; import javax.security.auth.callback.UnsupportedCallbackException; import javax.security.auth.login.FailedLoginException; import javax.security.auth.login.LoginException; - -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import org.apache.wiki.auth.NoSuchPrincipalException; -import org.apache.wiki.auth.WikiPrincipal; -import org.apache.wiki.auth.user.UserDatabase; -import org.apache.wiki.auth.user.UserProfile; +import java.io.IOException; /** * <p> @@ -55,8 +53,7 @@ import org.apache.wiki.auth.user.UserProfile; * </p> * @since 2.3 */ -public class UserDatabaseLoginModule extends AbstractLoginModule -{ +public class UserDatabaseLoginModule extends AbstractLoginModule { private static final Logger log = LogManager.getLogger( UserDatabaseLoginModule.class ); @@ -80,18 +77,13 @@ public class UserDatabaseLoginModule extends AbstractLoginModule final String password = new String( pcb.getPassword() ); // Look up the user and compare the password hash - if ( db == null ) - { + if ( db == null ) { throw new FailedLoginException( "No user database: check the callback handler code!" ); } final UserProfile profile = db.findByLoginName( username ); final String storedPassword = profile.getPassword(); - if ( storedPassword != null && db.validatePassword( username, password ) ) - { - if ( log.isDebugEnabled() ) - { - log.debug( "Logged in user database user " + username ); - } + if ( storedPassword != null && db.validatePassword( username, password ) ) { + log.debug( "Logged in user database user {}", username ); // If login succeeds, commit these principals/roles m_principals.add( new WikiPrincipal( username, WikiPrincipal.LOGIN_NAME ) ); @@ -99,21 +91,15 @@ public class UserDatabaseLoginModule extends AbstractLoginModule return true; } throw new FailedLoginException( "The username or password is incorrect." ); - } - catch( final IOException e ) - { + } catch( final IOException e ) { final String message = "IO exception; disallowing login."; log.error( message, e ); throw new LoginException( message ); - } - catch( final UnsupportedCallbackException e ) - { + } catch( final UnsupportedCallbackException e ) { final String message = "Unable to handle callback; disallowing login."; log.error( message, e ); throw new LoginException( message ); - } - catch( final NoSuchPrincipalException e ) - { + } catch( final NoSuchPrincipalException e ) { throw new FailedLoginException( "The username or password is incorrect." ); } } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/WebContainerLoginModule.java b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/WebContainerLoginModule.java index 57eeb4e..ce6ab5f 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/auth/login/WebContainerLoginModule.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/auth/login/WebContainerLoginModule.java @@ -81,47 +81,31 @@ public class WebContainerLoginModule extends AbstractLoginModule { // directly. If we find one, we're done. m_handler.handle( callbacks ); final HttpServletRequest request = rcb.getRequest(); - if ( request == null ) - { + if ( request == null ) { throw new LoginException( "No Http request supplied." ); } final HttpSession session = request.getSession(false); final String sid = (session == null) ? NULL : session.getId(); Principal principal = request.getUserPrincipal(); - if ( principal == null ) - { + if ( principal == null ) { // If no Principal in request, try the remoteUser - if ( log.isDebugEnabled() ) - { - log.debug( "No userPrincipal found for session ID=" + sid); - } + log.debug( "No userPrincipal found for session ID={}", sid); userId = request.getRemoteUser(); - if ( userId == null ) - { - if ( log.isDebugEnabled() ) - { - log.debug( "No remoteUser found for session ID=" + sid); - } + if ( userId == null ) { + log.debug( "No remoteUser found for session ID={}", sid); throw new FailedLoginException( "No remote user found" ); } principal = new WikiPrincipal( userId, WikiPrincipal.LOGIN_NAME ); } - if ( log.isDebugEnabled() ) - { - log.debug("Logged in container principal " + principal.getName() + "." ); - } + log.debug("Logged in container principal {}.", principal.getName() ); m_principals.add( principal ); return true; - } - catch( final IOException e ) - { - log.error( "IOException: " + e.getMessage() ); + } catch( final IOException e ) { + log.error( "IOException: {}", e.getMessage() ); return false; - } - catch( final UnsupportedCallbackException e ) - { - log.error( "UnsupportedCallbackException: " + e.getMessage() ); + } catch( final UnsupportedCallbackException e ) { + log.error( "UnsupportedCallbackException: {}", e.getMessage() ); return false; } } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/filters/PingWeblogsComFilter.java b/jspwiki-main/src/main/java/org/apache/wiki/filters/PingWeblogsComFilter.java index 1539e7b..52250e4 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/filters/PingWeblogsComFilter.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/filters/PingWeblogsComFilter.java @@ -84,9 +84,7 @@ public class PingWeblogsComFilter extends BasePageFilter { params.addElement( "The Butt Ugly Weblog" ); // FIXME: Must be settable params.addElement( engine.getURL( ContextEnum.PAGE_VIEW.getRequestContext(), blogName, null ) ); - if( log.isDebugEnabled() ) { - log.debug( "Pinging weblogs.com with URL: " + engine.getURL( ContextEnum.PAGE_VIEW.getRequestContext(), blogName, null ) ); - } + log.debug( "Pinging weblogs.com with URL: {}", engine.getURL( ContextEnum.PAGE_VIEW.getRequestContext(), blogName, null ) ); xmlrpc.executeAsync("weblogUpdates.ping", params, new AsyncCallback() { diff --git a/jspwiki-main/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java b/jspwiki-main/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java index 25bbca9..8bafdfc 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/parser/JSPWikiMarkupParser.java @@ -1018,17 +1018,12 @@ public class JSPWikiMarkupParser extends MarkupParser { ruleLine = ruleLine.substring( 0, ruleLine.length() - 1 ); } - if( log.isDebugEnabled() ) { - log.debug("page="+page.getName()+", ACL = "+ruleLine); - } + log.debug("page={}, ACL = {}", page.getName(), ruleLine); try { final Acl acl = m_engine.getManager( AclManager.class ).parseAcl( page, ruleLine ); page.setAcl( acl ); - - if( log.isDebugEnabled() ) { - log.debug( acl.toString() ); - } + log.debug( acl.toString() ); } catch( final WikiSecurityException wse ) { return makeError( wse.getMessage() ); } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/AbstractReferralPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/AbstractReferralPlugin.java index 8a010dc..2b46b8b 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/AbstractReferralPlugin.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/AbstractReferralPlugin.java @@ -285,14 +285,11 @@ public abstract class AbstractReferralPlugin implements Plugin { page = m_engine.getManager( PageManager.class ).getPage( pageName ); if( page != null ) { final Date lastModPage = page.getLastModified(); - if( log.isDebugEnabled() ) { - log.debug( "lastModified Date of page " + pageName + " : " + m_dateLastModified ); - } + log.debug( "lastModified Date of page {} : {}", pageName, m_dateLastModified ); if( lastModPage.after( m_dateLastModified ) ) { m_dateLastModified = lastModPage; } } - } } } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferringPagesPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferringPagesPlugin.java index 3a3766e..6d5d978 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferringPagesPlugin.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/ReferringPagesPlugin.java @@ -93,9 +93,7 @@ public class ReferringPagesPlugin extends AbstractReferralPlugin { extras = rb.getString( "referringpagesplugin.more" ); } - if( log.isDebugEnabled() ) { - log.debug( "Fetching referring pages for {} with a max of {}", page.getName(), items ); - } + log.debug( "Fetching referring pages for {} with a max of {}", page.getName(), items ); if( links != null && links.size() > 0 ) { links = filterAndSortCollection( links ); diff --git a/jspwiki-main/src/main/java/org/apache/wiki/rss/DefaultRSSGenerator.java b/jspwiki-main/src/main/java/org/apache/wiki/rss/DefaultRSSGenerator.java index a703e7e..f55628a 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/rss/DefaultRSSGenerator.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/rss/DefaultRSSGenerator.java @@ -306,9 +306,7 @@ public class DefaultRSSGenerator implements RSSGenerator { /** {@inheritDoc} */ @Override public String generateBlogRSS( final Context wikiContext, final List< Page > changed, final Feed feed ) { - if( log.isDebugEnabled() ) { - log.debug( "Generating RSS for blog, size=" + changed.size() ); - } + log.debug( "Generating RSS for blog, size={}", changed.size() ); final String ctitle = m_engine.getManager( VariableManager.class ).getVariable( wikiContext, PROP_CHANNEL_TITLE ); if( ctitle != null ) { diff --git a/jspwiki-main/src/main/java/org/apache/wiki/search/DefaultSearchManager.java b/jspwiki-main/src/main/java/org/apache/wiki/search/DefaultSearchManager.java index 2c5c1db..cff0dfe 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/search/DefaultSearchManager.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/search/DefaultSearchManager.java @@ -137,7 +137,7 @@ public class DefaultSearchManager extends BasePageFilter implements SearchManage } /** - * Provides a list of suggestions to use for a page name. Currently the algorithm just looks into the value parameter, + * Provides a list of suggestions to use for a page name. Currently, the algorithm just looks into the value parameter, * and returns all page names from that. * * @param wikiName the page name @@ -173,9 +173,7 @@ public class DefaultSearchManager extends BasePageFilter implements SearchManage } sw.stop(); - if( log.isDebugEnabled() ) { - log.debug( "Suggestion request for " + wikiName + " done in " + sw ); - } + log.debug( "Suggestion request for {} done in {}", wikiName, sw ); return list; } @@ -214,9 +212,7 @@ public class DefaultSearchManager extends BasePageFilter implements SearchManage } sw.stop(); - if( log.isDebugEnabled() ) { - log.debug( "AJAX search complete in {}", sw ); - } + log.debug( "AJAX search complete in {}", sw ); return list; } } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java index 2436290..dbf6ec7 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/search/LuceneSearchProvider.java @@ -345,16 +345,14 @@ public class LuceneSearchProvider implements SearchProvider { * @throws IOException If there's an indexing problem */ protected Document luceneIndexPage( final Page page, final String text, final IndexWriter writer ) throws IOException { - if( log.isDebugEnabled() ) { - log.debug( "Indexing " + page.getName() + "..." ); - } - + log.debug( "Indexing {}...", page.getName() ); + // make a new, empty document final Document doc = new Document(); - if( text == null ) { return doc; } + final String indexedText = text.replace( "__", " " ); // be nice to Language Analyzers - cfr. JSPWIKI-893 // Raw name is the keyword we'll use to refer to this document for updates. diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/DefaultTemplateManager.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/DefaultTemplateManager.java index 53d817e..617d629 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/ui/DefaultTemplateManager.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/DefaultTemplateManager.java @@ -146,9 +146,7 @@ public class DefaultTemplateManager extends BaseModuleManager implements Templat } } - if( log.isDebugEnabled() ) { - log.debug( "Final name = "+name ); - } + log.debug( "Final name = {}", name ); return name; } @@ -185,44 +183,6 @@ public class DefaultTemplateManager extends BaseModuleManager implements Templat return getPath( template ) + "/" + name; } - /* - * Returns a property, as defined in the template. The evaluation is lazy, i.e. the properties are not loaded until the template is - * actually used for the first time. - */ - /* - public String getTemplateProperty( WikiContext context, String key ) - { - String template = context.getTemplate(); - - try - { - Properties props = (Properties)m_propertyCache.getFromCache( template, -1 ); - - if( props == null ) - { - try - { - props = getTemplateProperties( template ); - - m_propertyCache.putInCache( template, props ); - } - catch( IOException e ) - { - log.warn("IO Exception while reading template properties",e); - - return null; - } - } - - return props.getProperty( key ); - } - catch( NeedsRefreshException ex ) - { - // FIXME - return null; - } - } -*/ /** * Returns an absolute path to a given template. */ @@ -238,10 +198,7 @@ public class DefaultTemplateManager extends BaseModuleManager implements Templat final Set< String > skinSet = sContext.getResourcePaths( place ); final Set< String > resultSet = new TreeSet<>(); - if( log.isDebugEnabled() ) { - log.debug( "Listings skins from " + place ); - } - + log.debug( "Listings skins from {}", place ); if( skinSet != null ) { final String[] skins = skinSet.toArray( new String[]{} ); for( final String skin : skins ) { @@ -249,9 +206,7 @@ public class DefaultTemplateManager extends BaseModuleManager implements Templat if( s.length > 2 && skin.endsWith( "/" ) ) { final String skinName = s[ s.length - 1 ]; resultSet.add( skinName ); - if( log.isDebugEnabled() ) { - log.debug( "...adding skin '" + skinName + "'" ); - } + log.debug( "...adding skin '{}'", skinName ); } } } @@ -259,7 +214,6 @@ public class DefaultTemplateManager extends BaseModuleManager implements Templat return resultSet; } - /** {@inheritDoc} */ @Override public Map< String, String > listTimeFormats( final PageContext pageContext ) { @@ -310,34 +264,6 @@ public class DefaultTemplateManager extends BaseModuleManager implements Templat return resultMap; } - /* - * Always returns a valid property map. - */ - /* - private Properties getTemplateProperties( String templateName ) - throws IOException - { - Properties p = new Properties(); - - ServletContext context = m_engine.getServletContext(); - - InputStream propertyStream = context.getResourceAsStream(getPath(templateName)+PROPERTYFILE); - - if( propertyStream != null ) - { - p.load( propertyStream ); - - propertyStream.close(); - } - else - { - log.debug("Template '"+templateName+"' does not have a propertyfile '"+PROPERTYFILE+"'."); - } - - return p; - } -*/ - /** {@inheritDoc} */ @Override public Collection< WikiModuleInfo > modules() { diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiServletFilter.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiServletFilter.java index f0abce6..1ade49a 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiServletFilter.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiServletFilter.java @@ -129,9 +129,7 @@ public class WikiServletFilter implements Filter { m_engine.getManager( AuthenticationManager.class ).login( httpRequest ); final Session 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() ); - } + log.debug( "Executed security filters for user={}, path={}",wikiSession.getLoginPrincipal().getName(), httpRequest.getRequestURI() ); } catch( final WikiSecurityException e ) { throw new ServletException( e ); }
