The component containers are responsible for providing Java EE application security. The container provides two security forms:
Annotations (also called metadata) 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 using annotations. When the application is deployed, this information can either be used by or overridden by the application or module deployment descriptor.
Declarative security means that the security mechanism for an application is declared and handled externally to the application. Deployment descriptors describe the Java EE application’s security structure, including security roles, access control, and authentication requirements.
The GlassFish Server supports the deployment descriptors specified by Java EE and has additional security elements included in its own deployment descriptors. Declarative security is the application deployer’s responsibility. For more information about GlassFish Server deployment descriptors, see the Oracle GlassFish Server 3.1 Application Deployment Guide.
There are two levels of declarative security, as follows:
For an application, roles used by any application must be defined in @DeclareRoles annotations in the code or role-name elements in the application deployment descriptor (application.xml). Those role names are scoped to the EJB XML deployment descriptors (ejb-jar.xml and glassfish-ejb-jar.xml files) and to the servlet XML deployment descriptors (web.xml and glassfish-web.xml files). For an individually deployed web or EJB module, you define roles using @DeclareRoles annotations or role-name elements in the Java EE deployment descriptor files web.xml or ejb-jar.xml.
To map roles to principals and groups, define matching security-role-mapping elements in the glassfish-application.xml, glassfish-ejb-jar.xml, or glassfish-web.xml file for each role-name used by the application. For more information, see Roles, Principals, and Principal to Role Mapping.
Component level security encompasses web components and EJB components.
A secure web container authenticates users and authorizes access to a servlet or JSP by using the security policy laid out in the servlet XML deployment descriptors (web.xml and glassfish-web.xml files).
Programmatic security involves an EJB component or servlet using method calls to the security API, as specified by the Java EE security model, to make business logic decisions based on the caller or remote user’s security role. Programmatic security should only be used when declarative security alone is insufficient to meet the application’s security model.
The Java EE specification defines programmatic security as consisting of two methods of the EJB EJBContext interface and two methods of the servlet HttpServletRequest interface. The GlassFish Server supports these interfaces as specified in the specification.
For more information on programmatic security, see the following:
The Java EE Specification