Bonjour à tous
je suis en train de configurer spring security.
Le login marche mais aprés m'etre connecte je fais un
<security:authentication property="principal.username" />
pour récupérer le login de l'utilisateur connecté.
Si quelqu'un peut bien m'aider svp...
ci joint la page.xhtml
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <html xmlns="http://www.w3.org/1999/xhtml"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:a4j="http://richfaces.org/a4j"
xmlns:rich="http://richfaces.org/rich"
xmlns:security="http://www.springframework.org/security/tags">
...
<ui:define name="contenu">
login : <security:authentication property="principal.username" />
<h:outputText value="#{msg.titreApplication}" />
</ui:define>
</html> |
la page loginBean.java
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
| @Component
@Scope("session")
public class LoginBean
{
private String username = "";
private String password = "";
private boolean rememberMe = false;
private boolean loggedIn = false;
private User user;
//getters and setters
...
public String doLogin() throws IOException, ServletException
{
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
RequestDispatcher dispatcher = ((ServletRequest) context.getRequest()).getRequestDispatcher("/j_spring_security_check");
dispatcher.forward((ServletRequest) context.getRequest(),(ServletResponse) context.getResponse());
FacesContext.getCurrentInstance().responseComplete();
// It's OK to return null here because Faces is just going to exit.
return null;
}
@PostConstruct
@SuppressWarnings("unused")
private void handleErrorMessage()
{
Exception e = (Exception) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get(AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY);
if (e instanceof BadCredentialsException)
{
FacesContext.getCurrentInstance().getExternalContext().getSessionMap().put(AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY, null);
FacesContext.getCurrentInstance().addMessage(null,
new FacesMessage(FacesMessage.SEVERITY_ERROR, "Username or password not valid.", null));
}
} |
Merci
Partager