Class BaSyxHTTPServer
- Author:
- pschorn, espen, haque, danish
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionBaSyxHTTPServer(org.eclipse.basyx.vab.protocol.http.server.BaSyxContext context, de.iip_ecosphere.platform.support.aas.SetupSpec spec, de.iip_ecosphere.platform.support.aas.SetupSpec.AasComponent component) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddChildContextsIfConfigured(org.eclipse.basyx.vab.protocol.http.server.BaSyxContext context) Adds a child context if such were configured.private Consumer<? super org.eclipse.basyx.vab.protocol.http.server.BaSyxChildContext> Adds a child context to tomcat.private voidaddFilterChainProxyFilterToContext(org.apache.catalina.Context context, org.springframework.security.web.FilterChainProxy filterChainProxy) Adds a filter chain proxy to context.private voidaddNewServletAndMappingToTomcatEnvironment(org.eclipse.basyx.vab.protocol.http.server.BaSyxContext context, org.apache.catalina.Context rootCtx, Map.Entry<String, javax.servlet.http.HttpServlet> entry) Adds new servlets and mappings.private voidaddSecurityFiltersToContext(org.apache.catalina.Context context, org.eclipse.basyx.vab.protocol.http.server.JwtBearerTokenAuthenticationConfiguration jwtBearerTokenAuthenticationConfiguration) Adds security filters to context.private voidconfigureCorsOrigin(org.eclipse.basyx.vab.protocol.http.server.BaSyxContext context, javax.servlet.http.HttpServlet servlet) Configures the CORS origin.private voidConfigures the health endpoint.private voidconfigureSslConnector(org.eclipse.basyx.vab.protocol.http.server.BaSyxContext context, org.apache.catalina.connector.Connector httpsConnector) SSL Configuration for SSL connector.private org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFiltercreateBearerTokenAuthenticationFilter(org.eclipse.basyx.vab.protocol.http.server.JwtBearerTokenAuthenticationConfiguration jwtBearerTokenAuthenticationConfiguration) Creates a bearer token authentication filter.private org.springframework.security.web.access.ExceptionTranslationFilterCreates an exception translation filter.private org.springframework.security.web.FilterChainProxycreateFilterChainProxy(org.eclipse.basyx.vab.protocol.http.server.JwtBearerTokenAuthenticationConfiguration jwtBearerTokenAuthenticationConfiguration) Creates a filter chain proxy for token authentication.private org.apache.tomcat.util.descriptor.web.FilterDefcreateFilterChainProxyFilterDefinition(org.springframework.security.web.FilterChainProxy filterChainProxy) Creates a filter chain proxy filter definition.private org.apache.tomcat.util.descriptor.web.FilterMapCreates a filter chain proxy filter map.private org.springframework.security.web.firewall.HttpFirewallCreates the HTTP firewall.private org.springframework.security.oauth2.jwt.JwtClaimValidator<Collection<String>> createJwtClaimValidatorForRequiredAudience(String requiredAud) Creates a JWT claim validator for required audience.private org.springframework.security.oauth2.jwt.JwtDecodercreateJwtDecoder(String issuerUri, String jwkSetUri, String requiredAud) Creates a JWT decoder.private org.springframework.security.oauth2.core.OAuth2TokenValidator<org.springframework.security.oauth2.jwt.Jwt> createOAuth2TokenValidator(String issuerUri, String requiredAud) Creates an OAuth2 token validator.private org.springframework.security.web.SecurityFilterChaincreateSecurityFilterChain(org.eclipse.basyx.vab.protocol.http.server.JwtBearerTokenAuthenticationConfiguration jwtBearerTokenAuthenticationConfiguration) Creates a security filter chain for OAuth2.booleanhasEnded()Returns a value indicating whether the server is currently running.private booleanisCorsOriginDefined(org.eclipse.basyx.vab.protocol.http.server.BaSyxContext context) Returns whether CORS origin is defined.private booleanReturns whether the tomcat server is running.voidshutdown()This Method stops and destroys the tomcat instance.voidstart()Starts the server in a new thread to avoid blocking the main threadprivate voidStops it if the tomcat server is running.
-
Field Details
-
LOGGER
private static final de.iip_ecosphere.platform.support.logging.Logger LOGGER -
tomcat
private final org.apache.catalina.startup.Tomcat tomcat
-
-
Constructor Details
-
BaSyxHTTPServer
public BaSyxHTTPServer(org.eclipse.basyx.vab.protocol.http.server.BaSyxContext context, de.iip_ecosphere.platform.support.aas.SetupSpec spec, de.iip_ecosphere.platform.support.aas.SetupSpec.AasComponent component) Constructor. Create new Tomcat instance and add the provided servlet mappings- Parameters:
context- Basyx context with of url mappings to HTTPServletspec- the setup specificationcomponent- the component to create the server for
-
-
Method Details
-
addChildContextsIfConfigured
private void addChildContextsIfConfigured(org.eclipse.basyx.vab.protocol.http.server.BaSyxContext context) Adds a child context if such were configured.- Parameters:
context- the BaSyx context
-
addChildContextToTomcat
private Consumer<? super org.eclipse.basyx.vab.protocol.http.server.BaSyxChildContext> addChildContextToTomcat()Adds a child context to tomcat.- Returns:
- the child context consumer
-
configureHealthEndpoint
private void configureHealthEndpoint()Configures the health endpoint. -
addNewServletAndMappingToTomcatEnvironment
private void addNewServletAndMappingToTomcatEnvironment(org.eclipse.basyx.vab.protocol.http.server.BaSyxContext context, org.apache.catalina.Context rootCtx, Map.Entry<String, javax.servlet.http.HttpServlet> entry) Adds new servlets and mappings.- Parameters:
context- the BaSyx contextrootCtx- the root contextentry- the servlet entries
-
configureCorsOrigin
private void configureCorsOrigin(org.eclipse.basyx.vab.protocol.http.server.BaSyxContext context, javax.servlet.http.HttpServlet servlet) Configures the CORS origin.- Parameters:
context- the contextservlet- the servlet
-
isCorsOriginDefined
private boolean isCorsOriginDefined(org.eclipse.basyx.vab.protocol.http.server.BaSyxContext context) Returns whether CORS origin is defined.- Parameters:
context- the context to look into- Returns:
truefor defined,falseelse
-
addSecurityFiltersToContext
private void addSecurityFiltersToContext(org.apache.catalina.Context context, org.eclipse.basyx.vab.protocol.http.server.JwtBearerTokenAuthenticationConfiguration jwtBearerTokenAuthenticationConfiguration) Adds security filters to context.- Parameters:
context- the context to modifyjwtBearerTokenAuthenticationConfiguration- the bearer token authentication setup
-
addFilterChainProxyFilterToContext
private void addFilterChainProxyFilterToContext(org.apache.catalina.Context context, org.springframework.security.web.FilterChainProxy filterChainProxy) Adds a filter chain proxy to context.- Parameters:
context- the context to modifyfilterChainProxy- the proxy
-
createFilterChainProxyFilterMap
private org.apache.tomcat.util.descriptor.web.FilterMap createFilterChainProxyFilterMap()Creates a filter chain proxy filter map.- Returns:
- the map
-
createFilterChainProxyFilterDefinition
private org.apache.tomcat.util.descriptor.web.FilterDef createFilterChainProxyFilterDefinition(org.springframework.security.web.FilterChainProxy filterChainProxy) Creates a filter chain proxy filter definition.- Parameters:
filterChainProxy- the proxy- Returns:
- the filter definition
-
createFilterChainProxy
private org.springframework.security.web.FilterChainProxy createFilterChainProxy(org.eclipse.basyx.vab.protocol.http.server.JwtBearerTokenAuthenticationConfiguration jwtBearerTokenAuthenticationConfiguration) Creates a filter chain proxy for token authentication.- Parameters:
jwtBearerTokenAuthenticationConfiguration- the authentication configuration- Returns:
- the filter chain proxy
-
createHttpFirewall
private org.springframework.security.web.firewall.HttpFirewall createHttpFirewall()Creates the HTTP firewall.- Returns:
- the firewall instance.
-
createSecurityFilterChain
private org.springframework.security.web.SecurityFilterChain createSecurityFilterChain(org.eclipse.basyx.vab.protocol.http.server.JwtBearerTokenAuthenticationConfiguration jwtBearerTokenAuthenticationConfiguration) Creates a security filter chain for OAuth2.- Parameters:
jwtBearerTokenAuthenticationConfiguration- the authentication configuration- Returns:
- the filter chain
-
createExceptionTranslationFilter
private org.springframework.security.web.access.ExceptionTranslationFilter createExceptionTranslationFilter()Creates an exception translation filter.- Returns:
- the filter
-
createBearerTokenAuthenticationFilter
private org.springframework.security.oauth2.server.resource.web.BearerTokenAuthenticationFilter createBearerTokenAuthenticationFilter(org.eclipse.basyx.vab.protocol.http.server.JwtBearerTokenAuthenticationConfiguration jwtBearerTokenAuthenticationConfiguration) Creates a bearer token authentication filter.- Parameters:
jwtBearerTokenAuthenticationConfiguration- the token authentication configuration- Returns:
- the filter
-
createJwtDecoder
private org.springframework.security.oauth2.jwt.JwtDecoder createJwtDecoder(String issuerUri, String jwkSetUri, @Nullable String requiredAud) Creates a JWT decoder.- Parameters:
issuerUri- the issuer URIjwkSetUri- the JWK Set URIrequiredAud- the required audience for the OAuth2 token validator- Returns:
- the decoder
-
createOAuth2TokenValidator
private org.springframework.security.oauth2.core.OAuth2TokenValidator<org.springframework.security.oauth2.jwt.Jwt> createOAuth2TokenValidator(String issuerUri, @Nullable String requiredAud) Creates an OAuth2 token validator.- Parameters:
issuerUri- the issuer URIrequiredAud- the required audience for the OAuth2 token validator- Returns:
- the validator
-
createJwtClaimValidatorForRequiredAudience
private org.springframework.security.oauth2.jwt.JwtClaimValidator<Collection<String>> createJwtClaimValidatorForRequiredAudience(String requiredAud) Creates a JWT claim validator for required audience.- Parameters:
requiredAud- the required audience for the OAuth2 token validator- Returns:
- the claim validator
-
configureSslConnector
private void configureSslConnector(org.eclipse.basyx.vab.protocol.http.server.BaSyxContext context, org.apache.catalina.connector.Connector httpsConnector) SSL Configuration for SSL connector.- Parameters:
context-httpsConnector-
-
start
public void start()Starts the server in a new thread to avoid blocking the main threadThis method blocks until the server is up and running.
If an error occurs during server startup the process is aborted and the method returns immediately.
hasEnded()returnstruein this case.
This behavior can be disabled by setting the system propertyorg.apache.catalina.startup.EXIT_ON_INIT_FAILURE = false, for instance with the-Dcommand line option when launching the JVM, or throughSystem.setProperty(String, String)(before the first call toBaSyxHTTPServer). In this case the startup is finished regardless of any errors and subsequent calls tohasEnded()returnfalse, but the server might be left in an undefined and non-functional state.TODO: Throw exception upon startup failure. This is a breaking change, so wait until next major version.
-
stopTomcatServerIfRunningAlready
private void stopTomcatServerIfRunningAlready() throws org.apache.catalina.LifecycleExceptionStops it if the tomcat server is running.- Throws:
org.apache.catalina.LifecycleException- if stopping tomcat fails
-
isTomcatServerRunning
private boolean isTomcatServerRunning()Returns whether the tomcat server is running.- Returns:
truefor running,falseelse
-
shutdown
public void shutdown()This Method stops and destroys the tomcat instance. This is important since Tomcat would be already bound to port 8080 when new tests are run that require a start of tomcat -
hasEnded
public boolean hasEnded()Returns a value indicating whether the server is currently running.- Returns:
falseif the server is running,trueotherwise.
-