Pretty Faces with Spring Security and primefaces

Splash Forums PrettyFaces Users Pretty Faces with Spring Security and primefaces

This topic contains 3 replies, has 2 voices, and was last updated by  Christian Kaltepoth 9 years, 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
  • #18414

    soroor ash

    Hi :)

    my configuration is:

    maven- version:2.3.1

    hibernate – version: 3.2.7ga

    spring – version: 2.5.6

    spring-security-version: 2.0.4

    mysql – version: 5.1.9

    jsf – version:2.1.0-b03

    primefaces – version: 3.2

    prettyfaces – version :3.3.3

    my problem:

    After Login , get session correctly but , dialog not closed and not show welcome message and not directly to admin page.

    my login page is :

    <script type="text/javascript">
    function handleLoginRequest(xhr, status, args) {
    if (args.validationFailed || !args.loggedIn) {
    jQuery('#dialog').effect("shake", { times:3 }, 100);
    } else {

    <p:dialog id="dialog" header="Login" widgetVar="dlg" style="width:300px;">
    <h:form id="loginForm" prependId="false">
    <h:panelGrid columns="2" cellpadding="5">
    <label for="j_username">
    <h:outputText value="Username:"/>
    <h:inputText validator="#{loginBean.validateUsername}"
    <label for="j_password">
    <h:outputText value="Password:"/>
    <h:inputSecret validator="#{loginBean.validatePassword}" id="j_password"
    <label for="_spring_security_remember_me">
    <h:outputText value="Remember me"/>
    <h:selectBooleanCheckbox id="_spring_security_remember_me"/>

    <f:facet name="footer">
    <p:commandButton type="submit" update=":growl" id="login"
    action="#{loginBean.doLogin}" value="Login"
    oncomplete="handleLoginRequest(xhr, status, args);" />

    my applicationContext-security.xml is:


    <http auto-config="true" access-denied-page="/faces/accessDenied.xhtml">
    <intercept-url pattern="/faces/admin**" access="ROLE_SUPERVISOR"/>
    <intercept-url pattern="/faces/xhtml/**" access="IS_AUTHENTICATED_ANONYMOUSLY"/>

    <logout logout-url="/logout*" logout-success-url="/"/>

    <password-encoder hash="md5"/>
    <user name="rod" password="a564de63c2d0da68cf47586ee05984d7"
    <user name="dianne" password="65d15fe9156f9c4bbffd98085992a44e" authorities="ROLE_USER,ROLE_TELLER"/>
    <user name="scott" password="2b58af6dddbd072ed27ffc86725d7d3a" authorities="ROLE_USER"/>
    <user name="peter" password="22b5c9accc6e1ba628cedc63a72d57f8" authorities="ROLE_USER"/>

    my web.xml is:

    <!-- Pretty faces -->

    <!-- Pretty Filter -->
    <filter-name>Pretty Filter</filter-name>

    <filter-name>Pretty Filter</filter-name>

    <!-- Filter Config -->

    <!-- Filter Mappings -->

    my pretty-config.xml is:

    <url-mapping id="manage">
    <pattern value="/adminPage" />
    <view-id value="/faces/adminIndex.xhtml" />

    my method in LoginBean is:

    public String doLogin() throws IOException, ServletException {

    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();

    RequestDispatcher dispatcher = ((ServletRequest) context.getRequest())

    dispatcher.forward((ServletRequest) context.getRequest(), (ServletResponse) context.getResponse());


    AbstractProcessingFilter.SPRING_SECURITY_LAST_EXCEPTION_KEY, null);
    new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome !!!", null));
    loggedIn = Boolean.TRUE;

    // It's OK to return null here because Faces is just going to exit.
    return "pretty:manag";


    Please Help me i’m very helpless.


    First of all, you have a typo in the return statement of your login method. You return pretty:manag but it should be pretty:manage.

    Are you sure your handleLoginRequest gets invoked? If you return a PrettyFaces navigation from an action method invoked by an AJAX request, JSF typically automatically redirects the user to the target page. I’m not sure the oncomplete handler is invoked in this case.

    I would also recommend to use Firebug or some similar development tool to look into the AJAX response you are getting.


    soroor ash

    Thank you christian :)

    i change pretty:manag to pretty:manage but not redirect.

    if used login method Instead doLogin(), in LoginBean:

    public void login(ActionEvent actionEvent) {
    RequestContext context = RequestContext.getCurrentInstance();
    FacesMessage msg = null;
    boolean loggedIn = false;

    if(username != null && username.equals("rod") && password != null && password.equals("a564de63c2d0da68cf47586ee05984d7")) {
    loggedIn = true;
    msg = new FacesMessage(FacesMessage.SEVERITY_INFO, "Welcome", username);
    } else {
    loggedIn = false;
    msg = new FacesMessage(FacesMessage.SEVERITY_WARN, "Login Error", "Invalid credentials");

    FacesContext.getCurrentInstance().addMessage(null, msg);
    context.addCallbackParam("loggedIn", loggedIn);

    then say message welcome and close dialog and no get seesion . but if add this line in method:

    try {
    } catch (IOException e) {
    } catch (ServletException e) {

    then not say message and not close dialog and not go to adminPage.xhtml :((((((

    I think should be the other way getSession for login but I do not know.

    please help me .

    Thank you :)


    I don’t think your problems are related to PrettyFaces at all. It seems more like a problem with the overall interaction between the different components involved in the login process.

    One of the key things you should check is the following:

    If you invoke an action method and return pretty:someId there, you should definitely be redirected to the target page. If this doesn’t work, you should use Firebug to have a look at the AJAX response you get from the server.

Viewing 4 posts - 1 through 4 (of 4 total)

The forum ‘PrettyFaces Users’ is closed to new topics and replies.

Comments are closed.