📄 cmsloginnew.java
字号:
/*
* File : $Source: /usr/local/cvs/opencms/src/com/opencms/workplace/CmsLoginNew.java,v $
* Date : $Date: 2003/04/14 08:09:47 $
* Version: $Revision: 1.10 $
*
* This library is part of OpenCms -
* the Open Source Content Mananagement System
*
* Copyright (C) 2001 The OpenCms Group
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* For further information about OpenCms, please see the
* OpenCms Website: http://www.opencms.org
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.opencms.workplace;
import com.opencms.boot.I_CmsLogChannels;
import com.opencms.core.A_OpenCms;
import com.opencms.core.CmsException;
import com.opencms.core.I_CmsSession;
import com.opencms.file.CmsObject;
import com.opencms.file.CmsUser;
import com.opencms.flex.util.CmsMessages;
import com.opencms.template.A_CmsXmlContent;
import com.opencms.template.CmsCacheDirectives;
import com.opencms.template.CmsXmlTemplate;
import com.opencms.template.CmsXmlTemplateFile;
import java.util.Hashtable;
import java.util.Vector;
/**
* Template class for displaying the login screen of the OpenCms workplace.<P>
* Reads template files of the content type <code>CmsXmlWpTemplateFile</code>.
*
* @author Alexander Kandzior (a.kandzior@alkacon.com)
* @version $Revision: 1.10 $
*/
public class CmsLoginNew extends CmsXmlTemplate {
/** Debug flag, set to 9 for maximum verbosity */
private static final int DEBUG = 0;
/**
* Gets the content of the login template and processes the data input.<p>
*
* If the user has authenticated himself to the system,
* the login window is closed and the workplace is opened.
* If the login was incorrect, an error message is displayed and the login
* dialog is displayed again.
*
* @param cms request initialized CmsObject
* @param templateFile the login template file
* @param elementName not used
* @param parameters parameters of the request and the template
* @param templateSelector selector of the template tag to be displayed
* @return the processed data of the template
* @throws CmsException if something goes wrong
*/
public byte[] getContent(CmsObject cms, String templateFile,
String elementName, Hashtable parameters, String templateSelector)
throws CmsException {
if (DEBUG > 1) System.err.println("\nCmsLoginNew: Login process started");
// Initialize language and encoding
CmsXmlLanguageFile langFile = new CmsXmlLanguageFile(cms);
m_messages = langFile.getMessages();
// Ensure encoding for the login page is set correctly accoring to selected language
cms.getRequestContext().setEncoding(langFile.getEncoding());
// Check if a "logout=true" parameter is present, if so trash the session
boolean logout = (null != (String)parameters.get("logout"));
I_CmsSession session = cms.getRequestContext().getSession(false);
// Check if there already is a session
if (session != null) {
// Old session found, must be invalidated
if (logout) {
session.invalidate();
if (DEBUG > 2) System.err.println("CmsLoginNew: logout, trashed old session");
} else {
if (DEBUG > 2) System.err.println("CmsLoginNew: kept old session, no logout parameter found");
}
} else {
if (DEBUG > 2) System.err.println("CmsLoginNew: no current active session");
}
// the template to be displayed
CmsXmlTemplateFile xmlTemplateDocument = new CmsXmlTemplateFile(cms, templateFile);
String username = null;
CmsUser user;
// get user name and password
String name = (String)parameters.get("OPENCMSUSERNAME");
String password = (String)parameters.get("OPENCMSPASSWORD");
// get further startup parameters
String startTaskId = (String)parameters.get(I_CmsWpConstants.C_PARA_STARTTASKID);
String startProjectId = (String)parameters.get(I_CmsWpConstants.C_PARA_STARTPROJECTID);
if (DEBUG > 1) System.err.println("CmsLoginNew: name=" + name + " password=" + password + " task=" + startTaskId + " project=" + startProjectId);
if((name != null) && (password != null)) {
if (DEBUG > 1) System.err.println("CmsLoginNew: trying to log in");
// user and password have been submitted, try to log in the user
boolean validLogin;
try {
username = cms.loginUser(name, password);
validLogin = true;
if (DEBUG > 1) System.err.println("CmsLoginNew: cms.loginUser() successfull");
}
catch(CmsException e) {
// invalid login
validLogin = false;
if (DEBUG > 1) System.err.println("CmsLoginNew: cms.loginUser() failed");
}
if((username != null) && (username.equals(CmsObject.C_USER_GUEST))) {
// please no Guest user in the workplace
// use the same behaviour as if the access was unauthorized
validLogin = false;
if (DEBUG > 1) System.err.println("CmsLoginNew: user was guest user");
} else if ( (username != null) &&
(! cms.userInGroup(username, CmsObject.C_GROUP_USERS)) &&
(! cms.userInGroup(username, CmsObject.C_GROUP_PROJECTLEADER)) &&
(! cms.userInGroup(username, CmsObject.C_GROUP_ADMIN)) ) {
// user MUST be in at last one of the default groups "Administrators", "Users" or "Projectmanagers"
// use the same behaviour as if the access was unauthorized
validLogin = false;
if (DEBUG > 1) System.err.println("CmsLoginNew: user was not in default groups");
}
if (! validLogin) {
throw new CmsException( "[OpenCms login failed]", CmsException.C_NO_USER);
}
if (DEBUG > 0) System.err.println("CmsLoginNew: user " + username + " logged in");
// get a session for this user so that he is authentificated at the
// end of this request
session = cms.getRequestContext().getSession(true);
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && A_OpenCms.isLogging() ) {
A_OpenCms.log(C_OPENCMS_INFO, "[CmsLogin] Login user " + username);
}
// read the user data from the databsse
user = cms.readUser(username);
// set the startup project id
setStartProjectId(cms, session, startProjectId);
// set startup task view
setStartTaskId(cms, session, startTaskId);
// set the additional user preferences
Hashtable preferences = (Hashtable)user.getAdditionalInfo(C_ADDITIONAL_INFO_PREFERENCES);
// check if preferences are existing, otherwise use defaults
if(preferences == null) {
preferences = getDefaultPreferences();
}
// check of the users language setting (if he has one)
session.removeValue(C_START_LANGUAGE);
String language = CmsXmlLanguageFile.getCurrentUserLanguage(cms);
if (DEBUG > 1) System.err.println("CmsLoginNew: language: " + language);
preferences.put(C_START_LANGUAGE, language);
session.putValue(C_ADDITIONAL_INFO_PREFERENCES, preferences);
langFile = new CmsXmlLanguageFile(cms, language);
if (DEBUG > 1) System.err.println("CmsLoginNew: encoding: " + langFile.getEncoding());
cms.getRequestContext().setEncoding(langFile.getEncoding(), true);
// trigger call of "login()" JavaScript in Template on page load
xmlTemplateDocument.setData("onload", "onload='login();'");
} else if ((! logout) && ((cms.getRequestContext().currentUser()) != null) &&
(! C_USER_GUEST.equals(cms.getRequestContext().currentUser().getName())) &&
((cms.userInGroup(cms.getRequestContext().currentUser().getName(), C_GROUP_USERS)) ||
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -