Discover how a bimodal integration strategy can address the major data management challenges facing your organization today.
Get the Report →Integrate with Okta Data using Apache Camel2
Create a simple Java app that uses Apache Camel routing and the CData JDBC Driver to copy Okta data to a JSON file on disk.
Apache Camel is an open source integration framework that allows you to integrate various systems consuming or producing data. When paired with the CData JDBC Driver for Okta, you can write Java apps that use Camel routes that integrate with live Okta data. This article walks through creating an app in NetBeans that connects, queries, and routes Okta data to a JSON file.
With built-in optimized data processing, the CData JDBC Driver offers unmatched performance for interacting with live Okta data. When you issue complex SQL queries to Okta, the driver pushes supported SQL operations, like filters and aggregations, directly to Okta and utilizes the embedded SQL engine to process unsupported operations client-side (often SQL functions and JOIN operations). Its built-in dynamic metadata querying allows you to work with and analyze Okta data using native data types.
Creating A New Maven/Java Project
Follow the steps below to create a new Java project and add the appropriate dependencies:
- Open NetBeans and create a new project.
- Select Maven from the categories list and Java Application from the projects list, then click Next.
- Name the project (and adjust any other properties) and click Finish.
- In the source package, create a new Java class (we used App.java for this article) and add the main method to the class.
Adding Project Dependencies
With the project created, we can start adding the dependencies needed to work with live Okta data from our App. If you have not already done so, install Maven in your environment, as it is required to add the JAR file for the CData JDBC Driver to your project.
Installing the CData JDBC Driver for Okta with Maven
- Download the CData JDBC Driver for Okta installer, unzip the package, and run the JAR file to install the driver.
- Use Maven to install the JDBC Driver as a connector.
mvn install:install-file -Dfile="C:\Program Files\CData[product_name] 2019\lib\cdata.jdbc.okta.jar" -DgroupId="org.cdata.connectors" -DartifactId="cdata-okta-connector" -Dversion="19" -Dpackaging=jar
Once the JDBC Driver is installed, we can add dependencies to our project. To add a dependency, you can either edit the pom.xml file or right-click the dependencies folder and click Add Dependency. The properties for each dependency follow, but you can search through the available libraries by typing the name of the dependency in the Query box in the Add Dependency wizard.
Required Dependencies
Dependency | Group ID | Artifact ID | Version |
---|---|---|---|
camel-core | org.apache.camel | camel-core | 3.0.0 |
camel-jackson | org.apache.camel | camel-jackson | 3.0.0 |
camel-jdbc | org.apache.camel | camel-jdbc | 3.0.0 |
camel-jsonpath | org.apache.camel | camel-jsonpath | 3.0.0 |
cdata-okta-connector | org.cdata.connectors | cdata-salesforce-connector | 19 |
commons-dbcp2 | org.apache.commons | commons-dbcp2 | 2.7.0 |
slf4j-log4j12 | org.slf4j | slf4j-log4j12 | 1.7.30 |
log4j | org.apache.logging.log4j | log4j | 2.12.1 |
Accessing Okta Data in Java Apps with Camel
After adding the required dependencies, we can use the Java DSL (Domain Specific Language) to create routes with access to live Okta data. Code snippets follow. Download the sample project (zip file) to follow along (make note of the TODO comments).
Start by importing the necessary classes into our main class.
import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.support.SimpleRegistry; import org.apache.commons.dbcp2.BasicDataSource; import org.apache.log4j.BasicConfigurator;
Then in the main method, we configure logging, create a new BasicDataSource and add it to the registry, create a new CamelContext, and finally add a route to the context. In this sample, we route Okta data to a JSON file.
Configure Logging
BasicConfigurator.configure();
Create a BasicDataSource
Create a BasicDataSource and set the driver class name (cdata.jdbc.salesforce.SalesforceDriver) and URL (using the required connection properties).
To connect to Okta, set the Domain connection string property to your Okta domain.
You will use OAuth to authenticate with Okta, so you need to create a custom OAuth application.
Creating a Custom OAuth Application
From your Okta account:
- Sign in to your Okta developer edition organization with your administrator account.
- In the Admin Console, go to Applications > Applications.
- Click Create App Integration.
- For the Sign-in method, select OIDC - OpenID Connect.
- For Application type, choose Web Application.
- Enter a name for your custom application.
- Set the Grant Type to Authorization Code. If you want the token to be automatically refreshed, also check Refresh Token.
- Set the callback URL:
- For desktop applications and headless machines, use http://localhost:33333 or another port number of your choice. The URI you set here becomes the CallbackURL property.
- For web applications, set the callback URL to a trusted redirect URL. This URL is the web location the user returns to with the token that verifies that your application has been granted access.
- In the Assignments section, either select Limit access to selected groups and add a group, or skip group assignment for now.
- Save the OAuth application.
- The application's Client Id and Client Secret are displayed on the application's General tab. Record these for future use. You will use the Client Id to set the OAuthClientId and the Client Secret to set the OAuthClientSecret.
- Check the Assignments tab to confirm that all users who must access the application are assigned to the application.
- On the Okta API Scopes tab, select the scopes you wish to grant to the OAuth application. These scopes determine the data that the app has permission to read, so a scope for a particular view must be granted for the driver to have permission to query that view. To confirm the scopes required for each view, see the view-specific pages in Data Model < Views in the Help documentation.
BasicDataSource basic = new BasicDataSource(); basic.setDriverClassName("cdata.jdbc.okta.OktaDriver"); basic.setUrl("jdbc:okta:Domain=dev-44876464.okta.com;InitiateOAuth=GETANDREFRESH");
The CData JDBC Driver includes a built-in connection string designer to help you configure the connection URL.
Built-in Connection String Designer
For assistance in constructing the JDBC URL, use the connection string designer built into the Okta JDBC Driver. Either double-click the JAR file or execute the jar file from the command line.
java -jar cdata.jdbc.okta.jar
Fill in the connection properties and copy the connection string to the clipboard.
Add the BasicDataSource to the Registry and Create a CamelContext
SimpleRegistry reg = new SimpleRegistry(); reg.bind("myDataSource", basic); CamelContext context = new DefaultCamelContext(reg);
Add Routing to the CamelContext
The routing below uses a timer component to run one time and passes a SQL query to the JDBC Driver. The results are marshaled as JSON (and formatted for pretty print) and passed to a file component to write to disk as a JSON file.
context.addRoutes(new RouteBuilder() { @Override public void configure() { from("timer://foo?repeatCount=1") .setBody(constant("SELECT * FROM Account LIMIT 10")) .to("jdbc:myDataSource") .marshal().json(true) .to("file:C:\\Users\\USER\\Documents?fileName=account.json"); } });
Managing the CamelContext Lifecycle
With the route defined, start the CamelContext to begin the lifecycle. In this example, we wait 10 seconds and then shut down the context.
context.start(); Thread.sleep(10000); context.stop();
Free Trial, Sample Project & Technical Support
Now, you have a working Java application that uses Camel to route data from Okta to a JSON file. Download a free, 30-day trial of the CData JDBC Driver for Okta and the sample project (make note of the TODO comments) and start working with your live Okta data in Apache Camel. Reach out to our Support Team if you have any questions.