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 8487770254086e34a29fd9b6737d2a74381baf5b Author: juanpablo <[email protected]> AuthorDate: Thu Mar 5 17:18:21 2020 +0100 JSPWIKI-303: use Session instead of WikiSession (2) --- .../org/apache/wiki/event/WikiSecurityEvent.java | 4 +- .../apache/wiki/plugin/AbstractReferralPlugin.java | 3 +- .../java/org/apache/wiki/plugin/InsertPage.java | 11 +-- .../org/apache/wiki/plugin/SessionsPlugin.java | 81 ++++++++-------------- .../apache/wiki/search/BasicSearchProvider.java | 15 ++-- .../java/org/apache/wiki/search/SearchMatcher.java | 9 ++- .../java/org/apache/wiki/tags/MessagesTag.java | 11 +-- .../java/org/apache/wiki/tags/UserCheckTag.java | 46 +++++------- .../java/org/apache/wiki/tags/UserProfileTag.java | 8 +-- .../org/apache/wiki/ui/WikiRequestWrapper.java | 25 ++++--- .../java/org/apache/wiki/ui/WikiServletFilter.java | 19 ++--- .../wiki/ui/admin/beans/SearchManagerBean.java | 46 ++++++------ .../org/apache/wiki/ui/admin/beans/UserBean.java | 16 ++--- .../src/test/java/org/apache/wiki/TestEngine.java | 4 +- 14 files changed, 140 insertions(+), 158 deletions(-) diff --git a/jspwiki-main/src/main/java/org/apache/wiki/event/WikiSecurityEvent.java b/jspwiki-main/src/main/java/org/apache/wiki/event/WikiSecurityEvent.java index 94a633c..f57a56b 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/event/WikiSecurityEvent.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/event/WikiSecurityEvent.java @@ -83,7 +83,7 @@ public final class WikiSecurityEvent extends WikiEvent { /** When a user logs out. */ public static final int LOGOUT = 44; - /** When a Principal should be added to the WikiSession */ + /** When a Principal should be added to the Session */ public static final int PRINCIPAL_ADD = 35; /** When a session expires. */ @@ -187,6 +187,7 @@ public final class WikiSecurityEvent extends WikiEvent { * * @see java.lang.Object#toString() */ + @Override public String toString() { final StringBuilder msg = new StringBuilder(); msg.append( "WikiSecurityEvent." ); @@ -233,6 +234,7 @@ public final class WikiSecurityEvent extends WikiEvent { * * @return a String description of the type */ + @Override public String getTypeDescription() { switch ( getType() ) { case LOGIN_AUTHENTICATED: return "login authenticated"; 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 69d5ca3..5d552e4 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 @@ -443,7 +443,8 @@ public abstract class AbstractReferralPlugin implements WikiPlugin m_length = length; } - @Override public String mutate( final WikiContext context, final String text ) { + @Override + public String mutate( final WikiContext context, final String text ) { if( text.length() > m_length ) { return text.substring( 0, m_length ) + "..."; } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/InsertPage.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/InsertPage.java index e341041..2cca1b4 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/InsertPage.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/InsertPage.java @@ -155,15 +155,10 @@ public class InsertPage // String cookieName = ""; - if( showOnce ) - { - cookieName = ONCE_COOKIE + - TextUtil.urlEncodeUTF8( page.getName() ) - .replaceAll( "\\+", "%20" ); + if( showOnce ) { + cookieName = ONCE_COOKIE + TextUtil.urlEncodeUTF8( page.getName() ).replaceAll( "\\+", "%20" ); - if( HttpUtil.retrieveCookieValue( context.getHttpRequest(), - cookieName ) != null ) - { + if( HttpUtil.retrieveCookieValue( context.getHttpRequest(), cookieName ) != null ) { return ""; //silent exit } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/plugin/SessionsPlugin.java b/jspwiki-main/src/main/java/org/apache/wiki/plugin/SessionsPlugin.java index aba5a0b..b8df39a 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/plugin/SessionsPlugin.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/plugin/SessionsPlugin.java @@ -19,102 +19,81 @@ package org.apache.wiki.plugin; import org.apache.wiki.WikiContext; -import org.apache.wiki.WikiSession; import org.apache.wiki.api.core.Engine; import org.apache.wiki.api.exceptions.PluginException; import org.apache.wiki.api.plugin.WikiPlugin; +import org.apache.wiki.auth.SessionMonitor; import org.apache.wiki.util.TextUtil; import java.security.Principal; import java.util.HashMap; -import java.util.Iterator; import java.util.Map; /** - * <p>Displays information about active wiki sessions. The parameter - * <code>property</code> specifies what information is displayed. + * <p>Displays information about active wiki sessions. The parameter <code>property</code> specifies what information is displayed. * If omitted, the number of sessions is returned. * * <p>Parameters : </p> * <ul> * <li><b>property</b> - specify what output to display, valid values are:</li> * <ul> - * <li><code>users</code> - returns a comma-separated list of - * users</li> - * <li><code>distinctUsers</code> - will only show - * distinct users. + * <li><code>users</code> - returns a comma-separated list of users</li> + * <li><code>distinctUsers</code> - will only show distinct users.</li> * </ul> * </ul> * @since 2.3.84 */ -public class SessionsPlugin - implements WikiPlugin -{ +public class SessionsPlugin implements WikiPlugin { + /** The parameter name for setting the property value. */ public static final String PARAM_PROP = "property"; /** * {@inheritDoc} */ - @Override public String execute( final WikiContext context, final Map<String, String> params ) - throws PluginException - { + @Override + public String execute( final WikiContext context, final Map<String, String> params ) throws PluginException { final Engine engine = context.getEngine(); final String prop = params.get( PARAM_PROP ); - if ( "users".equals( prop ) ) - { - final Principal[] principals = WikiSession.userPrincipals( engine ); + if( "users".equals( prop ) ) { + final Principal[] principals = SessionMonitor.getInstance( engine ).userPrincipals(); final StringBuilder s = new StringBuilder(); - for ( int i = 0; i < principals.length; i++ ) - { - s.append(principals[i].getName() + ", "); + for( final Principal principal : principals ) { + s.append( principal.getName() ).append( ", " ); } // remove the last comma and blank : - return TextUtil.replaceEntities( s.substring(0, s.length() - (s.length() > 2 ? 2 : 0) ) ); + return TextUtil.replaceEntities( s.substring( 0, s.length() - ( s.length() > 2 ? 2 : 0 ) ) ); } - // - // show each user session only once (with a counter that indicates the - // number of sessions for each user) - if ("distinctUsers".equals(prop)) - { - final Principal[] principals = WikiSession.userPrincipals(engine); - // we do not assume that the principals are sorted, so first count - // them : - final HashMap<String,Integer> distinctPrincipals = new HashMap<>(); - for (int i = 0; i < principals.length; i++) - { - final String principalName = principals[i].getName(); + // show each user session only once (with a counter that indicates the number of sessions for each user) + if( "distinctUsers".equals( prop ) ) { + final Principal[] principals = SessionMonitor.getInstance( engine ).userPrincipals(); + // we do not assume that the principals are sorted, so first count them : + final HashMap< String, Integer > distinctPrincipals = new HashMap<>(); + for( final Principal principal : principals ) { + final String principalName = principal.getName(); - if (distinctPrincipals.containsKey(principalName)) - { + if( distinctPrincipals.containsKey( principalName ) ) { // we already have an entry, increase the counter: - int numSessions = distinctPrincipals.get(principalName).intValue(); + int numSessions = distinctPrincipals.get( principalName ); // store the new value: - distinctPrincipals.put(principalName, ++numSessions); - } - else - { + distinctPrincipals.put( principalName, ++numSessions ); + } else { // first time we see this entry, add entry to HashMap with value 1 - distinctPrincipals.put(principalName, 1); + distinctPrincipals.put( principalName, 1 ); } } - // - // + final StringBuilder s = new StringBuilder(); - final Iterator<Map.Entry<String, Integer>> entries = distinctPrincipals.entrySet().iterator(); - while (entries.hasNext()) - { - final Map.Entry<String, Integer> entry = entries.next(); - s.append( entry.getKey() + "(" + entry.getValue().toString() + "), " ); + for( final Map.Entry< String, Integer > entry : distinctPrincipals.entrySet() ) { + s.append( entry.getKey() ).append( "(" ).append( entry.getValue().toString() ).append( "), " ); } // remove the last comma and blank : - //if (s.length() >= 2) return s.substring(0, s.length() - 2); - return TextUtil.replaceEntities( s.substring(0, s.length() - (s.length() > 2 ? 2 : 0) ) ); + return TextUtil.replaceEntities( s.substring( 0, s.length() - ( s.length() > 2 ? 2 : 0 ) ) ); } - return String.valueOf( WikiSession.sessions( engine ) ); + return String.valueOf( SessionMonitor.getInstance( engine ).sessions() ); } } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/search/BasicSearchProvider.java b/jspwiki-main/src/main/java/org/apache/wiki/search/BasicSearchProvider.java index 981294f..c7139b7 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/search/BasicSearchProvider.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/search/BasicSearchProvider.java @@ -52,19 +52,22 @@ public class BasicSearchProvider implements SearchProvider { /** * {@inheritDoc} */ - @Override public void initialize( final Engine engine, final Properties props ) throws NoRequiredPropertyException, IOException { + @Override + public void initialize( final Engine engine, final Properties props ) throws NoRequiredPropertyException, IOException { m_engine = engine; } /** * {@inheritDoc} */ - @Override public void pageRemoved( final WikiPage page ) {} + @Override + public void pageRemoved( final WikiPage page ) {} /** * {@inheritDoc} */ - @Override public void reindexPage( final WikiPage page ) {} + @Override + public void reindexPage( final WikiPage page ) {} /** * Parses a query into something that we can use. @@ -175,14 +178,16 @@ public class BasicSearchProvider implements SearchProvider { /** * {@inheritDoc} */ - @Override public Collection< SearchResult > findPages( final String query, final WikiContext wikiContext ) { + @Override + public Collection< SearchResult > findPages( final String query, final WikiContext wikiContext ) { return findPages( parseQuery( query ), wikiContext ); } /** * {@inheritDoc} */ - @Override public String getProviderInfo() { + @Override + public String getProviderInfo() { return "BasicSearchProvider"; } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/search/SearchMatcher.java b/jspwiki-main/src/main/java/org/apache/wiki/search/SearchMatcher.java index f609615..c9db833 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/search/SearchMatcher.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/search/SearchMatcher.java @@ -134,7 +134,8 @@ public class SearchMatcher { * Returns Wikipage for this result. * @return WikiPage */ - @Override public WikiPage getPage() { + @Override + public WikiPage getPage() { return m_page; } @@ -143,7 +144,8 @@ public class SearchMatcher { * * @return Score from 0+ */ - @Override public int getScore() { + @Override + public int getScore() { return m_score; } @@ -152,7 +154,8 @@ public class SearchMatcher { * * @return an empty array */ - @Override public String[] getContexts() { + @Override + public String[] getContexts() { // Unimplemented return new String[0]; } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/MessagesTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/MessagesTag.java index 2e8a20b..a3a75f6 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/MessagesTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/MessagesTag.java @@ -86,12 +86,15 @@ public class MessagesTag extends WikiTagBase { if( messages.length > 0 ) { final StringBuilder sb = new StringBuilder(); if( messages.length == 1 ) { - sb.append( "<div class=\"" + m_div + "\">" + m_prefix + TextUtil.replaceEntities( messages[ 0 ] ) + "</div>" ); + sb.append( "<div class=\"" ).append( m_div ).append( "\">" ) + .append( m_prefix ) + .append( TextUtil.replaceEntities( messages[ 0 ] ) ) + .append( "</div>" ); } else { - sb.append( "<div class=\"" + m_div + "\">" + m_prefix ); + sb.append( "<div class=\"" ).append( m_div ).append( "\">" ).append( m_prefix ); sb.append( "<ul>" ); - for( int i = 0; i < messages.length; i++ ) { - sb.append( "<li>" + TextUtil.replaceEntities( messages[ i ] ) + "</li>" ); + for( final String message : messages ) { + sb.append( "<li>" ).append( TextUtil.replaceEntities( message ) ).append( "</li>" ); } sb.append( "</ul></div>" ); } diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/UserCheckTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/UserCheckTag.java index 42fd786..ced9aae 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/UserCheckTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/UserCheckTag.java @@ -18,44 +18,30 @@ */ package org.apache.wiki.tags; -import org.apache.wiki.WikiSession; import org.apache.wiki.api.core.Session; import org.apache.wiki.auth.AuthenticationManager; /** - * Includes the content if an user check validates. This has - * been considerably enhanced for 2.2. The possibilities for the "status"-argument are: + * Includes the content if an user check validates. This has been considerably enhanced for 2.2. The possibilities for the + * "status"-argument are: * * <ul> - * <li>"anonymous" - the body of the tag is included - * if the user is completely unknown (no cookie, no password)</li> - * <li>"asserted" - the body of the tag is included - * if the user has either been named by a cookie, but - * not been authenticated.</li> - * <li>"authenticated" - the body of the tag is included - * if the user is validated either through the container, - * or by our own authentication.</li> - * <li>"assertionsAllowed" - * - the body of the tag is included - * if wiki allows identities to be asserted using cookies.</li> - * <li>"assertionsNotAllowed" - * - the body of the tag is included - * if wiki does <i>not</i> allow identities to - * be asserted using cookies.</li> - * <li>"containerAuth" - the body of the tag is included - * if the user is validated through the container.</li> - * <li>"customAuth" - the body of the tag is included - * if the user is validated through our own authentication.</li> - * <li>"known" - if the user is not anonymous</li> - * <li>"notAuthenticated" - * - the body of the tag is included - * if the user is not yet authenticated.</li> + * <li>"anonymous" - the body of the tag is included if the user is completely unknown (no cookie, no password)</li> + * <li>"asserted" - the body of the tag is included if the user has either been named by a cookie, but not been authenticated.</li> + * <li>"authenticated" - the body of the tag is included if the user is validated either through the container, or by our own authentication.</li> + * <li>"assertionsAllowed" - the body of the tag is included if wiki allows identities to be asserted using cookies.</li> + * <li>"assertionsNotAllowed" - the body of the tag is included if wiki does <i>not</i> allow identities to be asserted using cookies.</li> + * <li>"containerAuth" - the body of the tag is included if the user is validated through the container.</li> + * <li>"customAuth" - the body of the tag is included if the user is validated through our own authentication.</li> + * <li>"known" - if the user is not anonymous</li> + * <li>"notAuthenticated" - the body of the tag is included if the user is not yet authenticated.</li> * </ul> * * If the old "exists" -argument is used, it corresponds as follows: * <p> * <tt>exists="true" ==> status="known"<br> * <tt>exists="false" ==> status="unknown"<br> + * </p> * * It is NOT a good idea to use BOTH of the arguments. * @@ -120,17 +106,17 @@ public class UserCheckTag extends WikiTagBase { if( m_status != null ) { switch( m_status ) { case ANONYMOUS: - if( status.equals( WikiSession.ANONYMOUS ) ) { + if( status.equals( Session.ANONYMOUS ) ) { return EVAL_BODY_INCLUDE; } break; case AUTHENTICATED: - if( status.equals( WikiSession.AUTHENTICATED ) ) { + if( status.equals( Session.AUTHENTICATED ) ) { return EVAL_BODY_INCLUDE; } break; case ASSERTED: - if( status.equals( WikiSession.ASSERTED ) ) { + if( status.equals( Session.ASSERTED ) ) { return EVAL_BODY_INCLUDE; } break; @@ -160,7 +146,7 @@ public class UserCheckTag extends WikiTagBase { } return SKIP_BODY; case NOT_AUTHENTICATED: - if( !status.equals( WikiSession.AUTHENTICATED ) ) { + if( !status.equals( Session.AUTHENTICATED ) ) { return EVAL_BODY_INCLUDE; } break; diff --git a/jspwiki-main/src/main/java/org/apache/wiki/tags/UserProfileTag.java b/jspwiki-main/src/main/java/org/apache/wiki/tags/UserProfileTag.java index ab752d2..f019c85 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/tags/UserProfileTag.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/tags/UserProfileTag.java @@ -163,8 +163,8 @@ public class UserProfileTag extends WikiTagBase { /** * Returns a sorted list of the {@link org.apache.wiki.auth.authorize.Group} objects a user possesses - * in his or her WikiSession. The result is computed by consulting - * {@link org.apache.wiki.WikiSession#getRoles()} + * in his or her Session. The result is computed by consulting + * {@link org.apache.wiki.api.core.Session#getRoles()} * and extracting those that are of type Group. * @return the list of groups, sorted by name */ @@ -198,8 +198,8 @@ public class UserProfileTag extends WikiTagBase { /** * Returns a sorted list of the {@link org.apache.wiki.auth.authorize.Role} objects a user possesses - * in his or her WikiSession. The result is computed by consulting - * {@link org.apache.wiki.WikiSession#getRoles()} + * in his or her Session. The result is computed by consulting + * {@link org.apache.wiki.api.core.Session#getRoles()} * and extracting those that are of type Role. * @return the list of roles, sorted by name */ diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiRequestWrapper.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiRequestWrapper.java index 5abfd26..64104ec 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiRequestWrapper.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/WikiRequestWrapper.java @@ -18,8 +18,8 @@ */ package org.apache.wiki.ui; -import org.apache.wiki.WikiSession; import org.apache.wiki.api.core.Engine; +import org.apache.wiki.api.core.Session; import org.apache.wiki.auth.SessionMonitor; import org.apache.wiki.auth.authorize.Role; @@ -35,7 +35,7 @@ import java.security.Principal; */ public class WikiRequestWrapper extends HttpServletRequestWrapper { - private final WikiSession m_session; + private final Session m_session; /** * Constructs a new wrapped request. @@ -46,17 +46,18 @@ public class WikiRequestWrapper extends HttpServletRequestWrapper { public WikiRequestWrapper( final Engine engine, final HttpServletRequest request ) { super( request ); - // Get and stash a reference to the current WikiSession + // Get and stash a reference to the current Session m_session = SessionMonitor.getInstance( engine ).find( request.getSession() ); } /** * Returns the remote user for the HTTP request, taking into account both container and JSPWiki custom authentication status. * Specifically, if the wrapped request contains a remote user, this method returns that remote user. Otherwise, if the user's - * WikiSession is an authenticated session (that is, {@link WikiSession#isAuthenticated()} returns <code>true</code>, - * this method returns the name of the principal returned by {@link WikiSession#getLoginPrincipal()}. + * Session is an authenticated session (that is, {@link Session#isAuthenticated()} returns <code>true</code>, + * this method returns the name of the principal returned by {@link Session#getLoginPrincipal()}. */ - @Override public String getRemoteUser() { + @Override + public String getRemoteUser() { if( super.getRemoteUser() != null ) { return super.getRemoteUser(); } @@ -70,10 +71,11 @@ public class WikiRequestWrapper extends HttpServletRequestWrapper { /** * Returns the user principal for the HTTP request, taking into account both container and JSPWiki custom authentication status. * Specifically, if the wrapped request contains a user principal, this method returns that principal. Otherwise, if the user's - * WikiSession is an authenticated session (that is, {@link WikiSession#isAuthenticated()} returns - * <code>true</code>, this method returns the value of {@link WikiSession#getLoginPrincipal()}. + * Session is an authenticated session (that is, {@link Session#isAuthenticated()} returns + * <code>true</code>, this method returns the value of {@link Session#getLoginPrincipal()}. */ - @Override public Principal getUserPrincipal() { + @Override + public Principal getUserPrincipal() { if( super.getUserPrincipal() != null ) { return super.getUserPrincipal(); } @@ -88,9 +90,10 @@ public class WikiRequestWrapper extends HttpServletRequestWrapper { * Determines whether the current user possesses a supplied role, taking into account both container and JSPWIki custom authentication * status. Specifically, if the wrapped request shows that the user possesses the role, this method returns <code>true</code>. If not, * this method iterates through the built-in Role objects (<em>e.g.</em>, ANONYMOUS, ASSERTED, AUTHENTICATED) returned by - * {@link WikiSession#getRoles()} and checks to see if any of these principals' names match the supplied role. + * {@link Session#getRoles()} and checks to see if any of these principals' names match the supplied role. */ - @Override public boolean isUserInRole( final String role ) { + @Override + public boolean isUserInRole( final String role ) { final boolean hasContainerRole = super.isUserInRole(role); if( hasContainerRole ) { return true; 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 39ff442..9b98604 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 @@ -22,8 +22,8 @@ import org.apache.log4j.Logger; import org.apache.log4j.NDC; import org.apache.wiki.WikiContext; import org.apache.wiki.WikiEngine; -import org.apache.wiki.WikiSession; import org.apache.wiki.api.core.Engine; +import org.apache.wiki.api.core.Session; import org.apache.wiki.auth.AuthenticationManager; import org.apache.wiki.auth.SessionMonitor; import org.apache.wiki.auth.WikiSecurityException; @@ -42,7 +42,7 @@ import java.io.PrintWriter; /** * Filter that verifies that the {@link org.apache.wiki.api.core.Engine} is running, and sets the authentication status for the user's - * WikiSession. Each HTTP request processed by this filter is wrapped by a {@link WikiRequestWrapper}. The wrapper's primary responsibility + * Session. Each HTTP request processed by this filter is wrapped by a {@link WikiRequestWrapper}. The wrapper's primary responsibility * is to return the correct <code>userPrincipal</code> and <code>remoteUser</code> for authenticated JSPWiki users (whether authenticated * by container or by JSPWiki's custom system). The wrapper's other responsibility is to incorporate JSPWiki built-in roles * into the role-checking algorithm for {@link HttpServletRequest#isUserInRole(String)}. Just before the request is wrapped, the method @@ -68,7 +68,8 @@ public class WikiServletFilter implements Filter { * @param config The FilterConfig. * @throws ServletException If a Engine cannot be started. */ - @Override public void init( final FilterConfig config ) throws ServletException { + @Override + public void init( final FilterConfig config ) throws ServletException { final ServletContext context = config.getServletContext(); // TODO REMOVEME when resolving JSPWIKI-129 @@ -82,12 +83,13 @@ public class WikiServletFilter implements Filter { /** * Destroys the WikiServletFilter. */ - @Override public void destroy() { + @Override + public void destroy() { } /** * Checks that the Engine 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)} + * Session. 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 @@ -96,7 +98,8 @@ public class WikiServletFilter implements Filter { * @throws ServletException if {@link org.apache.wiki.auth.AuthenticationManager#login(HttpServletRequest)} fails for any reason * @throws IOException If writing to the servlet response fails. */ - @Override public void doFilter( final ServletRequest request, final ServletResponse response, final FilterChain chain ) throws IOException, ServletException { + @Override + public void doFilter( final ServletRequest request, final ServletResponse response, final FilterChain chain ) throws IOException, ServletException { // Sanity check; it might be true in some conditions, but we need to know where. if( chain == null ) { throw new ServletException("FilterChain is null, even if it should not be. Please report this to the jspwiki development team."); @@ -125,10 +128,10 @@ public class WikiServletFilter implements Filter { httpRequest.setCharacterEncoding( m_engine.getContentEncoding().displayName() ); if ( !isWrapped( request ) ) { - // Prepare the WikiSession + // Prepare the Session try { m_engine.getManager( AuthenticationManager.class ).login( httpRequest ); - final WikiSession wikiSession = SessionMonitor.getInstance( m_engine ).find( httpRequest.getSession() ); + 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() ); diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/admin/beans/SearchManagerBean.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/admin/beans/SearchManagerBean.java index 98b6988..6ec3f71 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/ui/admin/beans/SearchManagerBean.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/admin/beans/SearchManagerBean.java @@ -33,46 +33,44 @@ import java.util.Collection; /** - * The SearchManagerBean is a simple AdminBean interface - * to the SearchManager. It currently can be used to force - * a reload of all of the pages. + * The SearchManagerBean is a simple AdminBean interface to the SearchManager. It currently can be used to force a reload of all of the pages. * * @since 2.6 */ -public class SearchManagerBean extends SimpleAdminBean -{ - private static final String PROGRESS_ID = "searchmanagerbean.reindexer"; +public class SearchManagerBean extends SimpleAdminBean { + private static final String PROGRESS_ID = "searchmanagerbean.reindexer"; private static final String[] METHODS = { "reload" }; // private static Logger log = Logger.getLogger( SearchManagerBean.class ); private WikiBackgroundThread m_updater; - public SearchManagerBean( final Engine engine) throws NotCompliantMBeanException - { + public SearchManagerBean( final Engine engine ) throws NotCompliantMBeanException { super(); - initialize(engine); + initialize( engine ); } - @Override public String[] getAttributeNames() + @Override + public String[] getAttributeNames() { return new String[0]; } - @Override public String[] getMethodNames() + @Override + public String[] getMethodNames() { return METHODS; } - @Override public String getTitle() + @Override + public String getTitle() { return "Search manager"; } /** - * Starts a background thread which goes through all the pages and adds them - * to the reindex queue. + * Starts a background thread which goes through all the pages and adds them to the reindex queue. * <p> * This method prevents itself from being called twice. */ @@ -83,13 +81,15 @@ public class SearchManagerBean extends SimpleAdminBean int m_count; int m_max; - @Override public void startupTask() throws Exception { + @Override + public void startupTask() throws Exception { super.startupTask(); setName( "Reindexer started" ); } - @Override public void backgroundTask() throws Exception { + @Override + public void backgroundTask() throws Exception { final Collection< WikiPage > allPages = m_engine.getManager( PageManager.class ).getAllPages(); final SearchManager mgr = m_engine.getManager( SearchManager.class ); @@ -97,11 +97,11 @@ public class SearchManagerBean extends SimpleAdminBean final ProgressItem pi = new ProgressItem() { - @Override public int getProgress() { + @Override + public int getProgress() { return 100 * m_count / m_max; } }; - m_engine.getManager( ProgressManager.class ).startProgress( pi, PROGRESS_ID ); for( final WikiPage page : allPages ) { @@ -120,12 +120,13 @@ public class SearchManagerBean extends SimpleAdminBean } } - @Override public int getType() - { + @Override + public int getType() { return CORE; } - @Override public String doGet( final WikiContext context ) { + @Override + public String doGet( final WikiContext context ) { if( m_updater != null ) { return "Update already in progress ("+ context.getEngine().getManager( ProgressManager.class ).getProgress(PROGRESS_ID)+ "%)"; } @@ -134,7 +135,8 @@ public class SearchManagerBean extends SimpleAdminBean "<div class='description'>Forces JSPWiki search engine to reindex all pages. Use this if you think some pages are not being found even if they should.</div>"; } - @Override public String doPost( final WikiContext context ) { + @Override + public String doPost( final WikiContext context ) { final String val = context.getHttpParameter( "searchmanagerbean-reload" ); if( val != null ) { reload(); diff --git a/jspwiki-main/src/main/java/org/apache/wiki/ui/admin/beans/UserBean.java b/jspwiki-main/src/main/java/org/apache/wiki/ui/admin/beans/UserBean.java index 23c94b3..3574ba1 100644 --- a/jspwiki-main/src/main/java/org/apache/wiki/ui/admin/beans/UserBean.java +++ b/jspwiki-main/src/main/java/org/apache/wiki/ui/admin/beans/UserBean.java @@ -57,13 +57,12 @@ public class UserBean extends SimpleAdminBean { final HttpServletRequest request = context.getHttpRequest(); final Session session = context.getWikiSession(); final UserManager mgr = context.getEngine().getManager( UserManager.class ); - - final String loginid = request.getParameter("loginid"); - final String loginname = request.getParameter("loginname"); - final String fullname = request.getParameter("fullname"); - final String password = request.getParameter("password"); - final String password2 = request.getParameter("password2"); - final String email = request.getParameter("email"); + final String loginid = request.getParameter( "loginid" ); + final String loginname = request.getParameter( "loginname" ); + final String fullname = request.getParameter( "fullname" ); + final String password = request.getParameter( "password" ); + final String password2 = request.getParameter( "password2" ); + final String email = request.getParameter( "email" ); if( request.getParameter( "action" ).equalsIgnoreCase( "remove" ) ) { try { @@ -100,8 +99,9 @@ public class UserBean extends SimpleAdminBean { p.setEmail( email ); p.setFullname( fullname ); - if( password != null && password.length() > 0 ) + if( password != null && password.length() > 0 ) { p.setPassword( password ); + } p.setLoginName( loginname ); try { diff --git a/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java b/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java index e83b1b5..980d01e 100644 --- a/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java +++ b/jspwiki-main/src/test/java/org/apache/wiki/TestEngine.java @@ -378,7 +378,7 @@ public class TestEngine extends WikiEngine public void saveText( final String pageName, final String content ) throws WikiException { // Build new request and associate our admin session final MockHttpServletRequest request = newHttpRequest(); - final WikiSession wikiSession = SessionMonitor.getInstance( this ).find( request.getSession() ); + final Session wikiSession = SessionMonitor.getInstance( this ).find( request.getSession() ); this.getAuthenticationManager().login( wikiSession, request, Users.ADMIN, Users.ADMIN_PASS ); // Create page and wiki context @@ -390,7 +390,7 @@ public class TestEngine extends WikiEngine public void saveTextAsJanne( final String pageName, final String content ) throws WikiException { // Build new request and associate our Janne session final MockHttpServletRequest request = newHttpRequest(); - final WikiSession wikiSession = SessionMonitor.getInstance( this ).find( request.getSession() ); + final Session wikiSession = SessionMonitor.getInstance( this ).find( request.getSession() ); this.getAuthenticationManager().login( wikiSession, request, Users.JANNE, Users.JANNE_PASS ); // Create page and wiki context
