This Java sample application is a web app that reads directory data from the Windows Azure Active Directory Graph API, and executes queries against a demo company. The full list of capabilities for the Graph API can be found on MSDN (link below). If you would like to access your own Azure AD tenant's directory data, then the application must be configured with your own Tenant ID, Application ID and App Key - these values are stored in the app's web.xml file, then rebuild the application.
Getting started is simple! To run this sample you will need:
- JDK 7 Standard Edition (JDK7 or greater)
- Eclipse IDE
- Apache Tomcat
- An Internet connection
- An Azure subscription (a free trial is sufficient)
Every Azure subscription has an associated Azure Active Directory tenant. If you don't already have an Azure subscription, you can get a free subscription by signing up at http://wwww.windowsazure.com. All of the Azure AD features used by this sample are available free of charge.
From your shell or command line:
git clone [email protected]:AzureADSamples/WebApp-GraphAPI-Java.git
If you already have a user account in your Azure Active Directory tenant, you can skip to the next step. This sample will not work with a Microsoft account, so if you signed in to the Azure portal with a Microsoft account and have never created a user account in your directory before, you need to do that now. If you create an account and want to use it to sign-in to the Azure portal, don't forget to add the user account as a co-administrator of your Azure subscription.
- Sign in to the Azure management portal.
- Click on Active Directory in the left hand nav.
- Click the directory tenant where you wish to register the sample application.
- Click the Applications tab.
- In the drawer, click Add.
- Click "Add an application my organization is developing".
- Enter a friendly name for the application, for example "WebApp-GraphAPI-Java", select "Web Application and/or Web API", and click next.
- For the sign-on URL, enter the base URL for the sample, which is by default
https://localhost:44320
. - For the App ID URI, enter
https://<your_tenant_name>/WebApp
, replacing<your_tenant_name>
with the name of your Azure AD tenant.
Almost done! Before moving on to the next step, you need to find the Client ID of your application, and create an App Key.
- While still in the Azure portal, click the Configure tab of your application.
- Find the Client ID value and copy it to the clipboard.
- Add a key - select a key duration of either 1 year or 2 year. When you save this page, the key value will be displayed, copy and save the value in a safe location - you will need this key later to configurate the Client Credentials for this app - this key value will not be displayed again, nor retrievable by any other means, so please record it as soon as it is visible from the Azure Portal.
- Configure Permissions - under the "Permissions to other applications" section, select application "Windows Azure Active Directory" (this is the Graph API), and under the first permission column (Application Permissions), select "Read Diretory data". This sample app doesn't use delegated permssions, so the Permission under Delegated Permissions are not used.
The Sample application can be built using the Eclipse IDE, and runs under Tomcat.The following instructions are provided:
1.Download and install the JDK 7 from the Oracle Website (select the version for your development environment (e.g. Windows x64) JDK 7
-
Select JDK Standard Edition (JDK SE 7 with latest update).
-
Set a system environmental variable named JAVA_HOME and give the variable value to your java installation. Typically, this value would be something like: C:\Program Files\Java\jdk1.7.0_06
-
Download and install the Eclipse IDE for Java EE Developers from the following website (select the version for your development environment (e.g. Windows x86). Eclipse IDE for Java EE - simply execute Eclipse.exe from a command line.
-
Download and install Apache Tomcat. Apache TomCat (http://tomcat.apache.org/) You can run Apache Tomcat by clicking /bin/startup.bat script. You can also shut down apache tomcat by clicking mcat folder>/bin/shutdown.bat. When running your application from Eclipse, it can be configured to automatically start Apache Tomcat, and execute in normal or debug mode.
-
Import the project in Eclipse by: a. Starting Eclipse by clicking Eclipse.exe. b. Specify a workspace folder of your choice. c. Click File/Import/General/Existing Projects Into the workspace d. Select the root directory to the project you want to import into. e. Click Finish.
Optionally, you can also import the JavaSampleApp.war file by selecting from Eclispe: File/Import/Web/War and selecting the JavaSampleApp.war file.
- To see the opened project: a. Click Window/Show View/Project Explorer. This would show the project explorer which would show the whole project hierarchy on the left of your screen.
b. update the web.xml file - under WebContent -> WEB-INF, locate web.xml file and open it - update three init-param values in the web.xml:
i. Replace the current param-value under TenantContextId with your tenant domain name (e.g. MyTestConpany.OnMicrosoft.com). Also replace the param-value under TenantDomainName with your tenant domain name.
ii. Replace the param-value under AppPrincipalId with the client ID value that was configured from the Azure Management Portal.
iii. Replace the param-value under SymmetricKey with the Key value that was configured from the Azure Managment Portal.
Save the web.xml file.
c. Now right click on the project name, and select �Run As/Run on Server�.
d. This would prompt you to specify a server
i. Select Apache Tomcat V7.0
ii. Select the root directory of the tomcat server.
iii. Select �Always use this server�.
Coming Soon.