In Java EE, the component containers are responsible for providing application security. A container provides two types of security: declarative and programmatic.
The following topics are addressed here:
Using Annotations to Specify Security Information
Annotations enable a declarative style of programming and so encompass both the declarative and programmatic security concepts. Users can specify information about security within a class file by using annotations. GlassFish Server uses this information when the application is deployed. Not all security information can be specified by using annotations, however. Some information must be specified in the application deployment descriptors.
Specific annotations that can be used to specify security information within an enterprise bean class file are described in Securing an Enterprise Bean Using Declarative Security. Chapter 51, "Getting Started Securing Web Applications", describes how to use annotations to secure web applications where possible. Deployment descriptors are described only where necessary.
For more information on annotations, see Further Information about Security.
Using Deployment Descriptors for Declarative Security
Declarative security can express an application component’s security requirements by using deployment descriptors. Because deployment descriptor information is declarative, it can be changed without the need to modify the source code. At runtime, the Java EE server reads the deployment descriptor and acts upon the corresponding application, module, or component accordingly. Deployment descriptors must provide certain structural information for each component if this information has not been provided in annotations or is not to be defaulted.
This part of the tutorial does not document how to create deployment descriptors; it describes only the elements of the deployment descriptor relevant to security. NetBeans IDE provides tools for creating and modifying deployment descriptors.
Different types of components use different formats, or schemas, for their deployment descriptors. The security elements of deployment descriptors discussed in this tutorial include the following.
Using Programmatic Security
Programmatic security is embedded in an application and is used to make
security decisions. Programmatic security is useful when declarative
security alone is not sufficient to express the security model of an
application. The API for programmatic security consists of methods of the Java
EE Security API
Programmatic security is discussed in more detail in the following sections: