ResolveUsernameScript.groovy revision c8408fe9c4eb7f97ffa5b6aafcd4157afd478bc8
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
c8408fe9c4eb7f97ffa5b6aafcd4157afd478bc8Jon Branch * Copyright 2014-2015 ForgeRock AS
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * The contents of this file are subject to the terms
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * of the Common Development and Distribution License
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * (the License). You may not use this file except in
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * compliance with the License.
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * You can obtain a copy of the License at
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * See the License for the specific language governing
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * permission and limitations under the License.
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * When distributing Covered Code, include this CDDL
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * Header Notice in each file and include the License file
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * If applicable, add the following below the CDDL Header,
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * with the fields enclosed by brackets [] replaced by
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * your own identifying information:
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay * "Portions Copyrighted [year] [name of copyright owner]"
c8408fe9c4eb7f97ffa5b6aafcd4157afd478bc8Jon Branchimport org.forgerock.json.resource.ResourceResponse
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.forgerock.openicf.connectors.scriptedcrest.ScriptedCRESTConfiguration
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.forgerock.openicf.misc.scriptedcommon.OperationType
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.exceptions.UnknownUidException
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.objects.Name
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.objects.ObjectClass
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.objects.OperationOptions
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemayimport org.identityconnectors.framework.common.objects.Uid
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemaydef configuration = configuration as ScriptedCRESTConfiguration
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemaydef objectClassInfo = configuration.propertyBag[objectClass.objectClassValue];
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay QueryRequest request = Requests.newQueryRequest(objectClassInfo.resourceContainer)
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay def attributeDefinition = objectClassInfo.attributes[name]
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay request.queryFilter = QueryFilter.equalTo(String.valueOf(attributeDefinition.jsonName), username)
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay request.queryFilter = QueryFilter.equalTo(Name.NAME, username)
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay def queryResult = connection.query(new RootContext(), request, results)
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay throw new ConnectException("Multiple results 'userName' is not unique!")
c8408fe9c4eb7f97ffa5b6aafcd4157afd478bc8Jon Branch ResourceResponse r = results.get(0) as ResourceResponse;
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay throw new UnsupportedOperationException(operation.name() + " operation of type:" +
3b9de50fdf0980762d6930a49e1a0f20b61a6f6bJason Lemay objectClass.objectClassValue + " is not supported.")