The next minor release of the Holon Platform, tagged 5.2, is on track and we are working to make it stable and complete. The 5.2 release line is focused on the following main goals:

  • Technology updates and alignment to the most recent updates of the libraries with which the platform provides integration: for example Spring 5, Spring Boot 2, JAX-RS 2.1, Swagger/OpenAPI 3.
  • A complete support for asynchronous and reactive programming, including integration with RxJava and Project Reactor.
  • A new MongoDB Datastore, the first Datastore API implementation for the NoSQL world, with asynchronous and reactive support for data access and manipulation using the Holon Platform Property model.
  • A new Vaadin Flow UI module, to use the new Vaadin 10 web applications framework with an API consistent with the current Holon Platform Vaadin 7 and 8 modules. This will allow a quite seamless migration of the web applications based on the previous Vaadin versions, created using the Holon Platform Vaadin module API.
  • A better support for the JDK 9+ module system, providing automatic module names for each artifact included in the Holon Platform.
  • Many API enhancements and new features, along with performance optimizations and improved API extensibility.

The official 5.2 release is expected for the end of September 2018. But in the meantime, you can download the first alpha release, named 5.2.0-alpha1, which is now available as developers preview and for testing purposes.

This alpha release only includes:

  • Support for JDK 9+ module system
  • Support for Spring 5.x
  • Support for Spring Boot 2.x
  • Support for JAX-RS 2.1

All the artifacts are available from Maven Central. You can find the complete list of changes on GitHub.

The alpha1 release of the documentation is also available.

As always, we are happy to receive any feedback or suggestion! Furthermore, we are always open to the community, so don’t hesitate to open issues and pull request on GitHub. All the Holon Platform repositories have instructions on how to contribute.

Stay tuned on the blog to learn about the next 5.2 release line steps!

The Holon Platform release 5.1.4 has just been published.

This release fixes some bugs and provide external dependencies updates.

Furthermore, some minor new features were introduced in the Holon Platform Vaadin module:

  • The ItemListing builder API now provides methods to easily setup the column headers caption using HTML markup. See the updated documentation section.
  • The PropertyListing builder API makes available methods to configure the default listing columns display positions using declarations such as “display as first” or “display before/after another column”. This can be useful in many situations to avoid the explicit column ordering specification of the whole property set. See this documentation section for details.
  • It’s now easier and quicker adding virtual (or “generated”) columns to a PropertyListing component, using the new builder API methods, which allow to declare the property value provider function and to configure the column before adding it to the listing. See the documentation to learn more.

See https://github.com/holon-platform/platform/releases/tag/5.1.4 for the complete list of changes.

As usual, all the platform artifacts are available from Maven Central.

The Holon Platform release 5.1.2 has just been published.

This is a maintenance release to fix some bugs and provide external dependencies updates.

If you use the TenantScope, we recommend to update the Holon Platform to this release, which solves a bug related to the Spring scoped target beans.

Furthermore, some minor enhancements were introduced to the JWT support API, for example the JWT nbf claim handling (see here) and a new JwtTokenParser API to obtain an Authentication instance from a JSON Web Token value.

See https://github.com/holon-platform/platform/releases/tag/5.1.2 for the complete list of changes.

As usual, all the platform artifacts are available from Maven Central.

On behalf of the team, it is my very great pleasure to announce that the Holon Platform version 5.1.0 is now generally available from Maven Central.

Along with all the latest bug fixes, there is also a lot of useful features that are made available with the 5.1 minor release. Just to give some examples:

  • PropertySet identifier properties support.
  • Type-specific PathProperty APIs to easily deal with most common property data types in a more consistent way.
  • Transactional operations support using the Datastore API.
  • Full support for the java.time.* Date and Time API in all the suitable platform modules.
  • A brand new Json API to easily deal with JSON serialization and deserialization in a library-independent way.
  • Considerable performance improvements at many levels, especially for the Datastore API implementations.
  • Improved extensibility at API level for some of the core platform architecture structures.
  • Better integration with Spring and Spring Boot, including new integration features for Spring Security.

Furthermore, a great deal of work has been done on the Holon Platform documentation, to make it even more complete, detailed and useful, providing a great number of code samples and cross-references to the core API sections.

See What’s new in version 5.1 for the full list of changes and the detailed release notes.

The public Java API is fully compatible with the previous versions, for a seamless migration from version 5.0.x.

So don’t wait any longer and start from here with the new platform version.

We’re working on next minor release of the Holon Platform, that is expected to be stable and generally available by the end of March.

UPDATE:

The release date was moved to April 20 to spend more time reviewing the documentation and providing more support material, such as tutorials and examples.

Along with all the latest bug fixes, there is also a lot of useful features that made it to this milestone.

As a minor release, the public Java API is fully compatible with the previous version, for a seamless migration with a minimal effort from version 5.0.0.

Below is a list of the of the new and noteworthy features, listed by module.

Core Module

  • The PropertySet object now supports identifier properties declaration, which can be used to provide a virtual primary key to distinguish a PropertyBox instance from another, both at Java object level (equals and hashCode) and at persistence architecture level.
  • The Property architecture was made even more flexible and extensible, providing configuration hooks for custom logic and introducing PathProperty extensions to easily deal with main property data types in a more consistent way. For example, the StringProperty interface can be used for String data type, the NumericProperty one for numeric types and so on.
  • Performance improvements to the ExpressionResolver based architecture through smart caching strategies and a revision of the internal expression resolution logic.
  • A deep revision of the Expression based architecture, which is the foundation, above all, of the Datastore API and the abstract query engine. This lead to a more consistent and extensible architecture, along with considerable performance improvements and a better foundation for future Datastore developments, including asynchronous and reactive implementations.
  • Introduction of an high level transactional support for Datastore, allowing to manage transactions in a platform agnostic way, independently from the underlying persistence technology.
  • Spring Security support and integration at authentication/authorization architecture level
  • A set of little improvements to the core Java API, to made it even more effective and easy to use.

JSON Module

  • A bran new Json Java API to easily deal with JSON serialization and deserialization in a JSON provider independent way, with full Property and PropertyBox support. At the moment, the supported JSON provider are Jackson and Gson.
  • An improved and consistent support for the java.time.* Date and Time API data types, including the support within a PropertyBox.

JAX-RS Module

  • Improved support for the java.time.* Date and Time API with JSON when a PropertyBox is used as data transfer object in JAX-RS endpoints.
  • A better Spring Boot auto-configuration support for Jersey and Resteasy.
  • The Swagger integration and auto-configuration is more extensible and configurable through Spring Boot properties.

JDBC Datastore Module

  • Complete and deep revision and rewriting of the internal SQL operations engine, which is now separated as an independent artifact from the core JDBC Datastore artifact. This lead to greater extensibility, a more consistent operation resolution strategy and remarkable performance improvements.
  • Support of the the PropertySet identifier properties to detect the persistent entities primary keys avoiding additional database accesses.
  • Improved extensibility by design, allowing to easily provide custom expressions and resolvers.
  • Full support for Date and Time functions.
  • Added the high level Transactional support.
  • Improved configuration capabilities when the Spring Boot auto-configuration is used.
  • Improved support for industry-standard vendors RDBMS, such as Oracle Database, Microsoft SQLServer, IBM DB2 and SAP HANA.

JPA Datastore Module

  • Complete and deep revision and rewriting of the internal JPQL operations engine, to improve consistency and performances.
  • Better support for generic entity beans.
  • Improved extensibility by design, allowing to easily provide custom expressions and resolvers.
  • Full support for Date and Time functions.
  • Added the high level Transactional support.
  • Improved configuration capabilities when the Spring Boot auto-configuration is used.
  • Better support for Apache OpenJPA and Datanucleus ORMs, along with the standard support for Hibernate and Eclipselink.

Vaadin Module

  • Support for the PropertySet identifier properties to make more easy and quick to setup data bound UI objects.
  • Full support of Vaadin version 8.3, including for example the @PushStateNavigation strategy for Navigator.
  • Better support for bean based data bound UI objects, with new builders and a seamless Java API just like the Property based one.
  • Support for drag and drop at Java API level.

The reference manual will be updated to reflect the API changes and to document all new features. Detailed release notes and changelog will be provided when new release will be made available and published.

So stay tuned!

Red Hat is the world’s leading provider of Open Source, enterprise IT solutions. We share the Red Hat’s mission to make the Open Source software a trusted and reliable asset for enterprise organizations, believing in the Open Source ecosystem as the most effective way to innovation.

For this reason, we’re pleased to announce that the Holon Platform has been certified for the Red Hat JBoss Middleware and has been published in the Red Hat Certified Product Catalog.

You can learn more here.

We intend to go on in the Red Hat partnership process, to achieve more certifications and provide our contribution to the Open Source growth in the enterprise world.

Follow us to be informed about next steps.

You can explore two examples of a simple web application, created with the Holon Platform and ready to be deployed on Red Hat JBoss EAP, on GitHub:

The Holon Platform release 5.0.6 has just been published.

This release introduces some useful features and fixes some bugs.

For example, new interfaces to build HttpRequest objects are provided for Servlet and JAX-RS requests, respectively in Core and JAX-RS modules. This allows to easily use the HTTP request messages for example to perform authentication operations using Holon’s message authenticators.

Many additional features have been added to the Vaadin module, for example to use value converters with Input and Input groups/forms, to configure value change listeners and new fluent builders are provided to create TabSheet and Accordion UI components. See the Vaadin module closed issues for the full list of changes.

See https://github.com/holon-platform/platform/releases/tag/5.0.6 for the complete list of changes.

As usual, all the platform artifacts are available from Maven Central.

See modules to check for each Holon Platform module update.

The fourth bug fix release of the Holon Platform has just been published.

This release introduces some minor features, fixes more bugs and includes some external dependencies updates. Main minor new features are:

See https://github.com/holon-platform/platform/releases/tag/5.0.5 for the complete list of changes.

As usual, all the platform artifacts are available from Maven Central.

See modules to check for each Holon Platform module update.

The fourth bug fix release of the Holon Platform has just been published.

This release introduces some minor features and fixes more bugs. See https://github.com/holon-platform/platform/releases/tag/5.0.4 for the complete list of changes.

As usual, all the platform artifacts are available from Maven Central.

See modules to check for each Holon Platform module update.

The third bug fix release of the Holon Platform has just been published.

This release introduces some minor features and fixes more bugs. See https://github.com/holon-platform/platform/releases/tag/5.0.3 for the complete list of changes.

As usual, all the platform artifacts are available from Maven Central.

See modules to check for each Holon Platform modules update.

Information security is one of the most importart concerns facing an increasily connected world. And since APIs are the glue of the digital landscape, API security is more important than ever.

In this scenario, user identity and access management are core concepts to deal with. In API architectures, in particular with the emerging microservices approach, the real challenge is to enable a strong security and identity management support while keeping efficiency and reliability.

In a microservices environment, the services are scoped and deployed in multiple containers in a distributed setup, and the service interactions are frequent and remote, mostly over HTTP. In this distributed and stateless world, even the user identity has to be managed in a distributed and stateless way.

What we need here is a solution that allows reliable user identity management and authorization checking without additional overhead, and using the JSON Web Tokens (JWT for short) can be the answer.

Quoting from the jwt.io introduction, a JWT can be defined as follows:

JSON Web Token (JWT) is an open standard (RFC 7519) that defines a compact and self-contained way for securely transmitting information between parties as a JSON object. This information can be verified and trusted because it is digitally signed. JWTs can be signed using a secret (with the HMAC algorithm) or a public/private key pair using RSA.

In a world where service-to-service communication security is a real concern, using a JSON Web Token offers many advantages:

  • Performance and easy distribution: The JWT representation is compact, and thanks to its small size, the trasmission of a JWT token is fast and can be effectively performed using the HTTP protocol, for example using a URL, POST parameter, or inside a HTTP header.
  • Efficiency: A JWT token is self-contained, carrying in its payload all the identity information (including authorizations), avoiding the need to perform additional calls (for example a database query) to obtain user information.
  • Simplicity and standardization: JWT is an open standard and uses JSON to represent the identity information, a widely used and supported data format.
  • Granular security: With JWT you can provide fine grained resource access control.
  • Debuggability: JSON Web Tokens can be easily inspected, differently for example from an opaque API key.
  • Expiration control: A JWT supports an expiration time, easy to set and control.
  • OAuth2 compliance: OAuth2 uses an opaque token that relies on a central storage. You can return a JSON Web Token instead, with the allowed scopes and expiration.

Ok, now let’s get our hands dirty

I’ll take the simple API application example of my previous article, Spring Boot, Jersey, and Swagger: Always Happy Together, as a starting point to show you how to use the Holon Platform to secure API operations using JWT. The Holon Platform JWT support relies on the jjwt library to encode, decode and verify the JWT tokens.

The source code of the updated example API application can be found on GitHub, in the jwt branch of the spring-boot-jaxrs-swagger-api-example repository: https://github.com/holon-platform/spring-boot-jaxrs-swagger-api-example/tree/jwt.

In a typical scenario, the JSON Web Tokens emission, interchange and consumption process involves at least three actors: the issuer, the protected resource and the client.

1. The JWT issuer

The issuer is in charge to issue a JSON Web Token as a response to a valid authentication request. This step can include the user account credentials validation.

The produced JSON Web Token can contain detailed user information, including for example user profile information and authorizations, in addition to system and validation related data, such as the issuer name and the expiration time. These information are called claims in the JWT terminology, and they constitute the JWT payload. In addition to the set of reserved claims, you can provide a number of custom claims to represent the user identity and account information.

The issuer role can be easily intepreted by a OAuth2 UAA (User Account and Authentication) server, which returns a JWT instead of an opaque and randomly generated token.

In this example, we’ll simulate the JSON Web Token generation by a UAA server, using the Holon Platform authentication and authorization APIs from a JUnit test class. The Holon Platform authentication architecture relies on the Authentication interface to represent the authenticated principal (which can represent an user but also another entity). The Authentication structure supports permissions to represent the authorization grants and generic parameters to specify the account details.

To build a JSON Web Token from an Authentication, the JwtTokenBuilder class can be used. This builder will translate the Authentication permissions and parameters into JWT claims.

The JWT token builder needs to know which kind of token to build (signed or not), which algorithm has to be used to sign the token and any additional reserved claim (such as the token unique id, the issuer name and the expiration time) to add to the token itself before encoding it. This information can be collected and provided to the builder using the JwtConfiguration interface and the Holon Platform Spring Boot support can be used to build a JwtConfiguration using the application configuration properties.

To enable the Holon Platform JWT support, we just have to add the holon-auth-jwt artifact dependency to the dependecies section of our project’s pom:

<!-- Holon JWT support -->
<dependency>
  <groupId>com.holon-platform.core</groupId>
  <artifactId>holon-auth-jwt</artifactId>
</dependency>

Now we can use a set of Spring Boot configuration properties, with the holon.jwt prefix, to auto-configure a JwtConfiguration instance which will be made available as a Spring component. The list of all the configuration properties is available here.

In this example, we want to setup the issuer name to be used, the expiration time and the signature algorithm to use. For the sake of simplicity, in this example we’ll use a symmetric signing algorithm (HMAC with SHA-256), so we only need a single secret key, which has to be shared between the parties.

So you want to modify the application.yml configuration file adding the following configuration properties:

holon:
  jwt:
    signature-algorithm: HS256
    sharedkey-base64: eWGZLlCrUjtBZwxgzcLPnA
    expire-hours: 1
    issuer: example-issuer

The expire-hours property is used to specify an expiration time of one hour, but other configuration properties are available to use a different unit of time (for example expire-minutes, expire-seconds, expire-ms).

From now on, we can simply obtain the JwtConfiguration which represents these configuration properties as an injected dependency.

So, let’s see an example about a JSON Web Token generation from an Authentication object (you can find more examples in the ApiTest unit test class of the source repository):

@Autowired
private JwtConfiguration jwtConfiguration;

@Test
public void jwtBuilder() {
  Authentication authc = Authentication.builder("testUser") // principal name
    // permissions
    .permission("ROLE1").permission("ROLE2")
    // user details
    .parameter("firstName", "Test")
    .parameter("lastName", "User")
    .parameter("email", "test@holon-platform.com")
    // build the Authentication 
    .build();

  // Build the JSON Web Token using the provided configuration and Authentication
  String jwtToken = JwtTokenBuilder.buildJwtToken(jwtConfiguration, authc, 
    UUID.randomUUID().toString() // Token id claim (jti)
  );
}

The JWT produced in the example above will look like this:

eyJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1MDg3Njc1NzAsImp0aSI6ImNkYzNmMmQ3LWY5MWEtNGExZi1iY2Y0LTM1MGM3OWM2Y2FiYyIsInN1YiI6InRlc3RVc2VyIiwiaXNzIjoiZXhhbXBsZS1pc3N1ZXIiLCJleHAiOjE1MDg3NzExNzAsImZpcnN0TmFtZSI6IlRlc3QiLCJsYXN0TmFtZSI6IlVzZXIiLCJlbWFpbCI6InRlc3RAaG9sb24tcGxhdGZvcm0uY29tIiwiQVRIJHJvb3QiOmZhbHNlLCJBVEgkcHJtcyI6WyJST0xFMSIsIlJPTEUyIl19.4iXLnGHClfVPHF48Bz1aIyoOgsou8Usn2yXf4NUut_M

This token can be easily transmitted using the HTTP protocol, using for example an Authorization header.

See this example for a simple JWT authorization server which issues JSON Web Tokens as the response of a POST invocation providing username and password using the HTTP Basic scheme authorization header.

2. The protected resource

Now it’s time to protected our API operations using JWT.

We’ll leverage again on the Holon Platform authentication architecture, using the Realm security abstraction and the Holon Platform Spring Boot support to allow API resources access only to authenticated clients.

We’ll use HTTP Authorization header with the Bearer scheme to obtain the JWT provided by the client. The JSON Web Token will be validated according to the JWT configuration properties (checking the sign, the issuer name and the expiration time), then the JWT claims can be used to obtain the required user identity information.

We want to implement a simple authorization control too, so the permission claims will be used to obtain the user roles and check if it was granted to access an API operation.

First of all, we have to setup the Holon Platform security Realm, specifying:

  • An AuthenticationTokenResolver to translate the JWT into an authentication token which can be interpreted by the Realm’s authenticators.
  • The Authenticator which the Realm has to use in order to perform the account authentication.
  • An Authorizer, responsible for authorization control. The default Authorizer relies on the Authentication permissions to check the user authorization against the required permissions/roles.

The Realm is configured as a Spring component in the Application class and will be automatically located and used by the Holon Platform authorization and authentication architecture:

@Bean
public Realm realm(JwtConfiguration jwtConfiguration) {
  return Realm.builder()
    // HTTP Bearer authorization schema resolver
    .resolver(AuthenticationToken.httpBearerResolver())
    // JWT authenticator using the provided JwtConfiguration
    .authenticator(JwtAuthenticator.builder().configuration(jwtConfiguration).build())
    // default authorizer
    .withDefaultAuthorizer().build();
}

The JwtConfiguration bean is automatically created using the application confguration properties as seen before.

Finally, we enable the API endpoint protection simply by using the Holon Platform @Authenticate annotation on the JAX-RS resource class:

@Authenticate // require authentication
@ApiDefinition(docsPath = "/api/docs", title = "Example API", version = "v1", prettyPrint = true)
@Api("Test API")
@Component
@Path("/api")
public class ApiEndpoint {

  // content omitted

}

The Holon Platform JAX-RS module automatically setup Jersey enabling the following behaviour:

  • A resource method annotated with @Authenticate is only accessible by a valid, JWT authenticated, client request. If the @Authenticate annotation is declared at class level, all the JAX-RS class methods inherits the authentication setup. If the authentication is not present or not valid, a 401 - Unauthorized status error response is returned.
  • The JAX-RS SecurityContext of an authenticated request returns the Authentication instance associated to the request from the getUserPrincipal() method. The Holon Platform translates back the JWT claims into the Authentication permissions and parameters, so they can be simply accessed from the JAX-RS method.
  • The standard javax.annotation.security.* annotations (@PermitAll, @DenyAll, @RolesAllowed) are enabled to perform role-based resource access control, using the  Authentication permissions provided by the JWT. If authorization control is not successfull, a 403 - Forbidden  status error response is returned.
  • For more advanced authorization controls, the Realm component can be injected in the JAX-RS endpoint to leverage on the Realm API operations using the current Authentication.

For example, to declare that no role is required to access the original /ping operation, the @PermitAll annotation can be used:

@PermitAll // no specific role required
@ApiOperation("Ping request")
@ApiResponses({ @ApiResponse(code = 200, message = "OK: pong", response = String.class) })
@GET
@Path("/ping")
@Produces(MediaType.TEXT_PLAIN)
public Response ping() {
  return Response.ok("pong").build();
}

The ROLE2 authorization is required to access the following API operation, and the JAX-RS SecurityContext is used (injected through the standard JAX-RS @Context annotation) to obtain the authenticated principal name:

@RolesAllowed("ROLE2") // ROLE2 is required
@ApiOperation("Get user name")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = String.class) })
@GET
@Path("/user")
@Produces(MediaType.TEXT_PLAIN)
public Response userOperation(@Context SecurityContext securityContext) {
  // get the user principal name from the JAX-RS SecurityContext
  String principalName = securityContext.getUserPrincipal().getName();
  return Response.ok(principalName).build();
}

Finally, we add an API operation which uses the Authentication obtained from the JAX-RS SecurityContext to read the custom JWT claims ("firstName", "lastName", "email") and the Holon Platform Realm for additional authorization control. The example response is the JSON representation of a UserDetails example class:

@Inject
private Realm realm;

@RolesAllowed("ROLE2") // ROLE2 is required
@ApiOperation("Get user details")
@ApiResponses({ @ApiResponse(code = 200, message = "OK", response = String.class) })
@GET
@Path("/details")
@Produces(MediaType.APPLICATION_JSON)
public UserDetails userDetails(@Context SecurityContext securityContext) {

  // the Holon platform Authentication is available as the JAX-RS SecurityContext user principal
  Authentication auth = (Authentication) securityContext.getUserPrincipal();

  // use Realm to perform additional authorization checks
  boolean hasRole1 = realm.isPermitted(auth, "ROLE1");

  UserDetails userDetails = new UserDetails();
  userDetails.setUserId(auth.getName());
  userDetails.setRole1(hasRole1);

  // read the JWT claims, translated into Authentication parameters
  auth.getParameter("firstName", String.class).ifPresent(p -> userDetails.setFirstName(p));
  auth.getParameter("lastName", String.class).ifPresent(p -> userDetails.setLastName(p));
  auth.getParameter("email", String.class).ifPresent(p -> userDetails.setEmail(p));

  return userDetails;
}

3. The client

The last actor is the client, which obtains the JSON Web Token from the issuer and uses it to perform the API calls, providing it as HTTP Authorization header Bearer token.

In a service-to-service communication scenario, the JWT obtained from the original API request can be passed around to perform additional inter-service calls. No additional overhead, such as querying the database, is needed to obtain the identity information, which is encapsulated in the JWT payload.

See the ApiTest class to learn how to use the Holon Platform RestClient to perform RESTful API invocations providing the JWT as Authorization header Bearer token.

API Documentation

In the previous post, we’ve seen how to use the Holon Platform Swagger support to create and provide a standard API documentation. Now we want to complete the API documentation, adding the authorization information.

Let’s suppose to use OAuth2 to obtain the JWT bearer token. In this example, the OAuth2 authorization server is available at the https://example.org/api/oauth2 URL.

Our authorization example roles (ROLE1 and ROLE2) will be represented as OAuth2 scopes.

Using the standard Swagger annotations, we’ll add API authorization definitions in the JAX-RS endpoint class this way:

1. Declare the API security schemes (OAuth2 in this example) using the @SwaggerDefinition annotation, including the available authorization scopes, then declare the authorization scheme (that we called jwt-auth) in the @Api annotation:

@SwaggerDefinition(securityDefinition = @SecurityDefinition(oAuth2Definitions = 
  @OAuth2Definition(key = "jwt-auth", description = "JWT Bearer token", flow = Flow.IMPLICIT,  
                    authorizationUrl = "https://example.org/api/oauth2", 
                    scopes = {
		      @Scope(name = "ROLE1", description = "Test role 1"),
		      @Scope(name = "ROLE2", description = "Test role 2") })))
@Api(value = "Test API", authorizations = @Authorization("jwt-auth"))
// other annotations omitted
public class ApiEndpoint {
  // content omitted
}

2. Declare the authorization scopes (the roles), required to access a specific API operation, in the @ApiOperation annotation. For example:

@ApiOperation(value = "Get protected resource", 
  authorizations = @Authorization(value = "jwt-auth", scopes = @AuthorizationScope(scope = "ROLE1")))
  @ApiResponses({ @ApiResponse(code = 200, message = "OK", response = String.class) })
@RolesAllowed("ROLE1") 
// other annotations omitted
public Response protectedOperation() {
  return Response.ok("protected").build();
}

Thanks to the Holon platform Swagger auto-configuration, the API documentation can be obtained in JSON format from the URL:

http://hostname:9999/api/docs

Using the Swagger Editor to display the API documentation, it will appear like this:

The API authorization scheme can be inspected clicking on the lock icons, for example:

Summary

We’ve seen how JWT can be a lightweight and versatile alternative to other traditional authentication systems, mostly in the stateless API and microservices world, and how the Holon Platform can make its implementation simple and reliable.

The source code of this example API application can be found on GitHub, in the jwt branch of the spring-boot-jaxrs-swagger-api-example repository: https://github.com/holon-platform/spring-boot-jaxrs-swagger-api-example/tree/jwt.

See the previous post to learn how to create the API example application using Spring Boot, Jersey and the Holon Platform JAX-RS module.

The API world. Graphic from Wikimedia

We are on the cusp of the API economy: APIs are everywhere, boosting the digital transformation and disrupting the way we think. So a shifting is required also in the way we develop.

APIs are expected to enable automation, in turn driving efficiency, consistency and cost savings. API quality matters, both for API consumers and implementers. For these reasons, building an API infrastructure from scratch may not be a good idea. It is much easier and more productive to use a good framework or library, often more than one.

From a development point of view, it’s crucial to achieve target whilst ensuring the fulfillment of the following requirements: timing, costs saving and quality. Standardization is one of important way to achieve those goals: to ensure consistency, speed-up development, enable factorization and simplify maintanance.

Furthermore, a very important factor in APIs is a complete and accurate documentation. And best of all, the documentation should be produced and provided in a standard form, to automate the documentation process and to ensure a great overall experience in API consuming.

Even for the simplest API, achieving all these goals and accomplishing all the required tasks may be not so simple for a developer. A minimal infrastructure must be setted up, a set of components has to be selected, configured and enabled to work together. The API implementation stack configuration can be a complex, repetitive and error-prone process. The developer should not take care about the configuration and components integration details, focusing on the business tasks the API has to face and resolve.

It is where standards, frameworks and libraries come to help, taking charge of the API infrastructure setup and configuration and leaving the developer free to focus on the API goals. In one sentence: focus on what matters and forget the tedious stuff.

The Holon Platform can act both as glue for industry-standard libraries and as a catalyst for API development productivity.

In this post, we’ll start from the beginning, showing how to create a simple API service. We’ll focus on project setup and configuration, leaving out the API business logic concerns. In fact, this API will provide a single “ping” operation, which will respond with a pong message.

The building blocks we’re going to use for this project are:

  1. Spring Boot for auto-configuration and execution using an embedded servlet container
  2. Jersey, the reference JAX-RS implementation, to create the API operations using the RESTful paradigm
  3. JSON as data interchange format
  4. Swagger (OpenAPI) for API documentation
  5. Spring Boot Actuator for service monitoring and management
  6. And of course, the Holon Platform JAX-RS module, to leverage on some configuration facilities and automate the API documentation creation and provisioning

The code of this example is available on GitHub: https://github.com/holon-platform/spring-boot-jaxrs-swagger-api-example.

Creating the API application

Maven is used for project setup and dependency management, so let’s start with configuring the project’s pom dependencies.

First of all, we import the Holon Platform BOM (Bill Of Materials), this way we’ll no longer need to specify the Holon Platform artifacts version. The right version of each artifact is declared and provided by the platform BOM.

<dependencyManagement>
  <dependencies>
    <!-- Holon Platform BOM -->
    <dependency>
      <groupId>com.holon-platform</groupId>
      <artifactId>bom</artifactId>
      <version>5.0.2</version>
      <type>pom</type>
      <scope>import</scope>
    </dependency>
  </dependencies>
</dependencyManagement>

We’ll use the Holon JAX-RS Spring Boot starter with Jersey as implementation, so we declare the following dependency:

<!-- Holon JAX-RS using Jersey -->
<dependency>
  <groupId>com.holon-platform.jaxrs</groupId>
  <artifactId>holon-starter-jersey</artifactId>
</dependency>

Do you prefer to use Resteasy as JAX-RS implementation? With Holon it’s only a matter of configuration, just change the Holon starter to use:

<!-- Holon JAX-RS using Resteasy -->
<dependency>
  <groupId>com.holon-platform.jaxrs</groupId>
  <artifactId>holon-starter-resteasy</artifactId>
</dependency>

These Holon Spring Boot starters inherit the standard Spring Boot web starters, and provide embedded servlet container configuration, logging and Holon specific auto-configuration facilities. By default, Tomcat is used as embedded servlet container. Want to use Undertow? Just change the starter name (for example, holon-starter-jersey-undertow). Concerning JSON data format instead, Jackson is automatically setted up. What if Gson is your preferred choice? It’s only about changing a name, again (for example, holon-starter-jersey-gson).

Now, independently from the starter you choosed, we have to create just 2 Java classes. The first one, which we call Application, is the Spring Boot application entry-point, which triggers auto-configuration and provides the main method used to run the application itself, starting the embedded servlet container and deploying our API endpoints:

@SpringBootApplication
public class Application {

  public static void main(String[] args) {
      SpringApplication.run(Application.class, args);
  }
	
}

A application.yml file can be used to provide application configuration properties. For example, to configure the embedded server port:

server:
  port: 9999

Next it’s time to create the API endpoint, which will provide the API operations listening to the HTTP requests and returning the corresponding responses, using JSON as data format. As said before, this simple API will only provide a ping operation, mapped to the GET request method, returning a pong response encoded as JSON. Finally, we want to map the API operations endpoint to the base “/api” path. Using JAX-RS, this is how the API endpoint can be defined:

@Component
@Path("/api")
public class ApiEndpoint {

    @GET
    @Path("/ping")
    @Produces(MediaType.APPLICATION_JSON)
    public Response ping() {
        return Response.ok("pong").build();
    }

}

Note the @Component annotation on the API endpoint class. This is a standard Spring annotation to declare this class as a Spring component, candidate for auto-detection. Relying on the Holon Platform auto-configuration features, this class will be automatically detected and registered as a JAX-RS resource in Jersey (or Resteasy). And of course, will be enabled as a Spring component, allowing, for example, dependency injections.

To run the application, we’ll use the Spring Boot maven plugin, declaring it in the project pom:

<build>
  <plugins>
    <plugin>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-maven-plugin</artifactId>
      <executions>
        <execution><goals><goal>repackage</goal></goals></execution>
      </executions>
    </plugin>
  </plugins>
</build>

This way, a runnable jar will be created by the Spring Boot plugin, with all the required dependencies and able to be execute standalone using a JRE.

To test the application, we can use the run Spring Boot maven goal this way:

mvn spring-boot:run

That’s it. The application can be now started, activating our API service. The ping operation will be available sending an HTTP GET request to an URL like this:

http://hostname:9999/api/ping

Obtaining a response like the following:

HTTP/1.1 200
Content-Type: application/json
Content-Length: 4
post

Documenting the API operations

We’ll use Swagger for API documentation. The Swagger specification is now the foudation of the Open API Initiative, which is trying to standardizing on how REST APIs are described.

The Holon Platform provides many configuration facilities for Swagger, perfectly integrated with JAX-RS and the Spring Boot auto-configuration architecture.

Let’s start adding the Holon Platform Swagger depencency to our project pom:

<dependency>		
  <groupId>com.holon-platform.jaxrs</groupId>
  <artifactId>holon-jaxrs-swagger</artifactId>
</dependency>

From now on, the Holon Platform auto-configuration services will auto-detect any JAX-RS endpoint annotated with the standard Swagger @Api annotation and automatically create a JAX-RS endpoint to generate and provide the Swagger API documentation. By default, this endpoint will be mapped to the /api-docs path and supports a type query parameter to obtain the Swagger API documentation as JSON (the default behaviour) or YAML.

Standard Swagger annotations are supported to enrich and configure the API documentation, such as @ApiOperation. Additionaly, the Holon Platform Swagger module provides the @ApiDefinition annotation, which can be used to configure the overall API informations (such the title and the version) and to change the default API documentation endpoint path. In this example, we want to use the /api/docs path to provide the API documentation.

So you want to modify the ApiEndpoint class this way:

@ApiDefinition(docsPath = "/api/docs", title = "Example API", version = "v1", prettyPrint = true)
@Api("Test API")
@Component
@Path("/api")
public class ApiEndpoint {

    @ApiOperation("Ping request")
    @ApiResponses({ @ApiResponse(code = 200, message = "OK: pong", response = String.class) })
    @GET
    @Path("/ping")
    @Produces(MediaType.APPLICATION_JSON)
    public Response ping() {
        return Response.ok("pong").build();
    }

}

This way, the Swagger API documentation can be obtained in JSON format from the URL:

http://hostname:9999/api/docs

Or in the YAML format:

http://hostname:9999/api/docs?type=yaml

Using the Swagger Editor to display the API documentation, it will appear like this:

Monitoring the API application

As a last step, we want to add application monitoring and management capabilities, using the Spring Boot Actuator, which adds several production grade services to obtain application information, health check, configuration and so on.

To enable the Spring Boot Actuator endpoints auto-configuration, we have to add the following dependencies to the project pom:

<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>4.3.11.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
  <version>1.5.8.RELEASE</version>
</dependency>

Now a set of monitoring endpoints should be registered. For example, the health check endpoint listens to the /health path. So we expect to obtain the health information performing a GET request to an URL like this:

http://localhost:9999/health

But wait… things do not go as we expected: the server renponds with a 404 (not found) error code! Why?

This is a well-known and annoying problem which occurs when the Jersey servlet is mapped to the root context path. The problem is that Jersey will get all the request. It does not know that it needs to forward to any actuator endpoints.

This can be resolved by change Jersey to be used as filter instead of a servlet. Using Spring Boot we can do this using a configuration property in the application.yml file:

spring:
  jersey:
    type: filter

But this is not enough: we also have to set the Jersey property to forward requests for URLs it doesn’t know. With the Holon Platform JAX-RS module this is simple, just another configuration property to set:

holon:
  jersey:
    forwardOn404: true

Well done, everything work as expected! The health check endpoint is reachable and provides the following JSON response content:

{"status":"UP"}

Summary

With 2 Java classes, a pom and a Spring Boot configuration file we setted up a production grade API application, able to be runned standalone, with API documentation and monitoring capabilities. Now it’s time to focus on business tasks, making the API somehow useful!

This this only the first article in a series that shows how to use the Holon Platform to face the API development challenges, including the microservices world, so stay tuned!


The source code of the example API created in this post is available on GitHub: https://github.com/holon-platform/spring-boot-jaxrs-swagger-api-example.

See the Holon Platform examples for other API development related sample projects.

We love the Vaadin framework and we use it from years now to build an amazing and modern User Experience for our internal projects and products. But above all, we choosed Vaadin to build the UI of many web applications for one reason: simplicity.

We share the values and objectives of the Vaadin fight for simplicity: focus on what matters the most, saving time which can be reemployed to create user value through better UX and features, and ensure freedom of choice, so that your choices are not limited by technologies, licensing or anything else.

The Holon Platform Vaadin module takes a step further towards semplicity and productivity, providing a fluent API to build the application components and backend connectors and a complete integration with the Holon Platform architecture, such as the Property model, the Datastore API, the authentication, authorization and localization support. Furthermore, Spring and Spring Boot are supported out-of-the-box, to exploit Spring’s great feautures and services and forget about the most annoying configuration concerns.

Check the full-stack web application tutorial to learn how to build a simple web application in minutes with Vaadin and the Holon Platform modules, using the Java language only.

The fight for simplicity is just started, and we want to be part of it. Join us and get started with the Holon Platform!

One of the Holon platform foundation concepts is the Property model, which can be used to represent a generic data model, abstracting away from data structure and persistence implementation details. The property model architecture is designed for maximum flexibility and versatility, so as not to limit its use to backend or data management application levels, but to make it a cross-cutting asset, to be seamlessy used in a multitude of situations and application or communication layers.

The Property interface, as PathProperty or VirtualProperty implementation in particular, along with the PropertySet and PropertyBox structures, allow you to obtain the main following benefits:

  • Collect all the relevant features and configuration data in a single point, represented by a Property, to avoid duplications and inconsistency between application layers;
  • Abstract away the property definition from the concrete data representation and persistence model, to favor loose coupling and independence from underlying data structures, extensibility and versatibility;
  • Provide common operations and functionalities, such as value converters and validators, in a consistent and well defined way;
  • Enable the use of a standard API to manage the data model, relying on the Property architecture abstractions, for example to query the data model or to transport data in the form of property values.

Read the reference documentation to get all the information about the Property model and to explore the Holon Platform APIs which allow you to define and use it to the maximum of its potential.

Or just start coding, following the property model tutorial and exploring the examples available on GitHub.

The Holon Platform

We’re pleased to announce the first public, Open Source release of the Holon Platform: a complete and versatile Java ecosystem to build high quality, enterprise-grade web services and full-stack applications.

The platform is the result of many years of internal development and has been used to create enterprise business projects and products. There is a long history of development and evolution behind it, from the first version many years ago. The version 5.0.0 is the first Open Source and Apache 2.0 licensed release, open to the developers community, and open to the future. Follow us on GitHub and join the developers community!

Dive into a new way of developing in Java: the Holon Platform API is designed to leverage on the Java 8 new features, such as static interface methods and Optionals, to be simple and powerful, allowing to encapsulate the implementation details and to create high maintanable services and applications, boosting development team productivity.

The Holon platform provides a full-stack application development environment, however you can select only the components or modules you need, or extend them leveraging on the high configurability and extensibility features ensured by the platform architecture. A large set of business components is provided to get your enterprise application projects on track in a very short time with a minimal configuration effort.

The Holon platform is designed for mission critical environments, thanks to its the lightweight, scalable and optimized architecture and can be used to effectively address common business applications concerns like authentication, authorization, internationalization and system integration.

A wide support for Spring and Spring Boot is ensured by the platform to minimize configuration concerns and to focus on business tasks.

Furthermore, a complete Vaadin integration is available to build full-stack applications using the Java language only, from backend to UI.

So don’t wait any longer and get started with the Holon Platform!

We use cookies to ensure that we give you the best experience on our website.