1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013, 2014, 2016 Synacor, Inc. 5 * 6 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: https://www.zimbra.com/license 9 * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 10 * have been added to cover use of software over a computer network and provide for limited attribution 11 * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 15 * See the License for the specific language governing rights and limitations under the License. 16 * The Original Code is Zimbra Open Source Web Client. 17 * The Initial Developer of the Original Code is Zimbra, Inc. All rights to the Original Code were 18 * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015. 19 * 20 * All portions of the code are Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2012, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 /** 25 * @overview 26 * 27 * This file defines authentication. 28 * 29 */ 30 31 /** 32 * Constructor. Use {@link execute} to construct the authentication. 33 * @class 34 * This class represents in-app authentication following the expiration of the session. 35 * 36 * @see #execute 37 */ 38 ZmAuthenticate = function() {} 39 40 ZmAuthenticate.prototype.isZmAuthenticate = true; 41 ZmAuthenticate.prototype.toString = function() { return "ZmAuthenticate"; }; 42 43 44 ZmAuthenticate._isAdmin = false; 45 46 /** 47 * Sets the authentication as "admin". 48 * 49 * @param {Boolean} isAdmin <code>true</code> if admin 50 */ 51 ZmAuthenticate.setAdmin = 52 function(isAdmin) { 53 ZmAuthenticate._isAdmin = isAdmin; 54 }; 55 56 /** 57 * Executes an authentication. 58 * 59 * @param {String} uname the username 60 * @param {String} pword the password 61 * @param {AjxCallback} callback the callback 62 */ 63 ZmAuthenticate.prototype.execute = 64 function(uname, pword, callback) { 65 var command = new ZmCsfeCommand(); 66 var soapDoc; 67 if (!ZmAuthenticate._isAdmin) { 68 soapDoc = AjxSoapDoc.create("AuthRequest", "urn:zimbraAccount"); 69 var el = soapDoc.set("account", uname); 70 el.setAttribute("by", "name"); 71 } else { 72 soapDoc = AjxSoapDoc.create("AuthRequest", "urn:zimbraAdmin", null); 73 soapDoc.set("name", uname); 74 } 75 soapDoc.set("virtualHost", location.hostname); 76 soapDoc.set("password", pword); 77 var respCallback = new AjxCallback(this, this._handleResponseExecute, callback); 78 command.invoke({soapDoc: soapDoc, noAuthToken: true, noSession: true, asyncMode: true, callback: respCallback}) 79 }; 80 81 /** 82 * @private 83 */ 84 ZmAuthenticate.prototype._handleResponseExecute = 85 function(callback, result) { 86 if (!result.isException()) { 87 ZmCsfeCommand.noAuth = false; 88 } 89 90 if (callback) { 91 callback.run(result); 92 } 93 }; 94