onCreate-user-set-default-fields.js revision b3ec0fd47cdcf8f64148a88ac62a7a68411c5c89
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff/**
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff *
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * Copyright (c) 2011-2012 ForgeRock AS. All rights reserved.
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff *
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * The contents of this file are subject to the terms
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * of the Common Development and Distribution License
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * (the License). You may not use this file except in
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * compliance with the License.
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff *
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * You can obtain a copy of the License at
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * http://forgerock.org/license/CDDLv1.0.html
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * See the License for the specific language governing
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * permission and limitations under the License.
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff *
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * When distributing Covered Code, include this CDDL
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * Header Notice in each file and include the License file
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * at http://forgerock.org/license/CDDLv1.0.html
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * If applicable, add the following below the CDDL Header,
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * with the fields enclosed by brackets [] replaced by
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * your own identifying information:
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * "Portions Copyrighted [year] [name of copyright owner]"
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff */
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff/**
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle * @author jdabrowski
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle *
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle * This script sets default fields.
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle * It forces that user role is openidm-authorized and account status
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * is active.
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff *
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff * It is run every time new user is created.
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff */
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
894623f06f0b765163c8593164cf1cdd2f725819Chad KienleuiConfig = openidm.read("config/ui/configuration");
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienleobject.accountStatus = 'active';
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienleif(!object.roles) {
c96652ffdb237d5167f5a00a771bf3e298bdbb22Chad Kienle object.roles = 'openidm-authorized';
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff}
9abe33608be5ecedc64fcc7727c885fd04ac5558Andi Egloff
9abe33608be5ecedc64fcc7727c885fd04ac5558Andi Egloffif (!object.lastPasswordSet) {
9abe33608be5ecedc64fcc7727c885fd04ac5558Andi Egloff object.lastPasswordSet = "";
9abe33608be5ecedc64fcc7727c885fd04ac5558Andi Egloff}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
9abe33608be5ecedc64fcc7727c885fd04ac5558Andi Egloffif (!object.postalCode) {
9abe33608be5ecedc64fcc7727c885fd04ac5558Andi Egloff object.postalCode = "";
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienleif (!object.stateProvince) {
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle object.stateProvince = "";
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienleif (!object.passwordAttempts) {
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle object.passwordAttempts = "0";
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienleif (!object.lastPasswordAttempt) {
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle object.lastPasswordAttempt = (new Date()).toString();
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienleif (!object.address1) {
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle object.address1 = "";
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienleif (!object.address2) {
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle object.address2 = "";
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienleif (!object.country) {
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle object.country = "";
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienleif (!object.city) {
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle object.city = "";
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienleif (!object.givenName) {
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle object.givenName = "";
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienleif (!object.familyName) {
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle object.familyName = "";
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienleif (!object.phoneNumber) {
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle object.phoneNumber = "";
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloffif (!object.email) {
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff object.email = "";
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle}
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff//password and security answer are generated if missing just to keep those attributes filled
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloffif (!object.password) {
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff object.password = java.util.UUID.randomUUID().toString();
e37be42b67b58d254aa6a9fbbb8395390f191b84Jim Mitchener}
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienleif (uiConfig.configuration.siteIdentification) {
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle if (!object.siteImage) {
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle object.siteImage = "user.png";
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle }
894623f06f0b765163c8593164cf1cdd2f725819Chad Kienle
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle if (!object.passPhrase) {
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle object.passPhrase = "Welcome new user";
3c0bf53e0947b5bdcef79051c6e63796fac3a7fbChad Kienle }
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff}
c1bed58d59da76132e7b960e74825f038c282555Jon Branch
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloffif (uiConfig.configuration.securityQuestions) {
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff if (!object.securityAnswer) {
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff object.securityAnswer = java.util.UUID.randomUUID().toString();
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff }
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff if (!object.securityQuestion) {
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle object.securityQuestion = "1";
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle }
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle if (!object.securityAnswerAttempts) {
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle object.securityAnswerAttempts = "0";
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle }
b3c91ed9b21741200b26a3da31b64a887e629426Chad Kienle
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff if (!object.lastSecurityAnswerAttempt) {
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff object.lastSecurityAnswerAttempt = (new Date()).toString();
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff }
ad17b15404fe8bbc97c620669f32311567a9ab84Andi Egloff}