Establishing a Connection
Creating a JDBC Data Source
You can create a JDBC data source to connect from your Java application. Creating a JDBC data source based on the CData JDBC Driver for ServiceNow consists of three basic steps:
- Add the driver JAR file to the classpath. The JAR file is located in the lib subfolder of the installation directory. Note that the .lic file must be located in the same folder as the JAR file.
- Provide the driver class. For example:
cdata.jdbc.servicenow.ServiceNowDriver
- Provide the JDBC URL. For example:
jdbc:servicenow:InitiateOAuth=GETANDREFRESH;OAuthClientId=MyClientId;OAuthClientSecret=MyClientSecret;User=MyUser;Password=MyPassword;Url=https://MyInstance12345.service-now.com/; or jdbc:cdata:servicenow:InitiateOAuth=GETANDREFRESH;OAuthClientId=MyClientId;OAuthClientSecret=MyClientSecret;User=MyUser;Password=MyPassword;Url=https://MyInstance12345.service-now.com/;
The second format above can be used whenever there is a conflict in your application between drivers using the same URL format to ensure you are using the CData driver. The URL must start with either "jdbc:servicenow:" or "jdbc:cdata:servicenow:" and can include any of the connection properties in name-value pairs separated with semicolons.
Connecting to ServiceNow
Before you can connect to data, you will need to ensure the authenticating user has the following permissions assigned at minimum, required for listing metadata. Before you can do this, the administrator of the account must elevate their role by navigating to User menu -> Elevate Roles -> check the security_admin box -> OK. For the tables listed below, the user must have both row-level permission, such as sys_db_object and sys_glide_object, as well as field-level permission, such as sys_db_object.* and sys_glide_object.*. For additional tables which the user wishes to access, they must have at least row-level permission.
The connection property Url is a required property on all connections.
READ sys_db_object
Access to sys_db_object is required to connect to data. You can enable access to this as follows:
- Navigate to the System Security -> Access Controls (ACL). Select New to create an access control object.
- For Type, select record.
- For Operation, select read.
- For Name, select Table [sys_db_object] in the first drop-down and --None-- in the second drop-down.
- In the Requires role section, double-click the text box that says Insert a new row.... Search for and select your desired role.
- Click Submit to create the ACL object.
- Assign the role which has the created ACL to the authenticating user. To do this, navigate to User Administration > Users > Select authenticating user > Roles > Edit... > add your role from collection.
READ sys_glide_object
Access to the sys_glide_object is required for certain ServiceNow table metadata. To enable access to this repeat the above procedure, but select Field class [sys_glide_object] for the ACL's Name in Step 4.
READ sys_dictionary
Access to sys_dictionary is required to retrieve schema information from ServiceNow. You can enable access to this by navigating to User Administration > Users > Select authenticating user > Roles > Edit... > add "personalize_dictionary" role from collection.
Authenticating to ServiceNow
Basic
In order to authenticate using Basic Authentication you will need to provide your ServiceNow User and Password.
After setting the following connection properties, you are ready to connect:
- AuthScheme: Set this to BASIC.
- User: Set this to your username.
- Password: Set this to your password.
- Url: Set this to the base URL of your ServiceNow instance site. For example: https://MyInstance12345.service-now.com/.
- InitiateOAuth: Set this to OFF to avoid entering the OAuth Authorization process.
Using OAuth
ServiceNow uses the OAuth 2.0 authentication standard. To authenticate using OAuth, you will need to register an OAuth app with ServiceNow to obtain the OAuthClientId and OAuthClientSecret. In addition to the OAuth values, you will need to specify the Url, User, and Password.
For more information about connecting via OAuth authentication, refer to our Using OAuth Authentication guide.
ADFS
Set the AuthScheme to ADFS. The following connection properties need to be set:
- User: Set this to your ADFS username.
- Password: Set this to your ADFS password.
- SSOLoginURL: Set this to the login URL used by the SSO provider.
The following SSOProperties are needed to authenticate to ADFS:
- RelyingParty: This attribute is the value of the Relying Party Identifier on the ADFS server for ServiceNow.
AuthScheme=ADFS;User=username;Password=password;SSOLoginURL='https://sts.company.com';SSOProperties='RelyingParty=https://saml.service-now.com';Url=https://MyInstance12345.service-now.com/;
ADFS Integrated
To use the ADFS Integrated flow, specify the SSOLoginURL and leave the username and password empty.
Okta
Set the AuthScheme to Okta. The following connection properties are used to authenticate through Okta:
- User: Set to your Okta user.
- Password: Set to your Okta password.
- SSOLoginURL: Set to the login URL used by the SSO provider.
- using a trusted application or proxy that overrides the Okta client request
- configuring MFA
then you need to use combinations of SSOProperties input parameters to authenticate using Okta. Otherwise, you do not need to set any of these values.
In SSOProperties when required, set these input parameters:
- APIToken: When authenticating a user via a trusted application or proxy that overrides the Okta client request context, set this to the API Token the customer created from the Okta organization.
- MFAType: Set this if you have configured the MFA flow. Currently we support the following types: OktaVerify, Email, and SMS.
- MFAPassCode: Set this only if you have configured the MFA flow. If you set this to empty or an invalid value, the driver issues a one-time password challenge to your device or email. After the passcode is received, reopen the connection where the retrieved one-time password value is set to the MFAPassCode connection property.
- MFARememberDevice: Okta supports remembering devices when MFA is required. If remembering devices is allowed according to the configured authentication policies, the driver sends a device token to extend MFA authentication lifetime. This property is, by default, set to True. Set this to False only if you do not want MFA to be remembered.
Example connection string:
AuthScheme=Okta;SSOLoginURL='https://example.okta.com/home/appType/0bg4ivz6cJRZgCz5d6/46';User=oktaUserName;Password=oktaPassword;Url=https://MyInstance12345.service-now.com/;
OneLogin
Set the AuthScheme to OneLogin. The following connection properties are used to connect to OneLogin:
- User: Set this to the OneLogin user.
- Password: Set this to OneLogin password for the user.
- OAuthClientId: Set to the OAuthClientId, which can be obtained by selecting Developers > API Credentials > Credential > ClientId.
- OAuthClientSecret: Set to the OAuthClientSecret, which can be obtained by selecting Developers > API Credentials > Credential > ClientSecret.
- Subdomain: Set to the subdomain of the OneLogin user accessing the SSO app. For example, if your OneLogin URL is splinkly.onelogin.com, enter splinkly as the subdomain value.
- AppId: Set to the Id of the SSO app.
- Region (optional): Set to the region your OneLogin account resides in. The OneLogin API operates in multiple regions and this property is used to find the correct domain. It can take one of the following values:
- US (default)
- EU
The following is an example connection string:
The following connection string uses an API key to connect to OneLogin:
AuthScheme=OneLogin;User=OneLoginUserName;Password=OneLoginPassword;SSOProperties='OAuthClientID=3fc8394584f153ce3b7924d9cd4f686443a52b;OAuthClientSecret=ca9257fd5cc3277abb5818cea28c06fe9b3b285d73d06;Subdomain=OneLoginSubDomain;AppId=1433920';Url=https://MyInstance12345.service-now.com/;
PingFederate
Set the AuthScheme to PingFederate. The following connection properties need to be set:
- User: Set this to the PingFederate user.
- Password: Set this to PingFederate password for the user.
- SSOLoginURL: Set this to the login url used by the SSO provider.
- AuthScheme (optional): The authorization scheme to be used for the IdP endpoint. The allowed values for this IdP are None or Basic.
- SSLClientCert
- SSLClientCertType
- SSLClientCertSubject
- SSLClientCertPassword
AuthScheme=PingFederate;URL='https://dev103586.service-now.com';SSOLoginUrl='https://mycustomserver.com:9033/idp/sts.wst';User=admin;Password=PassValue123;