API for development
API for development
Eclipse GlassFish provides several APIs to build applications and components:
-
Jakarta EE API - Platform or Web profile, depends on the Eclipse GlassFish distribution
-
MicroProfile API - selected specifications, only avaiable in Eclipse GlassFish Full
-
GlassFish API - to access other functionality provided by Eclipse GlassFish
GlassFish API is composed of a few sets of APIs:
-
GlassFish API
-
GlassFish EE API
-
Simple GlassFish API
GlassFish API
Most of the functionality specific to Eclipse GlassFish is available in the GlassFish API. To compile applications or components, add the glassfish-api.jar to the compile classpath. You may also need scattered-archive-api.jar.
The glassfish-api.jar is located in the Eclipse GlassFish installation in as-install/modules/glassfish-api.jar.
In Maven project, you can add it as the following dependency:
<dependency>
<groupId>org.glassfish.main.common</groupId>
<artifactId>glassfish-api</artifactId>
</dependency>
This will already add scattered-archive-api.jar as a transitive dependency.
MicroProfile JWT Integration
The GlassFish API includes CDI qualifiers for integrating with built-in security mechanisms.
@MicroProfileJwtAuthenticationMechanism Qualifier
The @MicroProfileJwtAuthenticationMechanism qualifier allows direct injection of the GlassFish built-in MicroProfile JWT authentication mechanism:
import jakarta.inject.Inject;
import jakarta.security.enterprise.authentication.mechanism.http.HttpAuthenticationMechanism;
import org.glassfish.api.security.jwt.MicroProfileJwtAuthenticationMechanism;
@ApplicationScoped
public class SecurityService {
@Inject
@MicroProfileJwtAuthenticationMechanism
private HttpAuthenticationMechanism jwtAuthMechanism;
// Use the JWT authentication mechanism directly
}
This qualifier provides:
-
Direct Access: Direct access to the GlassFish JWT authentication mechanism
-
CDI Integration: Seamless integration with CDI dependency injection
-
Type Safety: Uses the standard
HttpAuthenticationMechanisminterface
The @MicroProfileJwtAuthenticationMechanism qualifier is complementary to the qualifiers for the standard Jakarta Security mechanisms like the Basic authentication mechanism. It can be combined with the other standard mechanisms in the same HttpAuthenticationMechanismHandler.
Example:
@ApplicationScoped
@Alternative
@Priority(Interceptor.Priority.APPLICATION)
public class CustomAuthenticationHandler implements HttpAuthenticationMechanismHandler {
@Inject
@MicroProfileJwtAuthenticationMechanism
HttpAuthenticationMechanism jwtAuthentication;
@Inject
@BasicAuthenticationMechanismDefinition.BasicAuthenticationMechanism
HttpAuthenticationMechanism basicAuthentication;
@Override
public AuthenticationStatus validateRequest(HttpServletRequest request, HttpServletResponse response, HttpMessageContext messageContext) throws AuthenticationException {
// delegate to one of the two mechanisms
}
}
GlassFish EE API
GlassFish EE API provides functionality related to Jakarta EE. To compile applications or components, add the glassfish-ee-api.jar to the compile classpath.
The glassfish-ee-api.jar is located in the Eclipse GlassFish installation in as-install/modules/glassfish-ee-api.jar.
In Maven project, you can add it as the following dependency:
<dependency>
<groupId>org.glassfish.main.common</groupId>
<artifactId>glassfish-ee-api</artifactId>
</dependency>
Simple GlassFish API
Simple GlassFish API provides basic functionality to deploy applications and run admin commands. Mostly to use embedded Eclipse GlassFish programmatically. To compile applications or components, add the simple-glassfish-api.jar to the compile classpath.
The simple-glassfish-api.jar is located in the Eclipse GlassFish installation in as-install/modules/simple-glassfish-api.jar.
In Maven project, you can add it as the following dependency:
<dependency>
<groupId>org.glassfish.main.common</groupId>
<artifactId>simple-glassfish-api</artifactId>
</dependency>