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