我正在设计使用JSP的安全登录。我打算使用表单授权来访问Websphere上的应用程序。基本思想是当域中的内部认证用户访问一个页面时,它将如常。但是,如果外部用户尝试访问它,它将引导他们登录页面,与Active Directory连接,并在正确的身份验证后将其重定向到页面。使用JSP和Websphere安全登录
为了使其工作,我试图修改Web.xml以允许使用内置的“j_security_check”servlet进行表单身份验证。登录后,它会迎接用户“你好,!”具有简单功能<%request.getRemoteUser()%>或<%request.getUserPrincipal()。getName()%>。
基础上examples found here,我修改web.xml中的细节如下:
<welcome-file-list>
<welcome-file>/protected/index.jsp</welcome-file>
</welcome-file-list>
<security-constraint>
<web-resource-collection>
<url-pattern>/protected/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
<role-name>users</role-name>
</auth-constraint>
</security-constraint>
<login-config>
<auth-method>FORM</auth-method>
<form-login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/error.jsp</form-error-page>
</form-login-config>
</login-config>
<security-role>
<description>Administrator</description>
<role-name>admin</role-name>
</security-role>
<security-role>
<description>Users</description>
<role-name>users</role-name>
</security-role>
在我的login.jsp,我有一个简单的表格,确实在日志
。在我的index.jsp下,它用简单的请求迎接用户。
<body>
Hello, <% request.getRemoteUser(); %>
Hello, <% request.getUserPrincipal().getName(); %>
</body>
我在这里面临三个问题。重要性按原样排列。
1)错误403 重定向和登录页面起作用。当我尝试访问index.jsp时,我被重定向到login.jsp。当我输入一个不正确的uid:pwd对时,我用error.jsp迎接。当我正确登录时,我被重定向回index.jsp,但我遇到了错误403:网站要求您登录。我确定我已经登录,因为我之前无法访问内置的snoop页面,但登录后,我可以。我怀疑这是在我的web.xml
2)在禁止在web.xml所有保护和访问index.jsp的获取用户的ID 甚至一些设置,我有一个“招呼你好,空!“而不是”你好,用户!“。在index.jsp中显示的代码应该是正确的,因为我从互联网上的snoop示例代码中复制了代码。 request.getRemoteUser()在我的index.jsp上不起作用,但适用于snoop页面。在执行请求之前,我一定不会打电话吗?
3)安全性(还不重要) 我认为这个j_security_check是在Spring Security下。我正在尝试加密发送方和接收方以及传输通道。这是因为对于身份验证,我相信密码不得以明文形式发送或存储。我发现some information here,这导致我尝试/尝试保护此认证过程。
对于我面临的前三个问题,我将不胜感激。感觉就像我已经接近完成这件事,但它如此接近,但到目前为止......