【问题标题】:HTTP authentification in JSF 1.2 on WebsphereWebsphere 上 JSF 1.2 中的 HTTP 身份验证
【发布时间】:2012-08-10 08:52:03
【问题描述】:

我在 Webshere 7.0 上使用 JSF 1.2 + Tomahawk 1.1.13

我的 web.xml:

<welcome-file-list>
    <welcome-file>/search.faces</welcome-file>
</welcome-file-list>

<security-constraint>
    <display-name>Websphere Security Constraint</display-name>
    <web-resource-collection>
        <web-resource-name>Default</web-resource-name>
        <description />
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
</security-constraint>

<login-config>
    <auth-method>FORM</auth-method>
    <form-login-config>
        <form-login-page>/login.jsp</form-login-page>
        <form-error-page>/login.jsp</form-error-page>
    </form-login-config>
</login-config>

我的 login.jsp:

<form method="post" action="j_security_check">

    <jsp:include page="head.jsp" />

    <t:panelGrid columns="2" border="1"
        columnClasses="unfixedCol,fixedCol"
        style="style=text-align:top; margin-top:20px; margin-bottom:20px;">

        <t:panelGroup>
            Login
        </t:panelGroup>
        <t:panelGroup>
            <h:inputText id="j_username" autocomplete="off" size="20" />
        </t:panelGroup>

        <t:panelGroup>
            Password
        </t:panelGroup>
        <t:panelGroup>
            <h:inputSecret id="j_password" autocomplete="off" size="20" />
        </t:panelGroup>

        <f:facet name="footer">
            <t:panelGroup colspan="4"
                style="text-align:right; background-color:#d9e2f2;">
                <h:commandButton type="submit" value="Submit" /> &nbsp; 
                <h:commandButton type="reset" value="Reset" />
            </t:panelGroup>
        </f:facet>

    </t:panelGrid>

    <jsp:include page="foot.jsp" />

</form>

当我访问 /localhost:9080/App/ 并输入正确的凭据时,一切似乎都正常,我登录了,但这会出现问题:

  1. 我可以访问应用程序 jsp 页面而无需安全检查(我可以访问 /localhost:9080/App/search.jsp 而无需检查,但是当我访问 /localhost:9080/App/ - 有安全性 -查看)。尝试了不同的 url 模式。

  2. 当我尝试使用 FacesContext.getCurrentInstance().getExternalContext().getUserPrincipal() 获取 HTTP 会话用户时 - 当我登录 id 时,始终为空。为什么?

检查了所有指南,包括一些 stackowerflow 问题,但没有意识到我的问题出在哪里。

感谢您的帮助

【问题讨论】:

    标签: jsf jsf-1.2


    【解决方案1】:

    对于我们的应用程序,我们定义如下:

    web.xml

    <security-constraint>
        <display-name>Security Constraint</display-name>
        <web-resource-collection>
            <web-resource-name>Protected Area</web-resource-name>
            <url-pattern>*.jsf</url-pattern>
            <http-method>GET</http-method>
            <http-method>POST</http-method>
        </web-resource-collection>
    </security-constraint>
    

    由于我们也集成了 LDAP 身份验证,因此我们创建了自定义 application-policy 并在 realm 中指定

    <login-config>
        <auth-method>FORM</auth-method>
        <realm-name>OUR_AUTH_NAME_DEFINED_IN_login-config.xml</realm-name>
        <form-login-config>
            <form-login-page>/login.jsp</form-login-page>
            <form-error-page>/login.jsp?invalidUser=true</form-error-page>
        </form-login-config>
    </login-config>
    

    希望对你有帮助!!!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-17
      • 2011-02-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多