标准型鉴别Java小 [英] Standard form authentification Java servlets

查看:139
本文介绍了标准型鉴别Java小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是做形式的认证与Java servlet的标准方法?

What is the standard way of doing form authentication with Java Servlets?

既然现在我已经实现了自己用一个简单的POST HTML表单:

Since now I have implemented that myself using a simple POST HTML form:


  1. 检查发送参数针对数据库

  2. 如果present,省去了用户对象放入HttpSession中

  3. 在每一个Servlet的这个对象是present
  4. 检查
  5. 如果不是:重定向到登录页面,并显示错误消息

但现在我已经绊倒如何配置安全与嵌入式码头,现在我想到的是,我可以重复使用已经实现了这一问题的解决方案,但这里的标准是什么方法呢?我使用自己的码头,但对于Tomcat或其他Web服务器?

But now I have stumbled over How to Configure Security with Embedded Jetty and now I am thinking of that I can reuse already implemented solutions to that problem, but what is the standard approach here? I am using Jetty myself, but what about Tomcat or other web servers?

我也看了关于 j_security_check ,与什么?那是一个传统的方法是什么?

I also read about j_security_check, what's with that? Is that a legacy method?

推荐答案

您应使用由Servlet容器如Tomcat中,WebSphere,Glassfish的提供JAAS的安全性。

You should be using JAAS security provided by Servlet containers like Tomcat, Websphere, Glassfish.

在默认情况下这些容器支持这些身份验证类型:

By default these containers supports these authentication types:


  • 基本

  • DIGEST

  • FORM

  • CLIENT-CERT

HTTP基本验证

指定HTTP基本身份验证要求服务器请求从Web客户端的用户名和密码,验证用户名和密码是通过比较他们对在指定或默认的境界授权用户的数据库中有效。

Specifying HTTP basic authentication requires that the server request a user name and password from the web client and verify that the user name and password are valid by comparing them against a database of authorized users in the specified or default realm.

基本身份验证是当你没有指定的认证机制的缺省值。

Basic authentication is the default when you do not specify an authentication mechanism.

在使用基本身份验证,发生下列操作:

When basic authentication is used, the following actions occur:


  1. 客户端请求访问受保护的资源。

  2. Web服务器返回请求用户名和密码的对话框。

  3. 的客户端提交到服务器的用户名和密码。
    4. \\服务器在指定领域对用户进行认证,如果成功,返回所请求的资源。

下面的图显示了当您指定HTTP基本身份验证会发生什么。

The below Figure shows what happens when you specify HTTP basic authentication.

HTTP客户端和服务器之间的HTTP基本认证四个步骤基本身份验证图

HTTP Basic Authentication Diagram of four steps in HTTP basic authentication between client and server

基于表单的认证

基于表单的认证允许开发人员通过自定义登录屏幕和错误页面来控制登录认证屏幕的外观和感觉,一个HTTP浏览器presents给最终用户。当基于表单的认证声明,发生以下操作。

Form-based authentication allows the developer to control the look and feel of the login authentication screens by customizing the login screen and error pages that an HTTP browser presents to the end user. When form-based authentication is declared, the following actions occur.


  1. 客户端请求访问受保护的资源。

  2. 如果客户端是未经验证,服务器会将客户端重定向到一个登录页面。

  3. 客户端提交登录表单服务器。

  4. 服务器尝试验证用户。

  5. 如果验证成功,验证用户的主体进行检查,以确保它在被授权访问该资源的作用。如果用户被授权时,服务器通过使用存储的URL路径重定向客户端向资源。

  6. 如果验证失败,客户端转发或重定向到一个错误页面。

下图显示了在指定基于表单的认证会发生什么。

The below Figure shows what happens when you specify form-based authentication.

当您创建一个基于表单的登录,一定要保持使用cookie或SSL会话信息会话。

When you create a form-based login, be sure to maintain sessions using cookies or SSL session information.

有关认证适当地进行,登录表单的操作必须始终j_security_check。这种限制是这样的登录表单将工作无论是它的资源,避免要求服务器指定出形式的行动领域。下面code片段显示形式应如何codeD插入HTML页面:

For authentication to proceed appropriately, the action of the login form must always be j_security_check. This restriction is made so that the login form will work no matter which resource it is for and to avoid requiring the server to specify the action field of the outbound form. The following code snippet shows how the form should be coded into the HTML page:

<form method="POST" action="j_security_check">
  <input type="text" name="j_username">
  <input type="password" name="j_password">
</form>

摘要式身份验证

像基本身份验证,摘要式身份验证验证基于用户名和密码的用户。但是,与基本身份验证,摘要式身份验证在网络上不发送用户密码。相反,客户端发送密码和附加数据的单向加密散列。尽管密码不在线路上发送,摘要式身份验证需要明文密码等价物提供给认证的容器,以便它可以通过计算预期的摘要验证接收验证器。

Like basic authentication, digest authentication authenticates a user based on a user name and a password. However, unlike basic authentication, digest authentication does not send user passwords over the network. Instead, the client sends a one-way cryptographic hash of the password and additional data. Although passwords are not sent on the wire, digest authentication requires that clear-text password equivalents be available to the authenticating container so that it can validate received authenticators by calculating the expected digest.

参考文献:

  • How to Secure My Web Applications
  • Securing Web Applications
  • Securing Java EE 5 Web Applications
  • Declaring Security Requirements in a Deployment Descriptor
  • Client Cert Authentication

这篇关于标准型鉴别Java小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆