CustomizerScript.groovy revision 37314e141b6bbe540ce20aab2d651f82cc865a24
24df09922f68ca6b53d3b8052e589d3b790f7c17vboxsync/*
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync *
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * Copyright (c) 2014 ForgeRock AS. All Rights Reserved
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync *
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * The contents of this file are subject to the terms
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * of the Common Development and Distribution License
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * (the License). You may not use this file except in
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * compliance with the License.
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync *
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * You can obtain a copy of the License at
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * http://forgerock.org/license/CDDLv1.0.html
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * See the License for the specific language governing
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * permission and limitations under the License.
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync *
24df09922f68ca6b53d3b8052e589d3b790f7c17vboxsync * When distributing Covered Code, include this CDDL
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * Header Notice in each file and include the License file
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * at http://forgerock.org/license/CDDLv1.0.html
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * If applicable, add the following below the CDDL Header,
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * with the fields enclosed by brackets [] replaced by
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * your own identifying information:
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync * "Portions Copyrighted [year] [name of copyright owner]"
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync */
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsyncimport AzureADOAuth2HttpClientFactory
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsyncimport org.apache.http.auth.UsernamePasswordCredentials
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsyncimport org.apache.olingo.client.api.v3.ODataClient
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsyncimport org.apache.olingo.client.core.ODataClientFactory
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsyncimport org.forgerock.openicf.misc.scriptedcommon.ScriptedConfiguration
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsyncimport org.identityconnectors.common.logging.Log
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsyncdef configuration = configuration as ScriptedConfiguration
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsyncdef log = log as Log
24df09922f68ca6b53d3b8052e589d3b790f7c17vboxsync
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsyncdef oauth2 = configuration.getPropertyBag().get("oauth2") as ConfigObject
24df09922f68ca6b53d3b8052e589d3b790f7c17vboxsync
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsyncfinal AzureADOAuth2HttpClientFactory oauth2HCF = new AzureADOAuth2HttpClientFactory(
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync oauth2.get("authority"),
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync oauth2.get("clientId"),
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync oauth2.get("clientSecret"),
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync oauth2.get("redirectURI"),
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync oauth2.get("resourceURI"),
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync new UsernamePasswordCredentials(
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync oauth2.get("username"),
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync oauth2.get("password")));
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync
5f9dfb422a6ed57822f9c0cb94fa7df8d24acc9bvboxsync//final ODataClient client = ODataClientFactory.getEdmEnabledV3("https://graph.windows.net/contoso.onmicrosoft.com/");
final ODataClient client = ODataClientFactory.getEdmEnabledV3(configuration.getPropertyBag().get("graphServiceUrl") as String)
client.getConfiguration().setHttpClientFactory(oauth2HCF);
configuration.propertyBag.putIfAbsent("ODataClient", client)
configuration.releaseClosure = {
def c = propertyBag.get("ODataClient") as ODataClient
((Closeable) c.configuration.getHttpClientFactory()).close()
}