getSiteIdentificationForLogin.js revision 7c46e67625712e94487c8a4354fe647faf63d6ca
5394N/A/*
5394N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5394N/A *
5394N/A * Copyright (c) 2011-2012 ForgeRock AS. All rights reserved.
5394N/A *
5394N/A * The contents of this file are subject to the terms
5394N/A * of the Common Development and Distribution License
5394N/A * (the License). You may not use this file except in
5394N/A * compliance with the License.
5394N/A *
5394N/A * You can obtain a copy of the License at
5394N/A * http://forgerock.org/license/CDDLv1.0.html
5394N/A * See the License for the specific language governing
5394N/A * permission and limitations under the License.
5394N/A *
5394N/A * When distributing Covered Code, include this CDDL
5394N/A * Header Notice in each file and include the License file
5394N/A * at http://forgerock.org/license/CDDLv1.0.html
5394N/A * If applicable, add the following below the CDDL Header,
5394N/A * with the fields enclosed by brackets [] replaced by
5394N/A * your own identifying information:
5394N/A * "Portions Copyrighted [year] [name of copyright owner]"
5394N/A */
5394N/A
6238N/A/**
5394N/A * @author mbilski
5394N/A *
5394N/A * This scripts returns site image and pass phrase for specified user.
5394N/A * If such user does not exists, it returns random data due to security reasons.
5394N/A *
5394N/A * For given non-existing login it always returns the same data
5394N/A *
5394N/A * This endpoint expects these parameters:
5394N/A *
5394N/A * login userName of user
5394N/A *
5394N/A */
5394N/A
5394N/Aif (request.method !== "query") {
5394N/A throw {
5394N/A "code" : 403,
5394N/A "message" : "Access denied"
5394N/A };
5394N/A}
5394N/A
5394N/A(function () {
5394N/A
5394N/A var params = {
5394N/A "_queryId": "for-userName",
5394N/A "uid": request.params.login
5714N/A },
5394N/A passPhrases = [
5394N/A "human",
5394N/A "letter",
5394N/A "bird"
5394N/A ],
5394N/A res, ret, code;
5394N/A
5394N/A ret = openidm.query("managed/user", params);
5394N/A
5394N/A if(ret && ret.result && ret.result[0] && ret.result[0].passPhrase && ret.result[0].siteImage) {
5394N/A res = {
5394N/A "passPhrase": ret.result[0].passPhrase,
5394N/A "siteImage": ret.result[0].siteImage
5394N/A };
5394N/A } else {
5394N/A code = new java.lang.String(request.params.login).hashCode();
5394N/A code = java.lang.Math.abs(code);
5394N/A
5394N/A ret = openidm.read("/config/ui/configuration");
5394N/A
6238N/A res = {
5947N/A "siteImage": ret.configuration.siteImages[code % ret.configuration.siteImages.length],
5947N/A "passPhrase": passPhrases[code % passPhrases.length]
5947N/A };
5947N/A }
5947N/A
5947N/A return [res];
5947N/A
5947N/A}());