cmsuser.java
来自「找了很久才找到到源代码」· Java 代码 · 共 731 行 · 第 1/2 页
JAVA
731 行
/*
* File : $Source: /usr/local/cvs/opencms/src/org/opencms/file/CmsUser.java,v $
* Date : $Date: 2007-08-13 16:29:58 $
* Version: $Revision: 1.37 $
*
* This library is part of OpenCms -
* the Open Source Content Management System
*
* Copyright (c) 2002 - 2007 Alkacon Software GmbH (http://www.alkacon.com)
*
* 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 Alkacon Software GmbH, please see the
* company website: http://www.alkacon.com
*
* For further information about OpenCms, please see the
* project 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 org.opencms.file;
import org.opencms.db.CmsUserSettings;
import org.opencms.main.CmsException;
import org.opencms.main.CmsIllegalArgumentException;
import org.opencms.main.OpenCms;
import org.opencms.security.CmsPrincipal;
import org.opencms.security.CmsSecurityException;
import org.opencms.security.I_CmsPrincipal;
import org.opencms.util.CmsMacroResolver;
import org.opencms.util.CmsStringUtil;
import org.opencms.util.CmsUUID;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
/**
* A user principal in the OpenCms permission system.<p>
*
* A user in OpenCms is uniquely definded by its user named returned by
* <code>{@link #getName()}</code>.<p>
*
* Basic users in OpenCms are users that can access the OpenCms Workplace.
* Moreover, the user must be created by another user with the
* <code>{@link org.opencms.security.CmsRole#ACCOUNT_MANAGER}</code> role.
* These users are "content managers" that actually have write permissions in
* at last some parts of the VFS.<p>
*
* Another possibility is to have users in a 'Guests' group.
* These users do not have access to the OpenCms Workplace.
* However, an user in a 'Guests' group can be created by every user, for example
* the "Guest" user. The main use case is that these users are used for users of
* the website that can generate their own accounts, in a "please register your
* account..." scenario.
* These user accounts can then be used to build personalized web sites.<p>
*
* @author Alexander Kandzior
* @author Michael Emmerich
* @author Michael Moossen
*
* @version $Revision: 1.37 $
*
* @since 6.0.0
*
* @see CmsGroup
*/
public class CmsUser extends CmsPrincipal implements I_CmsPrincipal, Cloneable {
/** Storage for additional user information. */
private Map m_additionalInfo;
/** The creation date. */
private long m_dateCreated;
/** The email of the user. */
private String m_email;
/** The first name of this user. */
private String m_firstname;
/** Boolean flag whether the last-login timestamp of this user was modified. */
private boolean m_isTouched;
/** The last login date of this user. */
private long m_lastlogin;
/** The last name of this user. */
private String m_lastname;
/** The password of this user. */
private String m_password;
/**
* Creates a new, empty OpenCms user principal.<p>
*
* Mostly intented to be used with the <code>org.opencms.workplace.tools.accounts.A_CmsEditUserDialog</code>.<p>
*/
public CmsUser() {
this(
null,
"",
"",
"",
"",
"",
0,
I_CmsPrincipal.FLAG_ENABLED,
System.currentTimeMillis(),
Collections.singletonMap(CmsUserSettings.ADDITIONAL_INFO_DESCRIPTION, ""));
}
/**
* Creates a new OpenCms user principal.<p>
*
* @param id the unique id of the new user
* @param name the fully qualified name of the new user
* @param password the password of the user
* @param firstname the first name
* @param lastname the last name
* @param email the email address
* @param lastlogin time stamp
* @param flags flags
* @param dateCreated the creation date
* @param additionalInfo user related information
*/
public CmsUser(
CmsUUID id,
String name,
String password,
String firstname,
String lastname,
String email,
long lastlogin,
int flags,
long dateCreated,
Map additionalInfo) {
m_id = id;
m_name = name;
m_password = password;
m_firstname = firstname;
m_lastname = lastname;
m_email = email;
m_lastlogin = lastlogin;
m_flags = flags;
m_dateCreated = dateCreated;
if (additionalInfo != null) {
m_additionalInfo = new HashMap(additionalInfo);
} else {
m_additionalInfo = new HashMap();
}
if (m_additionalInfo.get(CmsUserSettings.ADDITIONAL_INFO_ADDRESS) == null) {
m_additionalInfo.put(CmsUserSettings.ADDITIONAL_INFO_ADDRESS, "");
}
if (m_additionalInfo.get(CmsUserSettings.ADDITIONAL_INFO_DESCRIPTION) == null) {
m_additionalInfo.put(CmsUserSettings.ADDITIONAL_INFO_DESCRIPTION, "");
}
}
/**
* Validates an email address.<p>
*
* That means, the parameter should only be composed by digits and standard english letters, points, underscores and exact one "At" symbol.<p>
*
* @param email the email to validate
*/
public static void checkEmail(String email) {
OpenCms.getValidationHandler().checkEmail(email);
}
/**
* Validates a zip code.<p>
*
* That means, the parameter should only be composed by digits and standard english letters.<p>
*
* @param zipcode the zipcode to validate
*/
public static void checkZipCode(String zipcode) {
OpenCms.getValidationHandler().checkZipCode(zipcode);
}
/**
* Returns the "full" name of the given user in the format <code>"{firstname} {lastname} ({username})"</code>,
* or the empty String <code>""</code> if the user is null.<p>
*
* @param user the user to get the full name from
* @return the "full" name the user
*
* @see #getFullName()
*/
public static String getFullName(CmsUser user) {
if (user == null) {
return "";
} else {
return user.getFullName();
}
}
/**
* Returns <code>true</code> if the provided user type indicates a system user.<p>
*
* @param type the user type to check
*
* @return true if the provided user type indicates a system user
*/
public static boolean isSystemUser(int type) {
return (type & 1) > 0;
}
/**
* Checks if the provided user name is a valid user name and can be used as an argument value
* for {@link #setName(String)}.<p>
*
* @param name the user name to check
*
* @throws CmsIllegalArgumentException if the check fails
*/
public void checkName(String name) throws CmsIllegalArgumentException {
OpenCms.getValidationHandler().checkUserName(name);
}
/**
* @see java.lang.Object#clone()
*/
public Object clone() {
return new CmsUser(
m_id,
m_name,
m_password,
m_firstname,
m_lastname,
m_email,
m_lastlogin,
m_flags,
m_dateCreated,
m_additionalInfo);
}
/**
* Deletes a value from this users "additional information" storage map.<p>
*
* @param key the additional user information to delete
*
* @see #getAdditionalInfo()
*/
public void deleteAdditionalInfo(String key) {
m_additionalInfo.remove(key);
}
/**
* Returns this users complete "additional information" storage map.<p>
*
* The "additional information" storage map is a simple {@link java.util.Map}
* that can be used to store any key / value pairs for the user.
* Some information parts of the users address are stored in this map
* by default.<p>
*
* @return this users complete "additional information" storage map
*/
public Map getAdditionalInfo() {
return m_additionalInfo;
}
/**
* Returns a value from this users "additional information" storage map,
* or <code>null</code> if no value for the given key is available.<p>
*
* @param key selects the value to return from the "additional information" storage map
*
* @return the selected value from this users "additional information" storage map
*
* @see #getAdditionalInfo()
*/
public Object getAdditionalInfo(String key) {
return m_additionalInfo.get(key);
}
/**
* Returns the address line of this user.<p>
*
* @return the address line of this user
*/
public String getAddress() {
return (String)getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_ADDRESS);
}
/**
* Returns the city information of this user.<p>
*
* This information is stored in the "additional information" storage map
* using the key <code>{@link CmsUserSettings#ADDITIONAL_INFO_CITY}</code>.<p>
*
* @return the city information of this user
*/
public String getCity() {
return (String)getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_CITY);
}
/**
* Returns the country information of this user.<p>
*
* This informaion is stored in the "additional information" storage map
* using the key <code>{@link CmsUserSettings#ADDITIONAL_INFO_COUNTRY}</code>.<p>
*
* @return the country information of this user
*/
public String getCountry() {
return (String)getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_COUNTRY);
}
/**
* Returns the creation date.<p>
*
* @return the creation date
*/
public long getDateCreated() {
return m_dateCreated;
}
/**
* @see org.opencms.security.CmsPrincipal#getDescription()
*/
public String getDescription() {
return (String)getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_DESCRIPTION);
}
/**
* Returns the description of this organizational unit.<p>
*
* @param locale the locale
*
* @return the description of this organizational unit
*/
public String getDescription(Locale locale) {
CmsMacroResolver macroResolver = new CmsMacroResolver();
macroResolver.setMessages(org.opencms.db.generic.Messages.get().getBundle(locale));
return macroResolver.resolveMacros((String)getAdditionalInfo(CmsUserSettings.ADDITIONAL_INFO_DESCRIPTION));
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?