/ / Connexion de défi, authentification de base - jetée, authentification de base, jetée intégrée

Identification par défi, authentification de base - jetée, authentification de base, jetée intégrée

J'utilise la jetée 9, intégrée.

Je souhaite envoyer un défi lorsqu'un nom d’utilisateur n’existe pas dans mon fichier de propriétés.

J’ai étendu la classe BasicAuthenticator afin d’attraper l’exception normalement déclenchée quand un nom d’utilisateur n’existe pas. Je ne vois pas comment le demander à nouveau après avoir contesté l’utilisateur.

public class MyBasicAuthenticator extends BasicAuthenticator{
@Override
public Authentication validateRequest(ServletRequest req,
ServletResponse res, boolean mandatory)
{
Authentication authentication = null;
try{
authentication = super.validateRequest(req,res,mandatory);
return authentication;
}catch (Exception e){
return Authentication.SEND_FAILURE;
}
}

Authentication.SEND_FAILURE empêche l'appel d'ErrorHandler, mais il charge simplement une page vierge. SEND_FAILURE provient de l'interface d'authentification.

JavaDoc: http://download.eclipse.org/jetty/stable-9/apidocs/org/eclipse/jetty/security/authentication/BasicAuthenticator.html

Selon la réponse à cette question, Jetty6 avait une méthode d’envoi en défi, Jetty9 ne le faisait pas. Jetty UserRealm redirige sur la 3ème connexion échouée

Réponses:

0 pour la réponse № 1

Ceci est un problème d'authentification de base.

try {
authentication = super.validateRequest(req, res, mandatory);
} catch (Exception e) {
try{
HttpServletResponse r = (HttpServletResponse) res;
r.setHeader("WWW-Authenticate", "Basic");
r.setStatus(401);
} catch(Exception ew){}
authentication = Authentication.SEND_FAILURE;
}

Retourne 401 et un en-tête http contenant "WWW-Authenticate": "Basic"

Authentification.SEND_FAILURE empêche une exception plus bas dans la chaîne du gestionnaire.