page_type | description | languages | products | ||
---|---|---|---|---|---|
sample |
This sample demonstrates a Java web application authenticating via AD FS with the option to access a secured API resource. |
|
|
This sample application was modified to work with AD FS from the following sample application: https://github.com/AzureAD/azure-activedirectory-library-for-java
- The Java web application uses the Active Directory Authentication Library for Java(ADAL4J) to obtain a JWT access token from Active Directory Federation Services (AD FS):
- The access token is used as a bearer token to authenticate the user when calling a secured API (TODO)
This sample shows how to build a Java web app(confidential client) that uses OpenID Connect to sign-in users from an AD FS tenant using ADAL4J.
To run this sample, you'll need:
- Working installation of Java and Maven
- Tomcat or any other J2EE container solution
- An Internet connection
- Active Directory Federation Services (AD FS) tenant.
- A user account in your AD FS tenant.
To successfully use this sample, you need a working installation of Java and Maven.
From your shell or command line:
git clone https://[email protected]/dajon0708/SamlPoc/_git/SamlPoc
This has been completed by an administrator for the sample application.
- The Redirect URIs has been set to
https://localhost:8443/adal4jsample/secure/aad
- The Client Id and Client Secret has been generated, those values will be used in step 4.
Open web.xml
in the webapp/WEB-INF/ folder. Because we are working with ADFS we do not need to fill in the tenant name, instead Replace the "Authority" tag with the AD FS endpoint 'YOUR_CLIENT_ID' with the Application Id and 'YOUR_CLIENT_SECRET' with the key value noted.
-
$ mvn compile -DgroupId='com.microsoft.azure' -DartifactId=adal4jsample -DinteractiveMode=false
-
$ mvn package
This will generate a adal4jsample.war
file in your /targets directory. Deploy this war file using Tomcat or any other J2EE container solution.
Important You must enable HTTPS to listent to port 8433, that is the where ADFS is configured to accept callbacks from. For more information on Tomcat SSL/TLS configuration: https://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html
To deploy on Tomcat container
- Navigate to your Tomcat installation (default installation on windows is
C:\Program Files\Apache Software Foundation\Tomcat
) - copy the
adal4jsample.war
file to the Tomcat\webapps folder - Start the Tomcat server. One way to do this is by opening the Monitor Tomcat app, clicking on
start
in theGeneral
tab
This WAR will automatically be hosted at https://<yourserverhost>:<yourserverport>/adal4jsample/
Example: https://localhost:8433/adal4jsample/
- Click on "Log in using OpenID Connect" to start the process of logging in.
- Select Active Directory
- Select "Sign in using an x.503 certificate" username/password should work as well.
- Select a valid certificate and enter your pin
- You should be redirected to a page showing basic profile attributes of the user signed in, such as first name and last name.
- You should also be presented with a JWT token that can be parsed to extract custom claims.
- Optionally the access token received can be used to call a secured API, using it as a bearer token.
For more information, see ADAL4J conceptual documentation
For more information about how OAuth 2.0 protocols work in this scenario and other scenarios, see Authentication Scenarios for Azure AD.