Unwanted redirect to https://example.com/j_security_check after logging in

In certain occasions when logging in to my site I am redirected to https://example.com/j_security_check instead of going to the welcome page specified in my web.xml. I am using java 8 and wildfly 10.

This is my login page

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
    <h:head>
        <f:facet name="first">
            <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
            <meta name="apple-mobile-web-app-capable" content="yes"/>
            <meta http-equiv="Cache-Control" content="no-store, no-cache, must-revalidate, max-age=0"/>
            <meta http-equiv="Pragma" content="no-cache"/>
            <meta http-equiv="Expires" content="0"/>
        </f:facet>
        <title>GADMA-Pagos Web</title>
        <style>
            body .sombra-boton {
                box-shadow: 0 3px 1px -2px rgba(0, 0, 0, 0.2), 0 2px 2px 0 rgba(0, 0, 0, 0.14), 0 1px 5px 0 rgba(0, 0, 0, 0.12);
            }
            body  .estilo-boton-login{
                background: #0288D1;
                color: #ffffff;
                border: 1px solid #0288D1;
                border-radius: 4px;
                cursor: pointer;
                transition: background-color 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
                height: 30px;
            }
            body .estilo-boton-registro {
                background: #607D8B;
                color: #ffffff;
                border: 1px solid #607D8B;
                border-radius: 4px;
                cursor: pointer;
                transition: background-color 0.2s, color 0.2s, border-color 0.2s, box-shadow 0.2s;
                height: 30px;
            }

        </style>
    </h:head>
    <h:body styleClass="login-body">
        <div class="login-panel ui-fluid">
            <form id="login" method="post" action="j_security_check">
                <div class="grid grid-nogutter">
                    <div class="col-12 logo-container TexAlCenter MarAuto">
                        <p:graphicImage name="images/gadma.png" library="paradise-layout" width="55"/>
                        <div class="Fs20">Pago de Impuesto Predial Municipio de Atacames</div>
                    </div>
                    <div class="col-12">
                        <p:outputLabel  value="Nombre de usuario"/>
                        <div class="input-wrapper">
                            <input id="j_username" name="j_username" maxlength="20" size="20" required="true"/>
                            <p:graphicImage name="images/login/user.png" library="paradise-layout"
                                            styleClass="user-icon"/>
                        </div>
                    </div>
                    <div class="col-12">
                        <p:outputLabel value="Contraseña"/>
                        <div class="input-wrapper">
                            <input id="j_password" name="j_password" maxlength="20" size="20" required="true" type="password" />
                            <p:graphicImage name="images/login/lock.png" library="paradise-layout"
                                            styleClass="lock-icon"/>
                        </div>
                    </div>
                    <div class="col-12 chkbox-container">
                        <a href="">¿Se olvído la contraseña?</a>
                    </div>
                    <div class="col-12 ">
                        <button class="estilo-boton-login sombra-boton" type="submit" onclick="return verificarLogin(j_username, j_password);">Iniciar sesión</button>
                    </div>
                </div>
            </form>
            <p:divider align="center">
                <p>¿No tiene una cuenta?</p>
            </p:divider>
            <div class="col-12 ">
                <button class="estilo-boton-registro sombra-boton" onclick="PF('dlgTipoUsuario').show();" update=":form-seleccion-usuario:" >Registrarse</button>
            </div>
            <h:form>            
                <div class="col-12 TexAlCenter MarAuto">
                    <h:outputLink value="#{request.contextPath}/terminos-condiciones.xhtml" target="_blank" style="text-decoration-line: underline !important" >
                        Términos y condiciones del servicio
                    </h:outputLink>
                    <p:spacer width="5px"/>
                    <h:outputLink value="#{request.contextPath}/politica-privacidad.xhtml" target="_blank" style="text-decoration-line: underline !important">
                        Política de privacidad
                    </h:outputLink>
                </div>
            </h:form>
        </div>
        <h:form id="form-seleccion-usuario">
            <p:dialog header="Seleccione el tipo de usuario" widgetVar="dlgTipoUsuario"  responsive="true" draggable="true" resizable="false" width="350" closeOnEscape="true" modal="true" fitViewport="true">
                <div class="col-12 TexAlCenter MarAuto">    
                    <div class="ui-g-6">
                        <p:button value="Usuario con cédula/Doc. exterior" styleClass="rounded-button ui-button-info mr-2 mb-2" outcome="registro-cedula.xhtml" icon="pi pi-user"/>
                    </div>
                    <div class="ui-g-6">
                        <p:button value="Usuario con RUC" styleClass="rounded-button ui-button-info mr-2 mb-2" outcome="registro-ruc.xhtml" icon="pi pi-user"/>
                    </div>
                </div>
            </p:dialog>            
        </h:form>
    </h:body>
    <h:outputStylesheet name="css/primeicons.css" library="paradise-layout"/>
    <h:outputStylesheet name="css/estilos.css" library="paradise-layout"/>
    <h:outputStylesheet name="css/primeflex.min.css" library="paradise-layout"/>
    <h:outputStylesheet name="css/layout-bliss.css" library="paradise-layout"/>

    <script>
        // Add JavaScript validation for the login form
        function verificarLogin() {
            var username = document.getElementById('j_username').value;
            var password = document.getElementById('j_password').value;

            if (username.trim() === "" || password.trim() === "") {
                // Show error message using JSF messages
                alert('Por favor complete todos los campos.');
                return false;
            }
            return true;
        }
    </script>
</html>

I have tried to capture the j_security_check servlet path using a webfilter and redirect it to the welcome page but it is not working. My intention is that it does not fail when logging in and always works correctly.

Upvotes: 0

Views: 28

Answers (0)

Related Questions