Bonjour,
j'essaye de mettre en place une classe permettant une Authentification.
Or je n'arrive pas à comprendre lorsque je compile le code, j'obtiens cette erreur :
le code est le suivant :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 Auth.java:25 '{' expected private class String check (String Authorization) throws ServletException, IOException { ^ 1error
ça fait plusieurs jours que je tourne le code dans tous les sens, j'ai supposé que c'était un problème d'accolade, mais je fini par douté.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42 import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.sql.*; import javax.sql.*; import java.util.*; import java.lang.*; public class Auth extends HttpServlet { protected void doGet(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { String user; String authorization = request.getHeader("Authorization"); if (authorization == null || (user=check(authorization))==null) { response.setHeader("WWW-Authenticate", "Basic realm=\"Mon site\""); response.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } response.setContentType("text/plain"); response.getWriter().println("Bienvenue"); } } private class String check(String authorization) throws ServletException,IOException { if (!authorization.toLowerCase().startsWith(BASIC_SCHEME)) throw new ServletException("unrecognized authentication scheme"); String creditBase64= authorization.substring(1+BASIC_SCHEME.length()); sun.misc.BASE64Decoder decoder= new sun.misc.BASE64Decoder(); byte[] credit= decoder.decodeBuffer(creditBase64); String str= new String(credit); int index= str.indexOf(':'); String user= str.substring(0, index); String passwd= str.substring(index + 1); return (passwd.equals("toto"))?user:null; } private static final String BASIC_SCHEME="basic"; }![]()
Merci d'avance pour votre aide.
Acyclique
Partager