salut
j'ai integré jaas dans une application web
je voudrait testé est ce que ca marche bien mais j'ai rencontré un probleme: j'ai configuré dans web.xml une page jsf pageSecurise.jsfdont l'accés est securisé
voici ma classe MyLoginModule :
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 <security-constraint> <display-name>WebApp Administration</display-name> <web-resource-collection> <web-resource-name>WebApp Admin</web-resource-name> <url-pattern>/pages/pageSecurise.jsf</url-pattern> <http-method>DELETE</http-method> <http-method>GET</http-method> <http-method>POST</http-method> <http-method>PUT</http-method> </web-resource-collection> <auth-constraint> <role-name>admin</role-name> <role-name>other-role</role-name> </auth-constraint> </security-constraint>
j'ai bien dans la methode commit ajouté un Principal admin
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89 public class MyLoginModule implements LoginModule { private Subject subject; private CallbackHandler callbackHandler; private MyPrincipalName namePrincipal; private String userName; private boolean succeeded = false; private boolean commitSucceeded = false; @SuppressWarnings({ "unchecked", "unused" }) private Map sharedState; @SuppressWarnings({ "unchecked", "unused" }) private Map options; @SuppressWarnings("unchecked") public void initialize(Subject subject, CallbackHandler callbackHandler,Map sharedState, Map options) { this.subject = subject; this.callbackHandler = callbackHandler; //this.sharedState= sharedState; this.options= options; //debug = "true".equalsIgnoreCase((String) options.get("debug")); } public boolean login() throws LoginException { NameCallback nameCallback = new NameCallback("user"); PasswordCallback passwordCallback = new PasswordCallback("password :",false); Callback[] callbacks = new Callback[] {nameCallback,passwordCallback}; try { callbackHandler.handle(callbacks); } catch (Exception ex) { ex.printStackTrace(); throw new LoginException("Exception lors de la récupération des donnés !"); } userName = nameCallback.getName(); succeeded = validateUser(userName,passwordCallback.getPassword()); passwordCallback.clearPassword(); return succeeded; } public boolean abort() throws LoginException { if (!succeeded) return false; else if (succeeded && commitSucceeded) logout(); else succeeded = false; return true; } public boolean commit() throws LoginException { if (!succeeded) { userName = null; return false; } namePrincipal = new MyPrincipalName(userName); if (!subject.getPrincipals().contains(namePrincipal)) { { subject.getPrincipals().add(namePrincipal); System.out.println("commit done"); } } userName = null; commitSucceeded = true; return true; } public boolean logout() throws LoginException { subject.getPrincipals().remove(namePrincipal); namePrincipal = null; userName = null; succeeded = commitSucceeded = false; return true; } private boolean validateUser(String userName, char[] password) { return "admin".equals(userName) && "secret".equals(new String(password)); } }
mais j'obtient une erreur 403(Accés à la ressource interdit)
je veut savoir comment se fait la verification du role:comment le serveur compare le role déclaré pour ma page jsf dans le fichier web.xml à l'aide de la baliseet avec qu'elle valeur il comapre la valeure de sette balise
Code : Sélectionner tout - Visualiser dans une fenêtre à part <role-name>admin</role-name>
Partager