Red Hat Training
A Red Hat training course is available for Red Hat Decision Manager
Creating Red Hat Decision Manager business applications with Spring Boot
Red Hat Customer Content Services
brms-docs@redhat.comAbstract
Preface
As a developer, you can use Spring Boot starters through the business applications website to quickly create Red Hat Decision Manager business applications, configure those applications, and deploy them to an existing service or in the cloud.
Chapter 1. Red Hat Decision Manager business applications
Spring Framework is a Java platform that provides comprehensive infrastructure support for developing Java applications. Spring Boot is a lightweight framework based on Spring Boot starters. Spring Boot starters are pom.xml files that contain a set of dependency descriptors that you can include in your application.
Red Hat Decision Manager business applications are flexible, UI-agnostic logical groupings of individual services that provide certain business capabilities. Business applications are based on Spring Boot starters. They are usually deployed separately and can be versioned individually. A complete business application enables a domain to achieve specific business goals, for example order management or accommodation management.
On the business application website you can create a Process Automation Manager, Decision Manager, or Business Optimizer business application. After you create and configure your business application, you can deploy it to an existing service or to the cloud, through OpenShift.
Business applications can contain one or more of the following projects and more than one project of the same type:
- Business assets (kjar): Contains business processes, rules, and forms and are easily imported into Decision Central.
- Data model: Data model projects provide common data structures that are shared between the service projects and business assets projects. This enables proper encapsulation, promotes reuse, and reduces shortcuts. Each service project can expose its own public data model.
- Service: A deployable project that provides the actual service with various capabilities. It includes the business logic that operates your business. In most cases, a service project includes business assets and data model projects. A business application can split services into smaller component service projects for better manageability.
Chapter 2. Creating a business application
You can use the business application website to quickly and easily create business applications using the Spring Boot framework. Doing this by-passes the need to install and configure Red Hat Decision Manager.
Procedure
Enter the following URL in a web browser:
https://start.jbpm.org
- Click Configure your business application.
- Click Decision Management and click Next.
- Enter a package and application name.
From the Version menu, select Enterprise 7.2 and click Next.
NoteYou must select Enterprise 7.2 to create a Red Hat Decision Manager business application.
Select the project types that you want to include in your project. You can include more than one project type.
- Business Assets: Contains business processes, rules, and forms and are easily imported into Decision Central. Select Dynamic Assets instead if you want to add adaptive and dynamic assets such as cases.
- Data Model: Provides common data structures that are shared between the service projects and business assets projects. This enables proper encapsulation, promotes reuse, and reduces shortcuts. Each service project can expose its own public data model.
- Service: Includes business logic that operates your business.
Click Generate business application.
The
<business-application>.zipfile downloads, where<business-application>is the name that you entered in the Application Name box.-
Unzip the
<business-application>.zipfile. -
Open the
<business-application>/business-application-service/src/main/docker/settings.xmlfile in a text editor. Add the following repository to the
repositorieselement:<repository> <id>jboss-enterprise-repository-group</id> <name>Red Hat JBoss Enterprise Maven Repository</name> <url>https://maven.repository.redhat.com/ga/</url> <layout>default</layout> <releases> <updatePolicy>never</updatePolicy> </releases> <snapshots> <updatePolicy>daily</updatePolicy> </snapshots> </repository>Add the following plug-in repository to the
pluginRepositorieselement:<pluginRepository> <id>jboss-enterprise-repository-group</id> <name>Red Hat JBoss Enterprise Maven Repository</name> <url>https://maven.repository.redhat.com/ga/</url> <layout>default</layout> <releases> <updatePolicy>never</updatePolicy> </releases> <snapshots> <updatePolicy>daily</updatePolicy> </snapshots> </pluginRepository>Doing this adds the productized Maven repository to your business application.
Chapter 3. Business application configuration
3.1. Business application authentication and authorization
By default, business applications are secured by protecting all REST endpoints (URLs that contain /rest/). In addition, business applications have two sets of log in credentials that allow users to connect to Decision Central in development mode: the user with the ID user and password user and the kieserver user (password kieserver1!).
Both authentication and authorization is based on Spring security. Alter this security configuration for all business applications used in production environments. You can make configuration changes in the <business-application>/<business-application>-services/src/main/java/com/company/service/DefaultWebSecurityConfig.java file:
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration("kieServerSecurity")
@EnableWebSecurity
public class DefaultWebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf().disable()
.authorizeRequests()
.antMatchers("/rest/*").authenticated()
.and()
.httpBasic();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("user").password("user").roles("kie-server");
auth.inMemoryAuthentication().withUser("kieserver").password("kieserver1!").roles("kie-server");
}
}3.2. Configuring the application.properties file
After you create your business application, you can configure several components through the application.properties file to customize your application.
Prerequisites
-
You have a
<business-application>.zipfile that you created using the business application website.
Procedure
-
Unzip the
<business-application>.zipfile and navigate to the<business-application>/<business-application>-service/src/main/resourcesfolder. -
Open the
application.propertiesfile in a text editor. Configure the host, port, and path for the REST endpoints, for example:
server.address=localhost server.port=8090 cxf.path=/rest
Configure the Decision Server (
kieserver) so that it can be more easily identified, for example:kieserver.serverId=<business-application>-service kieserver.serverName=<business-application>-service kieserver.location=http://localhost:8090/rest/server kieserver.controllers=http://localhost:8080/jbpm-console/rest/controller
The following table lists the Decision Server parameters that you can configure in your business application:
Table 3.1. kieserver parameters
Parameter Values Description kieserver.serverIdstring
The ID used to identify the business application when connecting to the Decision Manager controller.
kieserver.serverNamestring
The name used to identify the business application when connecting to the Decision Manager controller. Can be the same string used for the
kieserver.serverIdparameter.kieserver.locationURL
Used by other components that use the REST API to identify the location of this server. Do not use the location as defined by
server.addressandserver.port.kieserver.controllersURLs
A comma-separated list of controller URLs.
If you selected Business Automation when you created your business application, specify which of the following components that you want to start at runtime:
Table 3.2.
kieservercapabilities parametersParameter Values Description kieserver.drools.enabledtrue, falseEnables or disables the Decision Manager component.
kieserver.dmn.enabledtrue, falseEnables or disables the Decision Model and Notation (DMN) component.
3.3. Configuring the business application with Red Hat Single Sign-On
You can use Red Hat Single Sign-On (RH SSO) to enable single sign-on between your services and to have a central place to configure and manage your users and roles.
Prerequisites
-
You have a
<business-application>.zipfile that you created using the business applications website.
Procedure
- Download and install RH SSO. For instructions, see the Red Hat Single Sign-On Getting Started Guide.
Configure RH SSO:
- Either use the default master realm or create a new realm.
-
Create the
springboot-appclient and set theAccessTypeto public. Set a valid redirect URI and web origin according to your local setup, for example:
-
Valid redirect URIs:
http://localhost:8090/* -
Web origin:
http://localhost:8090
-
Valid redirect URIs:
- Create realm roles that are used in the application.
- Create users that are used in the application and assign roles to them.
Add the following dependencies to the service project
pom.xmlfile:<dependencyManagement> <dependencies> <dependency> <groupId>org.keycloak.bom</groupId> <artifactId>keycloak-adapter-bom</artifactId> <version>${version.org.keycloak}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> .... <dependency> <groupId>org.keycloak</groupId> <artifactId>keycloak-spring-boot-starter</artifactId> </dependency>Update the
application.propertiesfile:# keycloak security setup keycloak.auth-server-url=http://localhost:8100/auth keycloak.realm=master keycloak.resource=springboot-app keycloak.public-client=true keycloak.principal-attribute=preferred_username keycloak.enable-basic-auth=true
Modify the
DefaultWebSecurityConfig.javafile to ensure that Spring Security works correctly with RH SSO:import org.keycloak.adapters.KeycloakConfigResolver; import org.keycloak.adapters.springboot.KeycloakSpringBootConfigResolver; import org.keycloak.adapters.springsecurity.authentication.KeycloakAuthenticationProvider; import org.keycloak.adapters.springsecurity.config.KeycloakWebSecurityConfigurerAdapter; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; import org.springframework.security.core.authority.mapping.SimpleAuthorityMapper; import org.springframework.security.core.session.SessionRegistryImpl; import org.springframework.security.web.authentication.session.RegisterSessionAuthenticationStrategy; import org.springframework.security.web.authentication.session.SessionAuthenticationStrategy; @Configuration("kieServerSecurity") @EnableWebSecurity public class DefaultWebSecurityConfig extends KeycloakWebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { super.configure(http); http .csrf().disable() .authorizeRequests() .anyRequest().authenticated() .and() .httpBasic(); } @Autowired public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception { KeycloakAuthenticationProvider keycloakAuthenticationProvider = keycloakAuthenticationProvider(); SimpleAuthorityMapper mapper = new SimpleAuthorityMapper(); mapper.setPrefix(""); keycloakAuthenticationProvider.setGrantedAuthoritiesMapper(mapper); auth.authenticationProvider(keycloakAuthenticationProvider); } @Bean public KeycloakConfigResolver KeycloakConfigResolver() { return new KeycloakSpringBootConfigResolver(); } @Override protected SessionAuthenticationStrategy sessionAuthenticationStrategy() { return new RegisterSessionAuthenticationStrategy(new SessionRegistryImpl()); } }
3.4. Configuring business application user group providers
With Red Hat Decision Manager, you can manage human-centric activities. To provide integration with user and group repositories, you can use two KIE API entry points:
-
UserGroupCallback: Responsible for verifying whether a user or group exists and for collecting groups for a specific user -
UserInfo: Responsible for collecting additional information about users and groups, for example email addresses and preferred language
You can configure both of these components by providing alternative code, either code provided out of the box or custom developed code.
For the UserGroupCallback component, retain the default implementation because it is based on the security context of the application. For this reason, it does not matter which backend store is used for authentication and authorisation (for example, RH-SSO). It will be automatically used as a source of information for collecting user and group information.
The UserInfo component is a separate component because it collects more advanced information.
Prerequisites
-
You have a
<business-application>.zipfile that you created using the business application website and that contains a business automation project.
Procedure
To provide an alternative implementation of
UserGroupCallback, add the following code to the Application class or a separate class annotated with@Configuration:@Bean(name = "userGroupCallback") public UserGroupCallback userGroupCallback(IdentityProvider identityProvider) throws IOException { return new MyCustomUserGroupCallback(identityProvider); }To provide an alternative implementation of
UserInfo, add the following code to the Application class or a separate class annotated with@Configuration:@Bean(name = "userInfo") public UserInfo userInfo() throws IOException { return new MyCustomUserInfo(); }
3.5. Enabling Swagger documentation
You can enable Swagger-based documentation for all endpoints available in the service project of your Red Hat Decision Manager business application.
Prerequisites
-
You have a
<business-application>.zipfile that you created using the business applications website.
Procedure
-
Unzip the
<business-application>.zipfile and navigate to the<business-application>/<business-application>-servicefolder. -
Open the service project
pom.xmlfile in a text editor. Add the following dependencies to the service project
pom.xmlfile and save the file.<dependency> <groupId>org.apache.cxf</groupId> <artifactId>cxf-rt-rs-service-description-swagger</artifactId> <version>3.2.6</version> </dependency> <dependency> <groupId>io.swagger</groupId> <artifactId>swagger-jaxrs</artifactId> <version>1.5.15</version> <exclusions> <exclusion> <groupId>javax.ws.rs</groupId> <artifactId>jsr311-api</artifactId> </exclusion> </exclusions> </dependency>To enable the Swagger UI (optional), add the following dependency to the
pom.xmlfile and save the file.<dependency> <groupId>org.webjars</groupId> <artifactId>swagger-ui</artifactId> <version>2.2.10</version> </dependency>
-
Open the
<business-application>/<business-application>-service/src/main/resources/application.propertiesfile in a text editor. Add the following line to the
application.propertiesfile to enable Swagger support:kieserver.swagger.enabled=true
After you start the business application, you can view the Swagger document at http://localhost:8090/rest/swagger.json. The complete set of endpoints is available at http://localhost:8090/rest/api-docs/?url=../swagger.json.
Chapter 4. Business application execution
By default, business applications contain a single runnable project, the service project. You can run the service project on Windows or Linux, in standalone or development (managed) mode. Standalone mode enables you to start your application without additional requirements. Applications started in development mode require Decision Central to be available as the Decision Manager controller.
4.1. Running business applications in standalone mode
Standalone (unmanaged) mode enables you to start your business application without additional requirements.
Prerequisites
-
You have a
<business-application>.zipfile that you created using the business applications website. - The business application is configured.
Procedure
-
Navigate to the
<business-application>/<business-application>-servicefolder. Enter one of the following commands:
Table 4.1. Standalone launch options
Command
Description
./launch.sh clean installLaunches in standalone mode on Linux or Unix.
./launch.bat clean installLaunches in standalone mode on Windows.
./launch.sh clean install -PmysqlLaunches in standalone mode on Linux or Unix if you have configured the application with a MySQL database.
./launch.bat clean install -PmysqlLaunches in standalone mode on Windows if you have configured the application with a MySQL database.
./launch.sh clean install -PpostgresLaunches in standalone mode on Linux or Unix if you have configured the application with a postgreSQL database.
./launch.bat clean install -PpostgresLaunches in standalone mode on Windows if you have configured the application with a PostgreSQL database.
The
clean installargument directs Maven to build a fresh installation. The projects are then built in the following order:- Data model
- Business assets
Service
The first time that you run the script, it might take a while to build the project because all dependencies of the project are downloaded. At the end of the build, the application starts.
Enter the following command to access your business application:
http://localhost:8090/
-
Enter the credentials
user/userorkieserver/kieserver1!.
4.2. Running business applications in development mode
Development (managed) mode enables developers to work on a Red Hat Decision Manager business application business assets project and dynamically deploy changes to the business application without the need to restart it. In addition, development mode provides a complete monitoring environment for business automation capabilities, for example process instances, tasks, and jobs.
Prerequisites
-
You have a
<business-application>.zipfile that contains a business assets project, that you created using the business applications website. - You configured the business application.
- Decision Central is installed and running.
Procedure
-
Navigate to the
<business-application>/<business-application>-servicefolder. Enter one of the following commands:
Table 4.2. Managed launch options
Command
Description
./launch-dev.sh clean installLaunches in development mode on Linux or Unix.
./launch-dev.bat clean installLaunches in development mode on Windows.
./launch-dev.sh clean install -PmysqlLaunches in development mode on Linux or Unix if you have configured the application with a MySQL database.
./launch-dev.bat clean install -PmysqlLaunches in development mode on Windows if you have configured the application with a MySQL database.
./launch-dev.sh clean install -PpostgresLaunches in development mode on Linux or Unix if you have configured the application with a postgreSQL database.
./launch-dev.bat clean install -PpostgresLaunches in development mode on Windows if you have configured the application with a PostgreSQL database.
The
clean installargument directs Maven to build a fresh installation. The projects are then built in the following order:- Data model
- Business assets
Service
The first time that you run the script, it might take a while to build the project because all dependencies of the project are downloaded. At the end of the build, the application starts.
Enter the following command to access your business application:
http://localhost:8090/
-
Enter the credentials
user/userorkieserver/kieserver1!. After the business application starts, it connects to the Decision Manager controller and is visible in Menu → Deploy → Execution Servers in Decision Central.
Chapter 5. Importing business assets projects into and deploying from Decision Central
You can import a business assets project that is part of a Red Hat Decision Manager business application into Decision Central and then deploy that project to a business application.
Prerequistes
- You have a business application project running in development mode.
- Red Hat Decision Manager Decision Central is installed.
Procedure
-
Navigate to the
<business-application>/<business-application>-kjarfolder. Execute the following following commands to initialize the Git repository for your project:
$ git init $ git add -A $ git commit -m "Initial project structure"
- Log in to Decision Central and go to Menu → Design → Projects.
Select Import Project and enter following URL:
file:///<business-application-path>/<business-application-name>-kjar
- Click Import and confirm the project to be imported.
- After the business assets project is imported into Decision Central, open the project and click Add Assets to add assets such as rules and decision tables to your business assets project.
- Click Deploy on your project page to deploy your project to a running business application.
- To verify the deployment, go to Menu → Deploy → Execution Servers.
Appendix A. Versioning information
Documentation last updated on Friday, June 05, 2020.