AMConfig.js revision b5418ee91771dec2a444b300d9ba32f9673fbc2b
2976N/A/**
2976N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2976N/A *
2976N/A * Copyright (c) 2011-2015 ForgeRock AS. All rights reserved.
2976N/A *
2976N/A * The contents of this file are subject to the terms
2976N/A * of the Common Development and Distribution License
2976N/A * (the License). You may not use this file except in
2976N/A * compliance with the License.
2976N/A *
2976N/A * You can obtain a copy of the License at
2976N/A * http://forgerock.org/license/CDDLv1.0.html
2976N/A * See the License for the specific language governing
2976N/A * permission and limitations under the License.
2976N/A *
2976N/A * When distributing Covered Code, include this CDDL
2976N/A * Header Notice in each file and include the License file
2976N/A * at http://forgerock.org/license/CDDLv1.0.html
2976N/A * If applicable, add the following below the CDDL Header,
2976N/A * with the fields enclosed by brackets [] replaced by
2976N/A * your own identifying information:
2976N/A * "Portions Copyrighted [year] [name of copyright owner]"
2976N/A */
2976N/A
5022N/A/*global define, window */
6238N/Adefine("config/process/AMConfig", [
2976N/A "jquery",
2976N/A "org/forgerock/openam/ui/common/util/Constants",
2976N/A "org/forgerock/commons/ui/common/main/EventManager",
2976N/A 'org/forgerock/openam/ui/admin/delegates/SMSGlobalDelegate',
2976N/A "org/forgerock/commons/ui/common/util/UIUtils"
3824N/A], function ($, Constants, EventManager, SMSGlobalDelegate, UIUtils) {
2976N/A var obj = [
2976N/A {
2976N/A startEvent: Constants.EVENT_LOGOUT,
2976N/A description: "used to override common logout event",
2976N/A override: true,
2976N/A dependencies: [
2976N/A "org/forgerock/commons/ui/common/main/Router",
2976N/A "org/forgerock/commons/ui/common/main/Configuration",
6238N/A "org/forgerock/commons/ui/common/main/SessionManager"
2976N/A ],
2976N/A processDescription: function (event, router, conf, sessionManager) {
2976N/A var argsURLFragment = event ? (event.args ? event.args[0] : '') : '',
2976N/A urlParams = UIUtils.convertQueryParametersToJSON(argsURLFragment),
3824N/A gotoURL = urlParams.goto;
3824N/A
3824N/A sessionManager.logout(function () {
3824N/A conf.setProperty('loggedUser', null);
3824N/A EventManager.sendEvent(Constants.EVENT_AUTHENTICATION_DATA_CHANGED, { anonymousMode: true});
5728N/A delete conf.gotoURL;
3842N/A if (gotoURL) {
3842N/A UIUtils.setUrl(decodeURIComponent(gotoURL));
3824N/A } else {
3842N/A EventManager.sendEvent(Constants.EVENT_CHANGE_VIEW, {route: router.configuration.routes.loggedOut });
2976N/A }
2976N/A }, function () {
2976N/A conf.setProperty('loggedUser', null);
6238N/A EventManager.sendEvent(Constants.EVENT_AUTHENTICATION_DATA_CHANGED, { anonymousMode: true});
6251N/A EventManager.sendEvent(Constants.EVENT_DISPLAY_MESSAGE_REQUEST, "unauthorized");
6251N/A if (gotoURL) {
6251N/A UIUtils.setUrl(decodeURIComponent(gotoURL));
6251N/A } else {
6258N/A EventManager.sendEvent(Constants.EVENT_CHANGE_VIEW, {route: router.configuration.routes.login });
4287N/A }
3824N/A });
6251N/A }
6251N/A },
3824N/A {
2976N/A startEvent: Constants.EVENT_INVALID_REALM,
2976N/A override: true,
2976N/A dependencies: [
2976N/A "org/forgerock/commons/ui/common/main/Router",
2976N/A "org/forgerock/commons/ui/common/main/Configuration"
2976N/A ],
2976N/A processDescription: function (event, router, conf) {
6238N/A if (event.error.responseJSON.message.indexOf('Invalid realm') > -1) {
2976N/A if (conf.baseTemplate) {
2976N/A EventManager.sendEvent(Constants.EVENT_DISPLAY_MESSAGE_REQUEST, "invalidRealm");
2976N/A } else {
2976N/A router.navigate('login', {trigger: true});
2976N/A EventManager.sendEvent(Constants.EVENT_DISPLAY_MESSAGE_REQUEST, "invalidRealm");
2976N/A }
2976N/A }
2976N/A }
2976N/A },
6238N/A {
5022N/A startEvent: Constants.EVENT_SHOW_CONFIRM_PASSWORD_DIALOG,
3824N/A description: "",
5636N/A dependencies: [
2976N/A "org/forgerock/commons/ui/user/profile/ConfirmPasswordDialog"
2976N/A ],
2976N/A processDescription: function (event, ConfirmPasswordDialog) {
2976N/A ConfirmPasswordDialog.show();
5022N/A }
5636N/A },
5636N/A {
5636N/A startEvent: Constants.EVENT_SHOW_CHANGE_SECURITY_DIALOG,
5636N/A override: true,
5636N/A dependencies: [
5636N/A "org/forgerock/openam/ui/user/profile/ChangeSecurityDataDialog"
5636N/A ],
5636N/A processDescription: function (event, ChangeSecurityDataDialog) {
2976N/A ChangeSecurityDataDialog.show(event);
2976N/A }
5636N/A },
5636N/A {
5636N/A startEvent: Constants.EVENT_ADD_NEW_REALM_DIALOG,
5636N/A override: true,
5636N/A dependencies: [
5636N/A "org/forgerock/commons/ui/common/main/Router",
5636N/A "org/forgerock/openam/ui/admin/views/realms/CreateUpdateRealmDialog",
5636N/A "org/forgerock/openam/ui/admin/views/realms/RealmsListView"
4915N/A ],
4915N/A processDescription: function (event, Router, CreateUpdateRealmDialog, RealmsListView) {
5636N/A Router.routeTo(Router.configuration.routes.realms, {
2976N/A args: [],
2976N/A trigger: true
4915N/A });
4915N/A
4915N/A CreateUpdateRealmDialog.show({
5636N/A callback : function(){
4915N/A RealmsListView.render();
4915N/A }
2976N/A });
2976N/A }
2976N/A },
5636N/A {
2976N/A startEvent: Constants.EVENT_RETURN_TO_AM_CONSOLE,
2976N/A description: "",
2976N/A dependencies: [
4915N/A "org/forgerock/commons/ui/common/main/Configuration"
2976N/A ],
5636N/A processDescription: function (event, conf) {
2976N/A var subRealm = conf.globalData.auth.subRealm || "/";
2976N/A window.location.href = "/" + Constants.context + "/realm/RMRealm?RMRealm.tblDataActionHref=" + encodeURIComponent(subRealm);
2976N/A }
4261N/A },
5224N/A {
2976N/A startEvent: Constants.EVENT_AUTHENTICATED,
2976N/A description: "",
5636N/A dependencies: [
5218N/A "underscore",
4261N/A "org/forgerock/commons/ui/common/main/Configuration",
2976N/A "org/forgerock/commons/ui/common/components/Navigation"
4261N/A ],
4261N/A processDescription: function (event, _, Configuration, Navigation) {
2976N/A if (_.contains(Configuration.loggedUser.roles, 'ui-admin')) {
3824N/A Navigation.configuration.links.admin.urls.realms.urls.push({
2976N/A 'url': '#realms/' + encodeURIComponent('/'),
2976N/A 'name': $.t('console.common.topLevelRealm'),
2976N/A 'cssClass': 'dropdown-sub'
2976N/A }, {
6238N/A 'url': '#realms',
3007N/A 'name': $.t('config.AppConfiguration.Navigation.links.realms.viewAll'),
2976N/A 'cssClass': 'dropdown-sub'
2976N/A });
2976N/A
2976N/A SMSGlobalDelegate.realms.all().done(function (data) {
2976N/A var urls = Navigation.configuration.links.admin.urls.realms.urls,
5636N/A realms = [];
5636N/A
5636N/A _.forEach(data.result, function (realm) {
3449N/A if (realm.active === true && realm.path !== '/' && realms.length < 2) {
3449N/A realms.push({
3449N/A 'url': '#realms/' + encodeURIComponent(realm.path),
6238N/A 'name': realm.name,
2976N/A 'cssClass': 'dropdown-sub'
5636N/A });
5636N/A }
5636N/A });
5636N/A
5636N/A urls.splice.apply(urls, [-1, 0].concat(realms));
2976N/A
5636N/A Navigation.reload();
2976N/A });
4261N/A
5636N/A Navigation.reload();
5224N/A }
2976N/A }
2976N/A }
5636N/A
5218N/A ];
4261N/A return obj;
2976N/A});
4261N/A