从infoq转载,不会翻译,但是看得懂。呵呵
Java Enterprise Edition Version 6 (JEE6) release includes new security features in the areas of web container security as well as authentication and authorization aspects in Java application development. These features include programmatic and declarative security enforcement in the web tier.
Based on Servlet 3.0 specification (JSR 315), the Java EE 6 Web applications can take advantage of the new programmatic and declarative security features and Security annotations previously available to EJB 3.x applications. The web applications can also use JSR 196 based pluggable authentication/authorization modules that can be configured as part of the servlet container.
Web module security can be implemented programmatically (using the new security methods added in HTTP Servlet Request) as well as in a declarative manner (using the new security annotations).
The container security context can be accessed programmatically using the new methods available in the HTTP servlet request. Servlet 3.0 specifies the following methods in HttpServletRequest interface that can be used to authenticate users in a web application.
The following HttpServletRequest interface methods are also available to access security information about the component’s caller:
There are new annotations that can be used to enforce security in the web modules. We can apply authentication, authorization and transport level encryption using the provided annotations and deployment descriptors. The new Java EE 6 annotations are as follows:
If the web application consists of a servlet, use the @HttpConstraint and, optionally, the @HttpMethodConstraint annotation within the @ServletSecurity annotation to specify a security constraint. For other web applications, use a security-constraint element in the deployment descriptor.
The security role names can be declared using the security-role element of deployment descriptor. A security role reference defines a mapping between the name of a role that is called from a web component using isUserInRole(String role) and the name of a security role that has been defined for the application. For example, to map the security role reference "cust" to the security role with role name "bankCustomer", the syntax would be:
<servlet> ... <security-role-ref> <role-name>cust</role-name> <role-link>bankCustomer</role-link> </security-role-ref> ... </servlet>
If the servlet is called by a user who belongs to "bankCustomer" security role, the method call isUserInRole("cust") returns true. The role-link element in the security-role-ref element must match a role-name defined in the security-role element of the same web.xml deployment descriptor, as shown here:
<security-role> <role-name>bankCustomer</role-name> </security-role>
Transport security ensures that no one can tamper with the data being sent to a client or data received from a client. Java EE specification lets the developers enforce the transport security using "user data constraint" and "transport guarantee" elements in web.xml file or using the "transportGuarantee" attribute of HttpConstraint annotation. A user data constraint establishes a requirement that the constrained requests be received over a protected transport layer connection. The strength of the required protection is defined by the value of the transport guarantee. Following are the values defined in TransportGuarantee inner class:
We can enforce transport security in web.xml using the "user-dataconstraint" element which should be placed inside the security-constraint tag containing the resource which need transport protection. For example we can add the following snippet inside the security-constraint to enforce use of SSL when user is accessing managed resources.
<user-data-constraint> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint>
For more information on Java EE 6 security features, check out the Security chapters in Servlet 3.0 specification document (Chapter 13) and Java EE 6 Tutorial (Chapter 24) . DZone has also recently published a reference card on the Java EE security enhancements (Note: Registration is required to download the document from their website) .