Skip to main content

Example source code

There are example Java projects that use Trivore ID's SSO mechanisms. Both mechanisms have their own GitLab repository. The Management API example project can be found here, and the OpenID Connect mechanism example project can be found here.

Management API

The source code for the example implementation of an SSO target via the Management API can be downloaded from GitLab.

Use Maven to build this example. The result of the Maven build is a simple .war package that can be deployed on Apache Tomcat or Eclipse Jetty.

$ mvn clean package
# Resulting .war file is located at target/sso-example-1.0-SNAPSHOT.war

When deploying the .war file to a servlet container, you need to define the following settings.

Property nameDescriptionExample value
sso.example.configLocationLocation of the .properties file that contains settingsclasspath:sso-example.properties or file:///etc/tomcat/sso-example.properties
sso.example.api.urlTrivore ID Management API URLhttps://{your-id-server}/api/rest/v1
sso.example.api.clientIdTrivore ID Management API client ID5892346374634783124
sso.example.api.clientSecretTrivore ID Management API client secretFjw526789fsAHf1j23TH312g3u

sso.example.configLocation can be defined as (in order of preference) the environment variable SSO_EXAMPLE_CONFIG_LOCATION, a Java system property using the -D argument, or a context init parameter in web.xml. Other properties can be defined as (in order of preference) a Java system property, a properties file defined by sso.example.configLocation, or a context init parameter in web.xml. The preferred way to define these properties for Apache Tomcat on Linux is to edit /etc/tomcat/tomcat.conf and add a new line at the end:

SSO_EXAMPLE_CONFIG_LOCATION=/etc/tomcat/sso-example.properties

and then create the /etc/tomcat/sso-example.properties file with content such as:

sso.example.api.url=https://{your-id-server}/api/rest/v1
sso.example.api.clientId=5892346374634783124
sso.example.api.clientSecret=Fjw526789fsAHf1j23TH312g3u

OpenID Connect

The source code for the example implementation of an SSO target via OpenID Connect can be downloaded from GitLab.

Use Maven to build this example. The result of the Maven build is a simple .war package that can be deployed on Apache Tomcat or Eclipse Jetty.

$ mvn clean package
# Resulting .war file is located at target/openid-example-1.0-SNAPSHOT.war

When deploying the .war file to a servlet container, you need to define the following settings.

Property nameDescriptionExample value
openid.example.configLocationLocation of the .properties file that contains settingsclasspath:openid-example.properties or file:///etc/tomcat/openid-example.properties
openid.example.metadataUrlTrivore ID OpenID Connect metadata URLhttps://{your-id-server}/.well-known/openid-configuration
openid.example.redirectUrlOpenID Connect redirect URLhttps://<example-hostname>/openid-example/callback
openid.example.clientIdOpenID Connect client ID5892346374634783124
openid.example.clientSecretOpenID Connect client secretFjw526789fsAHf1j23TH312g3u
openid.example.scopeOpenID Connect scope parameter valueopenid profile

openid.example.configLocation can be defined as (in order of preference) the environment variable OPENID_EXAMPLE_CONFIG_LOCATION, a Java system property using the -D argument, or a context init parameter in web.xml. Other properties can be defined as (in order of preference) a Java system property, a properties file defined by openid.example.configLocation, or a context init parameter in web.xml. The preferred way to define these properties for Apache Tomcat on Linux is to edit /etc/tomcat/tomcat.conf and add a new line at the end:

OPENID_EXAMPLE_CONFIG_LOCATION=/etc/tomcat/openid-example.properties

and then create the /etc/tomcat/openid-example.properties file with content such as:

openid.example.metadataUrl=https://id-server.example.com/.well-known/openid-configuration
openid.example.redirectUrl=https://my-client.example.com/openid-example/callback
openid.example.clientId=5892346374634783124
openid.example.clientSecret=Fjw526789fsAHf1j23TH312g3u
openid.example.scope=openid profile