Test the Java Application

In this section of the solution, you:

  • Register the sample Java web application to integrate it with Oracle Identity Cloud Service for authentication

  • Set up the application to make it use Oracle Identity Cloud Service's SDK for the Java programming language

  • Prepare, run, and test the application

Register the Java Application

To establish communication with Oracle Identity Cloud Service, the sample Java web application needs a Client ID and Secret. You also need to configure API permissions to grant to the application.

  1. In the Oracle Identity Cloud Service console, expand the Navigation Drawer, and then click Applications.
  2. In the Applications page, click Add.
  3. In the Add Application dialog box, click Confidential Application.
  4. In the Name and Description fields of the Details pane, enter SDK Web Application, and then click Next.
  5. In the Client pane, select Configure this application as a client now, and then populate the fields of this pane, as follows:
    Field Value
    Allowed Grant Types Select Client Credentials and Authorization Code.
    Allow non-HTTPS URLs Select this check box. The application works in non-HTTPS mode.
    Redirect URL http://localhost:8080/callback
    Post Logout Redirect URL http://localhost:8080
  6. In the Client pane, scroll down, select Grant the client access to Identity Cloud Service Admin APIs., enter Authenticator Client and Me in the field below, and then click Next.
  7. On the following panes, click Next until you reach the last pane. Then, click Finish.
  8. In the Application Added dialog box, note the Client ID and Client Secret values (because your Java web application needs these values to integrate with Oracle Identity Cloud Service), and then click Close.
  9. Because you want to integrate this application with Oracle Identity Cloud Service, click Activate.
  10. In the Activate Application? dialog box, click Activate Application.
  11. In the Oracle Identity Cloud Service console, click the user name at the top-right of the console, and then click Sign Out.

Set up the Java Application

Update the code of the sample Java application to make it use Oracle Identity Cloud Service's SDK for the Java programming language.

  1. Open the c:\temp\java\pom.xml file.
  2. Locate the following line of code:
    <systemPath>${basedir}/src/main/webapp/WEB-INF/lib/idcs-assert.jar</systemPath>
  3. Replace the idcs-assert.jar file with the name of the file that you noted in the Download the Java SDK section.
  4. Save your changes to the pom.xml file, and then close the file.
  5. Edit the c:\temp\java\src\main\java\sampleapp\util\ConnectionOptions.java file, update the getOptions method with the following content, and then save the file.
     public Map<String,Object> getOptions(){
            //Adding Oracle Identity Cloud Service connection parameters to the HashMap instance.
            this.options.put(IDCSTokenAssertionConfiguration.IDCS_HOST, "identity.oraclecloud.com");
            this.options.put(IDCSTokenAssertionConfiguration.IDCS_PORT, "443");
            this.options.put(IDCSTokenAssertionConfiguration.IDCS_CLIENT_ID, "123456789abcdefghij");
            this.options.put(IDCSTokenAssertionConfiguration.IDCS_CLIENT_SECRET, "abcde-12345-zyxvu-98765-qwerty");
            this.options.put(IDCSTokenAssertionConfiguration.IDCS_CLIENT_TENANT, "idcs-abcd1234");
            this.options.put(Constants.AUDIENCE_SERVICE_URL, "https://idcs-abcd1234.identity.oraclecloud.com:443");
            this.options.put(Constants.TOKEN_ISSUER, "https://identity.oraclecloud.com/");
            this.options.put(Constants.TOKEN_CLAIM_SCOPE, "urn:opc:idm:t.user.me openid");
            this.options.put("SSLEnabled", "true");
            this.options.put("redirectURL", "http://localhost:8080/callback");
            this.options.put("logoutSufix", "/oauth2/v1/userlogout");
            this.options.put(Constants.LOG_LEVEL, "DEBUG");
            this.options.put(Constants.CONSOLE_LOG, "True");
    	return this.options;
    }
    You can obtain the values for the IDCS_HOST, IDCS_PORT, and IDCS_CLIENT_TENANT parameters from the Learn About Methods and Functions topic of this solution. For the IDCS_CLIENT_ID and IDCS_CLIENT_SECRET parameter values, use the Client ID and Client Secret that Oracle Identity Cloud Service generated when you registered your Java web application.

Run the Java Application

Prepare, run, and test the sample Java web application.

  1. Launch NetBeans.
  2. Click File, and then click Open Project.
  3. Select the C:\temp\java folder, and then click Open Project.
  4. Right-click the name of the project, and then click Build.
  5. Right-click the name of the project, and then click Run.
    The application uses NetBeans' default port (8080). Make sure that your NetBeans application is configured to use this same port.
  6. After you see a new browser window open with the http://localhost:8080 URL, click Log in.
  7. In the Login page, click the red Oracle icon.
  8. In the Sign In page, sign in using your Oracle Identity Cloud Service credentials.
    After you sign in to Oracle Identity Cloud Service, the Home page of the Java web application appears. The name of the logged-in user appears at the top-right side of the page.
  9. In the left menu, click My Profile.
  10. Verify that information associated with your profile appears in the center of the page.