四种认证类型:
BASIC:HTTP规范,Base64
<web-app>
......
<login-config>
<auth-method>BASIC
</auth-method>
</login-config>
......
</web-app>
DIGEST:HTTP规范,数据完整性强一些,但不是SSL
<web-app>
......
<login-config>
<auth-method>DIGEST
</auth-method>
</login-config>
......
</web-app>
CLIENT-CERT:J2EE规范,数据完整性很强,公共钥匙(PKC)
<web-app>
......
<login-config>
<auth-method>CLIENT-CERT
</auth-method>
</login-config>
......
</web-app>
FORM:J2EE规范,数据完整性非常弱,没有加密,允许有定制的登陆界面。
<web-app>
<security-constraint>
<web-resource-collection>
<web-resource-name>Login</web-resource-name>
<url-pattern>/protected/Detail.jsp</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<auth-constraint>
<role-name>All Role</role-name>
</auth-constraint>
<user-data-constraint>
<transport-guarantee>NONE</transport-guarantee>
</user-data-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>
</web-app>
以上的配置意思为:
/protected/Detail.jsp是受保护的资源,可以通过GET和POST方式来访问,没有角色(容器的角色)限制
但是需要先登录才能访问,登录的URI为/login.jsp
登陆页面表单的action,用户名,密码要用统一的名字:
<form action="j_security_check
">
<input type="text" name="j_username
" />
<input type="password" name="j_password
" />
<input type="submit" value="enter" />
</form>