Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ under the License.
* Bump `org.codehaus.mojo:clirr-maven-plugin` from 2.8 to 2.9 ([PR#647](https://github.com/apache/jspwiki/pull/647))
* Bump `org.sonarsource.scanner.maven:sonar-maven-plugin` from 5.8.0.7211 to 5.9.0.7382 ([PR#648](https://github.com/apache/jspwiki/pull/648))
* Fix for [JSPWIKI-1384](https://issues.apache.org/jira/browse/JSPWIKI-1384): move `SampleAjaxPlugin` from the main sources to the test sources
* Fix for [JSPWIKI-1387](https://issues.apache.org/jira/browse/JSPWIKI-1387): a user who logs in to a locked account with the right password is told that the account is locked, instead of "Not a valid login"

**2026-11-17 Arturo Bernal (abernal AT apache DOT org)**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Licensed to the Apache Software Foundation (ASF) under one

import javax.security.auth.Subject;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.AccountLockedException;
import javax.security.auth.login.LoginException;
import javax.security.auth.spi.LoginModule;
import jakarta.servlet.http.HttpServletRequest;
Expand All @@ -58,6 +59,7 @@ Licensed to the Apache Software Foundation (ASF) under one
import java.util.Properties;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.wiki.WikiContext;
import org.apache.wiki.WikiSession;
import org.apache.wiki.auth.user.UserDatabase;
Expand Down Expand Up @@ -290,7 +292,8 @@ public boolean login( final Session session, final HttpServletRequest request, f
final CallbackHandler handler = new WikiCallbackHandler( m_engine, null, username, password );

// Execute the user's specified login module
final Set< Principal > principals = doJAASLogin( m_loginModuleClass, handler, m_loginModuleOptions );
final AtomicReference< LoginException > failure = new AtomicReference<>();
final Set< Principal > principals = doJAASLogin( m_loginModuleClass, handler, m_loginModuleOptions, failure );
if(!principals.isEmpty()) {
if( passwordExpired( session, principals ) ) {
return false;
Expand All @@ -306,6 +309,13 @@ public boolean login( final Session session, final HttpServletRequest request, f

return true;
}
// The login module only says that the account is locked to someone who knew the password
if( failure.get() instanceof AccountLockedException ) {
LOG.info( "Login denied for {}: the account is locked", username );
final ResourceBundle rb = m_engine.getManager( InternationalizationManager.class )
.getBundle( InternationalizationManager.CORE_BUNDLE, session.getLocale() );
session.addMessage( "login", rb.getString( "login.error.accountLocked" ) );
}
return false;
}

Expand Down Expand Up @@ -450,6 +460,18 @@ public boolean allowsCookieAuthentication() {
public Set< Principal > doJAASLogin( final Class< ? extends LoginModule > clazz,
final CallbackHandler handler,
final Map< String, String > options ) throws WikiSecurityException {
return doJAASLogin( clazz, handler, options, new AtomicReference<>() );
}

/**
* Same as {@link #doJAASLogin(Class, CallbackHandler, Map)}, and tells why the login failed, if it did.
*
* @param failure receives the exception thrown by the login module when the login fails
*/
private Set< Principal > doJAASLogin( final Class< ? extends LoginModule > clazz,
final CallbackHandler handler,
final Map< String, String > options,
final AtomicReference< LoginException > failure ) throws WikiSecurityException {
// Instantiate the login module
final LoginModule loginModule;
try {
Expand All @@ -472,6 +494,7 @@ public Set< Principal > doJAASLogin( final Class< ? extends LoginModule > clazz,
}
} catch( final LoginException e ) {
LOG.debug(e.getMessage(), e);
failure.set( e );
// Login or commit failed! No principal for you!
}

Expand Down
1 change: 1 addition & 0 deletions jspwiki-main/src/main/resources/CoreResources.properties
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ rename.unknownerror=An unknown error occurred ({0})
#login.error.capslock=Invalid login (please check your Caps Lock key) #obsolete
login.error.password=Not a valid login.
login.error.passwordExpired=Your password has expired and has to be changed. Use the lost password link of the login page to set a new one, or ask a wiki administrator.
login.error.accountLocked=Your account is locked. Ask a wiki administrator to unlock it, or try again later.
login.error.noaccess=It seems you don't have access to that. Sorry.

# Lostpassword.jsp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ rename.unknownerror=Ein unbekannter Fehler ist aufgetreten!

login.error.password=Ung\u00fcltiges Passwort!
login.error.passwordExpired=Ihr Passwort ist abgelaufen und muss ge\u00e4ndert werden. Verwenden Sie den Link zum Zur\u00fccksetzen des Passworts auf der Anmeldeseite, um ein neues zu setzen, oder wenden Sie sich an einen Administrator des Wikis.
login.error.accountLocked=Ihr Konto ist gesperrt. Bitten Sie einen Wiki-Administrator, es zu entsperren, oder versuchen Sie es sp\u00e4ter erneut.
login.error.noaccess=Du hast offenbar keine Berechtigung hierzu. Sorry!

# Lostpassword
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ rename.unknownerror=Ha ocurrido un error desconocido ({0})
#login.error.capslock=Id. de acceso no v\u00e1lido (verifica la tecla Caps Lock)
login.error.password=No es un id. de acceso v\u00e1lido.
login.error.passwordExpired=Su contrase\u00f1a ha caducado y debe cambiarse. Use el enlace de contrase\u00f1a olvidada de la p\u00e1gina de inicio de sesi\u00f3n para establecer una nueva, o consulte a un administrador del wiki.
login.error.accountLocked=Su cuenta est\u00e1 bloqueada. Pida a un administrador del wiki que la desbloquee, o int\u00e9ntelo de nuevo m\u00e1s tarde.
login.error.noaccess=Parece que no tienes acceso a eso. Lo siento.

# Lostpassword
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ newgroup.exists=Ryhm\u00e4 {0} on jo olemassa. Yrit\u00e4 jotain toista nime\u00

login.error.password=Virheellinen k\u00e4ytt\u00e4j\u00e4tunnus tai salasana
login.error.passwordExpired=Salasanasi on vanhentunut ja se on vaihdettava. Aseta uusi salasana kirjautumissivun unohtuneen salasanan linkin kautta tai pyyd\u00e4 apua wikin yll\u00e4pit\u00e4j\u00e4lt\u00e4.
login.error.accountLocked=Tilisi on lukittu. Pyyd\u00e4 wikin yll\u00e4pit\u00e4j\u00e4\u00e4 avaamaan lukitus tai yrit\u00e4 my\u00f6hemmin uudelleen.
login.error.noaccess=Valitettavasti sinulla ei n\u00e4yt\u00e4 olevan p\u00e4\u00e4sy\u00e4 haluamallesi sivulle. Pahoittelumme.

# JSPWikiMarkupParser
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ rename.unknownerror=Une erreur inattendue est apparue ({0})
#login.error.capslock=Identifiant invalide (veuillez v\u00e9rifier votre touche Verr.Maj.) #obsol\u00cbte
login.error.password=Identifiant invalide.
login.error.passwordExpired=Votre mot de passe a expir\u00e9 et doit \u00eatre chang\u00e9. Utilisez le lien de mot de passe perdu de la page de connexion pour en d\u00e9finir un nouveau, ou contactez un administrateur du wiki.
login.error.accountLocked=Votre compte est verrouill\u00e9. Demandez \u00e0 un administrateur du wiki de le d\u00e9verrouiller, ou r\u00e9essayez plus tard.
login.error.noaccess=Il semble que vous n'ayez pas acc\u00e8s \u00e0 ceci. D\u00e9sol\u00e9.

# Lostpassword.jsp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ rename.unknownerror=Errore sconosciuto: ({0})
#login.error.capslock=Invalid login (please check your Caps Lock key) #obsolete
login.error.password=L'identificativo non \u00e8 valido.
login.error.passwordExpired=La tua password \u00e8 scaduta e deve essere cambiata. Usa il link per il recupero della password nella pagina di accesso per impostarne una nuova, oppure rivolgiti a un amministratore del wiki.
login.error.accountLocked=Il tuo account \u00e8 bloccato. Chiedi a un amministratore del wiki di sbloccarlo, oppure riprova pi\u00f9 tardi.
login.error.noaccess=Spiacente, sembra che la risorsa non sia accessibile.

# Lostpassword.jsp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ rename.unknownerror=Er is een onbekende fout opgetreden ({0})
# Login.jsp
login.error.password=Geen geldige login.
login.error.passwordExpired=Uw wachtwoord is verlopen en moet worden gewijzigd. Gebruik de link voor een vergeten wachtwoord op de inlogpagina om een nieuw wachtwoord in te stellen, of vraag het aan een beheerder van de wiki.
login.error.accountLocked=Uw account is geblokkeerd. Vraag een wiki-beheerder om het te deblokkeren of probeer het later opnieuw.
login.error.noaccess=U heeft geen toegang tot deze informatie.Sorry.

# Lostpassword.jsp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ rename.unknownerror=An unknown error occurred ({0})
#login.error.capslock=Invalid login (please check your Caps Lock key) #obsolete
login.error.password=Login inv\u00e1lido.
login.error.passwordExpired=Sua senha expirou e precisa ser alterada. Use o link de senha esquecida da p\u00e1gina de login para definir uma nova ou pe\u00e7a a um administrador do wiki.
login.error.accountLocked=Sua conta est\u00e1 bloqueada. Pe\u00e7a a um administrador do wiki para desbloque\u00e1-la ou tente novamente mais tarde.
login.error.noaccess=Voc\u00ea n\u00e3o possui acesso \u00e0 isto. Me desculpe.

# Lostpassword.jsp
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ rename.unknownerror=\u041d\u0435\u0438\u0437\u0432\u0435\u0441\u0442\u043d\u0430
#login.error.capslock=\u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u043b\u043e\u0433\u0438\u043d (\u043f\u0440\u043e\u0432\u0435\u0440\u0442\u0435 \u043a\u043b\u0430\u0432\u0438\u0448\u0443 Caps Lock) #obsolete
login.error.password=\u041d\u0435\u0432\u0435\u0440\u043d\u044b\u0439 \u043b\u043e\u0433\u0438\u043d.
login.error.passwordExpired=\u0421\u0440\u043e\u043a \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0432\u0430\u0448\u0435\u0433\u043e \u043f\u0430\u0440\u043e\u043b\u044f \u0438\u0441\u0442\u0451\u043a, \u0435\u0433\u043e \u043d\u0443\u0436\u043d\u043e \u0441\u043c\u0435\u043d\u0438\u0442\u044c. \u0412\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0439\u0442\u0435\u0441\u044c \u0441\u0441\u044b\u043b\u043a\u043e\u0439 \u0432\u043e\u0441\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0438\u044f \u043f\u0430\u0440\u043e\u043b\u044f \u043d\u0430 \u0441\u0442\u0440\u0430\u043d\u0438\u0446\u0435 \u0432\u0445\u043e\u0434\u0430, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0434\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439, \u0438\u043b\u0438 \u043e\u0431\u0440\u0430\u0442\u0438\u0442\u0435\u0441\u044c \u043a \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0443 \u0432\u0438\u043a\u0438.
login.error.accountLocked=\u0412\u0430\u0448\u0430 \u0443\u0447\u0451\u0442\u043d\u0430\u044f \u0437\u0430\u043f\u0438\u0441\u044c \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u0430. \u041f\u043e\u043f\u0440\u043e\u0441\u0438\u0442\u0435 \u0430\u0434\u043c\u0438\u043d\u0438\u0441\u0442\u0440\u0430\u0442\u043e\u0440\u0430 \u0432\u0438\u043a\u0438 \u0440\u0430\u0437\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0451 \u0438\u043b\u0438 \u043f\u043e\u0432\u0442\u043e\u0440\u0438\u0442\u0435 \u043f\u043e\u043f\u044b\u0442\u043a\u0443 \u043f\u043e\u0437\u0436\u0435.
login.error.noaccess=\u0423 \u0412\u0430\u0441 \u043d\u0435\u0442 \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u044d\u0442\u043e\u043c\u0443. \u0418\u0437\u0432\u0438\u043d\u0438\u0442\u0435.


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ rename.unknownerror=\u53d1\u751f\u672a\u77e5\u9519\u8bef\uff08{0}\uff09
#login.error.capslock=Invalid login (please check your Caps Lock key) #obsolete
login.error.password=\u65e0\u6548\u767b\u5f55\u3002
login.error.passwordExpired=\u60a8\u7684\u5bc6\u7801\u5df2\u8fc7\u671f\uff0c\u5fc5\u987b\u4fee\u6539\u3002\u8bf7\u4f7f\u7528\u767b\u5f55\u9875\u9762\u4e0a\u7684\u201c\u5fd8\u8bb0\u5bc6\u7801\u201d\u94fe\u63a5\u8bbe\u7f6e\u65b0\u5bc6\u7801\uff0c\u6216\u8054\u7cfb wiki \u7ba1\u7406\u5458\u3002
login.error.accountLocked=\u60a8\u7684\u8d26\u6237\u5df2\u88ab\u9501\u5b9a\u3002\u8bf7\u8054\u7cfb\u7ef4\u57fa\u7ba1\u7406\u5458\u89e3\u9501\uff0c\u6216\u7a0d\u540e\u518d\u8bd5\u3002
login.error.noaccess=\u5bf9\u4e0d\u8d77\uff0c\u60a8\u65e0\u6743\u64cd\u4f5c\u3002

# Lostpassword.jsp
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
/*
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
*/
package org.apache.wiki.auth;

import jakarta.servlet.http.HttpServletRequest;
import org.apache.commons.io.FileUtils;
import org.apache.wiki.HttpMockFactory;
import org.apache.wiki.TestEngine;
import org.apache.wiki.api.core.Session;
import org.apache.wiki.api.spi.Wiki;
import org.apache.wiki.auth.user.UserDatabase;
import org.apache.wiki.auth.user.UserProfile;
import org.apache.wiki.auth.user.XMLUserDatabase;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.File;
import java.util.Date;
import java.util.Properties;
import java.util.UUID;

/** What a user who logs in to a locked account is told (JSPWIKI-1387). */
class LockedAccountLoginTest {

private TestEngine newEngine() throws Exception {
final Properties props = TestEngine.getTestProperties();
final File file = new File( "target/LockedAccountLoginTest" + UUID.randomUUID() + ".xml" );
FileUtils.copyFile( new File( "src/test/resources/userdatabase.xml" ), file );
props.put( XMLUserDatabase.PROP_USERDATABASE, file.getAbsolutePath() );
return new TestEngine( props );
}

private void lock( final TestEngine engine, final String loginName, final Date until ) throws Exception {
final UserDatabase db = engine.getManager( UserManager.class ).getUserDatabase();
final UserProfile profile = db.findByLoginName( loginName );
profile.setLockExpiry( until );
db.save( profile );
}

private Session newSession( final TestEngine engine ) {
final HttpServletRequest request = HttpMockFactory.createHttpRequest();
return Wiki.session().find( engine, request );
}

private boolean login( final TestEngine engine, final Session session, final String loginName, final String password ) throws Exception {
return engine.getManager( AuthenticationManager.class ).login( session, HttpMockFactory.createHttpRequest(), loginName, password );
}

@Test
void testALockedAccountTellsItsOwnerThatItIsLocked() throws Exception {
final TestEngine engine = newEngine();
lock( engine, "janne", new Date( System.currentTimeMillis() + 3_600_000L ) );
final Session session = newSession( engine );

Assertions.assertFalse( login( engine, session, "janne", "myP@5sw0rd" ) );

Assertions.assertFalse( session.isAuthenticated() );
Assertions.assertEquals( 1, session.getMessages( "login" ).length );
Assertions.assertTrue( session.getMessages( "login" )[ 0 ].contains( "locked" ), session.getMessages( "login" )[ 0 ] );
}

@Test
void testALockedAccountDoesNotShowToSomeoneWhoDoesNotKnowThePassword() throws Exception {
final TestEngine engine = newEngine();
lock( engine, "janne", new Date( System.currentTimeMillis() + 3_600_000L ) );
final Session session = newSession( engine );

Assertions.assertFalse( login( engine, session, "janne", "wrong" ) );

Assertions.assertEquals( 0, session.getMessages( "login" ).length );
}

@Test
void testAnAccountThatIsNotLockedLogsIn() throws Exception {
final TestEngine engine = newEngine();
final Session session = newSession( engine );

Assertions.assertTrue( login( engine, session, "janne", "myP@5sw0rd" ) );

Assertions.assertEquals( 0, session.getMessages( "login" ).length );
}

}
Loading