Announcement Announcement Module
Collapse
No announcement yet.
Security + PrimeFaces login form Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Security + PrimeFaces login form

    Hello, to All. I'm as searching long time how to create login from on primefaces for Sprint Secutiry+ Sprint WebFlow, but cant found any question.

    And my implementing dotn work. Can somebody help me to implement this?

    I have login page:
    Code:
    <ui:define name="mainZone">
            <h:form prependId="false">
    
                <p:growl id="messages" showDetail="true" sticky="true"
                    autoUpdate="true" />
    
                <p:panelGrid columns="2">
                    <f:facet name="header">
                        <h:outputText style="text-align: center"
                            value="Введите ваши идентификационные данные" />
                    </f:facet>
    
                    <p:row>
                        <p:column>
                            <h:outputLabel for="j_username" value="Ваш логин:" />
                        </p:column>
                        <p:column>
                            <p:inputText id='j_username' name='j_username' label="Логин"
                                required="true" />
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column>
                            <h:outputLabel for="j_password" value="Ваш пароль:" />
                        </p:column>
                        <p:column>
                            <p:password id='j_password' name='j_password' label="Пароль"
                                required="true" />
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column style="text-align: center">
                            <h:outputLabel for="_spring_security_remember_me"
                                value="Запомнить Вас?" />
                        </p:column>
                        <p:column>
                            <p:selectBooleanCheckbox id='_spring_security_remember_me' name='_spring_security_remember_me'/>
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column colspan="2" style="text-align: center">
                            <p:commandButton action="login" value="Войти в систему" />
                        </p:column>
                    </p:row>
                    <f:facet name="footer">
                        <h:outputText style="text-align: center; font-size: xx-small;"
                            value="#{asgePortalVersion.version}" />
                    </f:facet>
                </p:panelGrid>
            </h:form>
        </ui:define>
    I have next faces config:
    Code:
    <navigation-rule>
            <from-view-id>/login.xhtml</from-view-id>
            <navigation-case>
                <from-outcome>login</from-outcome>
                <to-view-id>/j_spring_security_check.html</to-view-id>
            </navigation-case>
        </navigation-rule>
    I have the next security config:
    Code:
    ...
    <form-login login-page="/login.html" authentication-failure-url="/login.html" login-processing-url="/j_spring_security_check.html" />
    ...
    And next config in web.xml:
    Code:
        <context-param>
            <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
            <param-value>.xhtml</param-value>
        </context-param>
    ....
    <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.html</url-pattern>
        </servlet-mapping>
    Or may be somebody post working code with primefaces?

  • #2
    I found solution:
    Code:
    <!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <ui:composition xmlns="http://www.w3.org/1999/xhtml"
        xmlns:ui="http://java.sun.com/jsf/facelets"
        xmlns:f="http://java.sun.com/jsf/core"
        xmlns:h="http://java.sun.com/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        xmlns:c="http://java.sun.com/jsp/jstl/core"
        template="/WEB-INF/templates/tmpl-login.xhtml">
    
        <ui:define name="mainZone">
            <h:form prependId="false" id="loginForm" onsubmit="document.#{p:component('loginForm')}.action='j_spring_security_check';">
    
                <p:growl id="messages" showDetail="true" sticky="true"
                    autoUpdate="true" />
    
                <p:panelGrid columns="2">
                    <f:facet name="header">
                        <h:outputText style="text-align: center"
                            value="Введите ваши идентификационные данные" />
                    </f:facet>
    
                    <p:row>
                        <p:column>
                            <h:outputLabel for="j_username" value="Ваш логин:" />
                        </p:column>
                        <p:column>
                            <p:inputText id='j_username' name='j_username' label="Логин"
                                required="true" />
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column>
                            <h:outputLabel for="j_password" value="Ваш пароль:" />
                        </p:column>
                        <p:column>
                            <p:password id='j_password' name='j_password' label="Пароль"
                                required="true" />
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column style="text-align: center">
                            <h:outputLabel for="_spring_security_remember_me"
                                value="Запомнить Вас?" />
                        </p:column>
                        <p:column>
                            <p:selectBooleanCheckbox id='_spring_security_remember_me' name='_spring_security_remember_me'/>
                        </p:column>
                    </p:row>
                    <p:row>
                        <p:column colspan="2" style="text-align: center">
                            <p:commandButton onclick="document.#{p:component('loginForm')}.action='j_spring_security_check';" value="Войти в систему" />
                        </p:column>
                    </p:row>
                    <f:facet name="footer">
                        <h:outputText style="text-align: center; font-size: xx-small;"
                            value="#{asgePortalVersion.version}" />
                    </f:facet>
                </p:panelGrid>
            </h:form>
        </ui:define>
    </ui:composition>
    All work BUT, it dont redirect after success login to the other page =(

    Comment


    • #3
      try to use "action" parameter for the redirecting to another page. It works for me.

      Comment

      Working...
      X