Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Security 基于表单的登录java web应用程序_Security_Jsf_Authentication_Jboss - Fatal编程技术网

Security 基于表单的登录java web应用程序

Security 基于表单的登录java web应用程序,security,jsf,authentication,jboss,Security,Jsf,Authentication,Jboss,我正在尝试对web应用程序执行基于表单的登录。我正在使用JSF和JBossV7.1.1。 我已经按照网页上的说明做了 <h:panelGrid columns="2"> <h:outputLabel value="Username: " /> <input type="text" id="j_username" name="j_username" /> <h:outputLabel value=

我正在尝试对web应用程序执行基于表单的登录。我正在使用JSF和JBossV7.1.1。 我已经按照网页上的说明做了

    <h:panelGrid columns="2">
        <h:outputLabel value="Username: " />
        <input type="text" id="j_username" name="j_username" />

        <h:outputLabel value="Password: " />
        <input type="password" id="j_password" name="j_password" />

        <h:outputText value="" />
        <h:panelGrid columns="1">
            <input type="submit" name="submit" value="Login" />
        </h:panelGrid>
    </h:panelGrid>
    <br />
</form>
这是我的登录页面: 登录以访问安全页面:

    <h:panelGrid columns="2">
        <h:outputLabel value="Username: " />
        <input type="text" id="j_username" name="j_username" />

        <h:outputLabel value="Password: " />
        <input type="password" id="j_password" name="j_password" />

        <h:outputText value="" />
        <h:panelGrid columns="1">
            <input type="submit" name="submit" value="Login" />
        </h:panelGrid>
    </h:panelGrid>
    <br />
</form>

    <h:panelGrid columns="2">
        <h:outputLabel value="Username: " />
        <input type="text" id="j_username" name="j_username" />

        <h:outputLabel value="Password: " />
        <input type="password" id="j_password" name="j_password" />

        <h:outputText value="" />
        <h:panelGrid columns="1">
            <input type="submit" name="submit" value="Login" />
        </h:panelGrid>
    </h:panelGrid>
    <br />
</form>


    <h:panelGrid columns="2">
        <h:outputLabel value="Username: " />
        <input type="text" id="j_username" name="j_username" />

        <h:outputLabel value="Password: " />
        <input type="password" id="j_password" name="j_password" />

        <h:outputText value="" />
        <h:panelGrid columns="1">
            <input type="submit" name="submit" value="Login" />
        </h:panelGrid>
    </h:panelGrid>
    <br />
</form>
我已成功执行身份验证,但当用户重定向到受限资源时,我需要知道用户使用的登录数据(例如,用于成功执行登录的用户名)。有人知道如何访问此信息吗?然后我想在JSF页面的ManagedBean类中使用它。
谢谢

远程用户位于JSFbean中,可由访问

    <h:panelGrid columns="2">
        <h:outputLabel value="Username: " />
        <input type="text" id="j_username" name="j_username" />

        <h:outputLabel value="Password: " />
        <input type="password" id="j_password" name="j_password" />

        <h:outputText value="" />
        <h:panelGrid columns="1">
            <input type="submit" name="submit" value="Login" />
        </h:panelGrid>
    </h:panelGrid>
    <br />
</form>
这是从中获得的,这也意味着它在JSF视图中可用,如下所示:

    <h:panelGrid columns="2">
        <h:outputLabel value="Username: " />
        <input type="text" id="j_username" name="j_username" />

        <h:outputLabel value="Password: " />
        <input type="password" id="j_password" name="j_password" />

        <h:outputText value="" />
        <h:panelGrid columns="1">
            <input type="submit" name="submit" value="Login" />
        </h:panelGrid>
    </h:panelGrid>
    <br />
</form>
<p>You're logged in as #{request.remoteUser}.</p>
您以#{request.remoteUser}身份登录

    <h:panelGrid columns="2">
        <h:outputLabel value="Username: " />
        <input type="text" id="j_username" name="j_username" />

        <h:outputLabel value="Password: " />
        <input type="password" id="j_password" name="j_password" />

        <h:outputText value="" />
        <h:panelGrid columns="1">
            <input type="submit" name="submit" value="Login" />
        </h:panelGrid>
    </h:panelGrid>
    <br />
</form>
或者更详细地说:

    <h:panelGrid columns="2">
        <h:outputLabel value="Username: " />
        <input type="text" id="j_username" name="j_username" />

        <h:outputLabel value="Password: " />
        <input type="password" id="j_password" name="j_password" />

        <h:outputText value="" />
        <h:panelGrid columns="1">
            <input type="submit" name="submit" value="Login" />
        </h:panelGrid>
    </h:panelGrid>
    <br />
</form>
<p>You're logged in as #{facesContext.externalContext.remoteUser}.</p>
您以{facesContext.externalContext.remoteUser}的身份登录

    <h:panelGrid columns="2">
        <h:outputLabel value="Username: " />
        <input type="text" id="j_username" name="j_username" />

        <h:outputLabel value="Password: " />
        <input type="password" id="j_password" name="j_password" />

        <h:outputText value="" />
        <h:panelGrid columns="1">
            <input type="submit" name="submit" value="Login" />
        </h:panelGrid>
    </h:panelGrid>
    <br />
</form>

Try
String userName=FacesContext.getCurrentInstance().getExternalContext().getRemoteUser()谢谢你们的回答!它起作用了!我已经读到,以编程方式基于表单的身份验证更加灵活,因此我将尝试这样做。我将从该链接[link]>中跟踪Balus的指示。