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
The following commit(s) were added to refs/heads/master by this push:
new e1aa339 use ATTR_CONTEXT constant from WikiContext
e1aa339 is described below
commit e1aa339b4a4c902b0561f200706eb7f86851d06d
Author: juanpablo <[email protected]>
AuthorDate: Fri Jan 10 13:03:36 2020 +0100
use ATTR_CONTEXT constant from WikiContext
---
ChangeLog.md | 3 +-
jspwiki-war/src/main/webapp/Login.jsp | 75 +++++++++-------------------
jspwiki-war/src/main/webapp/LoginForm.jsp | 14 ++----
jspwiki-war/src/main/webapp/LostPassword.jsp | 71 ++++++++++----------------
jspwiki-war/src/main/webapp/Message.jsp | 14 ++----
5 files changed, 59 insertions(+), 118 deletions(-)
diff --git a/ChangeLog.md b/ChangeLog.md
index 681d7c7..aced183 100644
--- a/ChangeLog.md
+++ b/ChangeLog.md
@@ -37,9 +37,10 @@ under the License.
* `WorkflowManager` renamed as
`org.apache.wiki.workflow.DefaultWorkflowManager`, with new
`org.apache.wiki.workflow.WorkflowManager` extracted as interface of the
latter
* Explicit casting from `WikiEngine#getAttribute()` and `
WikiPage#getAttribute()` no longer needed in most cases now
+* `WikiTagBase#ATTR_CONTEXT` constant moved to `WikiContext`
* `TestEngine` now includes test class and method where it was created next to
the timestamp, which is useful when you have tons of
timestamped dirs and want to know which folder was generated by what test
- * Also, if no folder is given for work, pages and attachment dirs, it tries
to place them under `./target/`
+ * Also, if no folder is given for work, pages and attachment dirs, it
tries to place them under `./target/`
* Applied format & fixes suggested by intellij to another bunch of files
**2020-01-03 Juan Pablo Santos (juanpablo AT apache DOT org)**
diff --git a/jspwiki-war/src/main/webapp/Login.jsp
b/jspwiki-war/src/main/webapp/Login.jsp
index 35d0ec2..c5db736 100644
--- a/jspwiki-war/src/main/webapp/Login.jsp
+++ b/jspwiki-war/src/main/webapp/Login.jsp
@@ -17,9 +17,10 @@
under the License.
--%>
+<%@ page import="java.security.Principal" %>
+<%@ page import="java.util.*" %>
<%@ page import="org.apache.log4j.*" %>
<%@ page import="org.apache.wiki.*" %>
-<%@ page import="java.security.Principal" %>
<%@ page import="org.apache.wiki.auth.*" %>
<%@ page import="org.apache.wiki.auth.login.CookieAssertionLoginModule" %>
<%@ page import="org.apache.wiki.auth.login.CookieAuthenticationLoginModule" %>
@@ -27,10 +28,8 @@
<%@ page import="org.apache.wiki.auth.user.UserProfile" %>
<%@ page import="org.apache.wiki.i18n.InternationalizationManager" %>
<%@ page import="org.apache.wiki.preferences.Preferences" %>
-<%@ page import="org.apache.wiki.tags.WikiTagBase" %>
<%@ page import="org.apache.wiki.workflow.DecisionRequiredException" %>
<%@ page errorPage="/Error.jsp" %>
-<%@ page import="java.util.*" %>
<%@ taglib uri="http://jspwiki.apache.org/tags" prefix="wiki" %>
<%!
Logger log = Logger.getLogger("JSPWiki");
@@ -39,25 +38,19 @@
WikiEngine wiki = WikiEngine.getInstance( getServletConfig() );
AuthenticationManager mgr = wiki.getAuthenticationManager();
WikiContext wikiContext = wiki.createContext( request, WikiContext.LOGIN );
- pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT,
- wikiContext,
- PageContext.REQUEST_SCOPE );
+ pageContext.setAttribute( WikiContext.ATTR_CONTEXT, wikiContext,
PageContext.REQUEST_SCOPE );
WikiSession wikiSession = wikiContext.getWikiSession();
ResourceBundle rb = Preferences.getBundle( wikiContext, "CoreResources" );
// Set the redirect-page variable if one was passed as a parameter
- if( request.getParameter( "redirect" ) != null )
- {
+ if( request.getParameter( "redirect" ) != null ) {
wikiContext.setVariable( "redirect", request.getParameter( "redirect"
) );
- }
- else
- {
+ } else {
wikiContext.setVariable( "redirect", wiki.getFrontPage() );
}
// Are we saving the profile?
- if( "saveProfile".equals(request.getParameter("action")) )
- {
+ if( "saveProfile".equals(request.getParameter("action")) ) {
UserManager userMgr = wiki.getUserManager();
UserProfile profile = userMgr.parseProfile( wikiContext );
@@ -65,35 +58,26 @@
userMgr.validateProfile( wikiContext, profile );
// If no errors, save the profile now & refresh the principal set!
- if ( wikiSession.getMessages( "profile" ).length == 0 )
- {
- try
- {
+ if ( wikiSession.getMessages( "profile" ).length == 0 ) {
+ try {
userMgr.setUserProfile( wikiSession, profile );
CookieAssertionLoginModule.setUserCookie( response,
profile.getFullname() );
- }
- catch( DuplicateUserException due )
- {
+ } catch( DuplicateUserException due ) {
// User collision! (full name or wiki name already taken)
wikiSession.addMessage( "profile",
wiki.getInternationalizationManager()
.get(
InternationalizationManager.CORE_BUNDLE,
Preferences.getLocale( wikiContext ),
due.getMessage(), due.getArgs() ) );
- }
- catch( DecisionRequiredException e )
- {
+ } catch( DecisionRequiredException e ) {
String redirect =
wiki.getURL(WikiContext.VIEW,"ApprovalRequiredForUserProfiles",null,true);
response.sendRedirect( redirect );
return;
- }
- catch( WikiSecurityException e )
- {
+ } catch( WikiSecurityException e ) {
// Something went horribly wrong! Maybe it's an I/O error...
wikiSession.addMessage( "profile", e.getMessage() );
}
}
- if ( wikiSession.getMessages( "profile" ).length == 0 )
- {
+ if ( wikiSession.getMessages( "profile" ).length == 0 ) {
String redirectPage = request.getParameter( "redirect" );
response.sendRedirect( wiki.getViewURL(redirectPage) );
return;
@@ -102,13 +86,10 @@
// If NOT using container auth, perform all of the access control logic
here...
// (Note: if using the container for auth, it will handle all of this for
us.)
- if( !mgr.isContainerAuthenticated() )
- {
- // If user got here and is already authenticated, it means
- // they just aren't allowed access to what they asked for.
+ if( !mgr.isContainerAuthenticated() ) {
+ // If user got here and is already authenticated, it means they just
aren't allowed access to what they asked for.
// Weepy tears and hankies all 'round.
- if( wikiSession.isAuthenticated() )
- {
+ if( wikiSession.isAuthenticated() ) {
response.sendError( HttpServletResponse.SC_FORBIDDEN,
rb.getString("login.error.noaccess") );
return;
}
@@ -116,33 +97,25 @@
// If using custom auth, we need to do the login now
String action = request.getParameter("action");
- if( request.getParameter("submitlogin") != null )
- {
+ if( request.getParameter("submitlogin") != null ) {
String uid = request.getParameter( "j_username" );
String passwd = request.getParameter( "j_password" );
log.debug( "Attempting to authenticate user " + uid );
// Log the user in!
- if ( mgr.login( wikiSession, request, uid, passwd ) )
- {
+ if ( mgr.login( wikiSession, request, uid, passwd ) ) {
log.info( "Successfully authenticated user " + uid + " (custom
auth)" );
- }
- else
- {
+ } else {
log.info( "Failed to authenticate user " + uid );
wikiSession.addMessage( "login",
rb.getString("login.error.password") );
}
}
- }
- else
- {
+ } else {
//
- // Have we already been submitted? If yes, then we can assume that
- // we have been logged in before.
+ // Have we already been submitted? If yes, then we can assume that
we have been logged in before.
//
Object seen = session.getAttribute("_redirect");
- if( seen != null )
- {
+ if( seen != null ) {
response.sendError( HttpServletResponse.SC_FORBIDDEN,
rb.getString("login.error.noaccess") );
session.removeAttribute("_redirect");
return;
@@ -164,16 +137,14 @@
// was called without parameters, this will be the front page. Otherwise,
// there's probably a 'redirect' parameter telling us where to go.
- if( wikiSession.isAuthenticated() )
- {
+ if( wikiSession.isAuthenticated() ) {
String rember = request.getParameter( "j_remember" );
// Set user cookie
Principal principal = wikiSession.getUserPrincipal();
CookieAssertionLoginModule.setUserCookie( response,
principal.getName() );
- if( rember != null )
- {
+ if( rember != null ) {
CookieAuthenticationLoginModule.setLoginCookie( wiki, response,
principal.getName() );
}
diff --git a/jspwiki-war/src/main/webapp/LoginForm.jsp
b/jspwiki-war/src/main/webapp/LoginForm.jsp
index fc458c4..e85cf90 100644
--- a/jspwiki-war/src/main/webapp/LoginForm.jsp
+++ b/jspwiki-war/src/main/webapp/LoginForm.jsp
@@ -19,7 +19,6 @@
<%@ page import="org.apache.log4j.*" %>
<%@ page import="org.apache.wiki.*" %>
-<%@ page import="org.apache.wiki.tags.WikiTagBase" %>
<%@ page errorPage="/Error.jsp" %>
<%@ taglib uri="http://jspwiki.apache.org/tags" prefix="wiki" %>
<%!
@@ -38,21 +37,16 @@
WikiEngine wiki = WikiEngine.getInstance( getServletConfig() );
// Retrieve the Login page context, then go and find the login form
- WikiContext wikiContext = (WikiContext) pageContext.getAttribute(
WikiTagBase.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
+ WikiContext wikiContext = (WikiContext) pageContext.getAttribute(
WikiContext.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
// If no context, it means we're using container auth. So, create one
anyway
- if( wikiContext == null )
- {
+ if( wikiContext == null ) {
wikiContext = wiki.createContext( request, WikiContext.LOGIN );
- pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT,
- wikiContext,
- PageContext.REQUEST_SCOPE );
+ pageContext.setAttribute( WikiContext.ATTR_CONTEXT, wikiContext,
PageContext.REQUEST_SCOPE );
}
response.setContentType("text/html; charset="+wiki.getContentEncoding() );
- String contentPage = wiki.getTemplateManager().findJSP( pageContext,
-
wikiContext.getTemplate(),
- "ViewTemplate.jsp"
);
+ String contentPage = wiki.getTemplateManager().findJSP( pageContext,
wikiContext.getTemplate(), "ViewTemplate.jsp" );
log.debug("Login template content is: " + contentPage);
diff --git a/jspwiki-war/src/main/webapp/LostPassword.jsp
b/jspwiki-war/src/main/webapp/LostPassword.jsp
index 858e9d1..32ffab4 100644
--- a/jspwiki-war/src/main/webapp/LostPassword.jsp
+++ b/jspwiki-war/src/main/webapp/LostPassword.jsp
@@ -17,54 +17,45 @@
under the License.
--%>
-<%@ page import="org.apache.log4j.*"%>
-<%@ page import="org.apache.wiki.*"%>
<%@ page import="java.util.*"%>
<%@ page import="java.text.*"%>
<%@ page import="javax.mail.*"%>
-<%@ page import="org.apache.wiki.auth.user.*"%>
+<%@ page import="javax.servlet.jsp.jstl.fmt.*"%>
+<%@ page import="org.apache.log4j.*"%>
+<%@ page import="org.apache.wiki.*"%>
<%@ page import="org.apache.wiki.auth.*"%>
-<%@ page import="org.apache.wiki.util.*"%>
+<%@ page import="org.apache.wiki.auth.user.*"%>
<%@ page import="org.apache.wiki.i18n.*"%>
<%@ page import="org.apache.wiki.preferences.Preferences" %>
-<%@ page import="org.apache.wiki.util.TextUtil" %>
+<%@ page import="org.apache.wiki.util.*"%>
<%@ page errorPage="/Error.jsp"%>
<%@ taglib uri="http://jspwiki.apache.org/tags" prefix="wiki" %>
-<%@ page import="org.apache.wiki.tags.WikiTagBase"%>
-<%@ page import="javax.servlet.jsp.jstl.fmt.*"%>
<%!Logger log = Logger.getLogger( "JSPWiki" );
String message = null;
- public boolean resetPassword( WikiEngine wiki, HttpServletRequest request,
ResourceBundle rb )
- {
+ public boolean resetPassword( WikiEngine wiki, HttpServletRequest request,
ResourceBundle rb ) {
// Reset pw for account name
String name = request.getParameter( "name" );
UserDatabase userDatabase = wiki.getUserManager().getUserDatabase();
boolean success = false;
- try
- {
+ try {
UserProfile profile = null;
/*
// This is disabled because it would otherwise be possible to DOS
JSPWiki instances
// by requesting new passwords for all users. See
https://issues.apache.org/jira/browse/JSPWIKI-78
- try
- {
- profile = userDatabase.find(name);
- }
- catch (NoSuchPrincipalException e)
- {
+ try {
+ profile = userDatabase.find(name);
+ } catch (NoSuchPrincipalException e) {
// Try email as well
}
- */
- if( profile == null )
- {
+ */
+ if( profile == null ) {
profile = userDatabase.findByEmail( name );
}
String email = profile.getEmail();
-
String randomPassword = TextUtil.generateRandomPassword();
// Try sending email first, as that is more likely to fail.
@@ -87,42 +78,34 @@
profile.setPassword( randomPassword );
userDatabase.save( profile );
success = true;
- }
- catch( NoSuchPrincipalException e )
- {
+ } catch( NoSuchPrincipalException e ) {
Object[] args = { name };
message = MessageFormat.format( rb.getString( "lostpwd.nouser" ),
args );
log.info( "Tried to reset password for non-existent user '" + name
+ "'" );
- }
- catch( SendFailedException e )
- {
+ } catch( SendFailedException e ) {
message = rb.getString( "lostpwd.nomail" );
log.error( "Tried to reset password and got SendFailedException: "
+ e );
- }
- catch( AuthenticationFailedException e )
- {
+ } catch( AuthenticationFailedException e ) {
message = rb.getString( "lostpwd.nomail" );
log.error( "Tried to reset password and got
AuthenticationFailedException: " + e );
- }
- catch( Exception e )
- {
+ } catch( Exception e ) {
message = rb.getString( "lostpwd.nomail" );
log.error( "Tried to reset password and got another exception: " +
e );
}
return success;
- }%>
+ }
+%>
<%
WikiEngine wiki = WikiEngine.getInstance( getServletConfig() );
//Create wiki context like in Login.jsp:
//don't check for access permissions: if you have lost your password you
cannot login!
- WikiContext wikiContext = (WikiContext) pageContext.getAttribute(
WikiTagBase.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
+ WikiContext wikiContext = (WikiContext) pageContext.getAttribute(
WikiContext.ATTR_CONTEXT, PageContext.REQUEST_SCOPE );
// If no context, it means we're using container auth. So, create one
anyway
- if( wikiContext == null )
- {
+ if( wikiContext == null ) {
wikiContext = wiki.createContext( request, WikiContext.LOGIN ); /*
reuse login context ! */
- pageContext.setAttribute( WikiTagBase.ATTR_CONTEXT, wikiContext,
PageContext.REQUEST_SCOPE );
+ pageContext.setAttribute( WikiContext.ATTR_CONTEXT, wikiContext,
PageContext.REQUEST_SCOPE );
}
ResourceBundle rb = Preferences.getBundle( wikiContext, "CoreResources" );
@@ -132,17 +115,13 @@
boolean done = false;
- if( (action != null) && (action.equals( "resetPassword" )) )
- {
- if( resetPassword( wiki, request, rb ) )
- {
+ if( action != null && action.equals( "resetPassword" ) ) {
+ if( resetPassword( wiki, request, rb ) ) {
done = true;
wikiSession.addMessage( "resetpwok", rb.getString(
"lostpwd.emailed" ) );
pageContext.setAttribute( "passwordreset", "done" );
- }
- else
- // Error
- {
+ } else {
+ // Error
wikiSession.addMessage( "resetpw", message );
}
}
diff --git a/jspwiki-war/src/main/webapp/Message.jsp
b/jspwiki-war/src/main/webapp/Message.jsp
index ceca9cb..6338e15 100755
--- a/jspwiki-war/src/main/webapp/Message.jsp
+++ b/jspwiki-war/src/main/webapp/Message.jsp
@@ -20,24 +20,20 @@
<%@ page isErrorPage="true" %>
<%@ page import="org.apache.log4j.*" %>
<%@ page import="org.apache.wiki.*" %>
-<%@ page import="org.apache.wiki.tags.WikiTagBase" %>
<%@ taglib uri="http://jspwiki.apache.org/tags" prefix="wiki" %>
<%!
Logger log = Logger.getLogger("JSPWiki");
%>
<%
WikiEngine wiki = WikiEngine.getInstance( getServletConfig() );
- WikiContext wikiContext = wiki.createContext( request,
- WikiContext.MESSAGE );
+ WikiContext wikiContext = wiki.createContext( request, WikiContext.MESSAGE
);
// Stash the wiki context and message text
- request.setAttribute( WikiTagBase.ATTR_CONTEXT, wikiContext );
- request.setAttribute( "message", request.getParameter("message"));
+ request.setAttribute( WikiContext.ATTR_CONTEXT, wikiContext );
+ request.setAttribute( "message", request.getParameter( "message" ) );
// Set the content type and include the response content
- response.setContentType("text/html; charset="+wiki.getContentEncoding() );
- String contentPage = wiki.getTemplateManager().findJSP( pageContext,
-
wikiContext.getTemplate(),
- "ViewTemplate.jsp"
);
+ response.setContentType( "text/html; charset=" + wiki.getContentEncoding()
);
+ String contentPage = wiki.getTemplateManager().findJSP( pageContext,
wikiContext.getTemplate(), "ViewTemplate.jsp" );
%><wiki:Include page="<%=contentPage%>" />
\ No newline at end of file