/*
* Copyright (c) 2001 - 2005 ivata limited.
* All rights reserved.
* -----------------------------------------------------------------------------
* ivata groupware may be redistributed under the GNU General Public
* License as published by the Free Software Foundation;
* version 2 of the License.
*
* These programs are free software; you can redistribute them and/or
* modify them under the terms of the GNU General Public License
* as published by the Free Software Foundation; version 2 of the License.
*
* These programs are distributed in the hope that they will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*
* See the GNU General Public License in the file LICENSE.txt for more
* details.
*
* If you would like a copy of the GNU General Public License write to
*
* Free Software Foundation, Inc.
* 59 Temple Place - Suite 330
* Boston, MA 02111-1307, USA.
*
*
* To arrange commercial support and licensing, contact ivata at
* http://www.ivata.com/contact.jsp
* -----------------------------------------------------------------------------
* $Log: UserDO.java,v $
* Revision 1.9 2005/10/14 14:31:39 colinmacleod
* Fixed bug in isMember - was only working for everyone group!
* Fixed some javadoc issues.
*
* Revision 1.8 2005/10/03 10:21:14 colinmacleod
* Fixed some style and javadoc issues.
*
* Revision 1.7 2005/10/02 14:08:58 colinmacleod
* Added/improved log4j logging.
*
* Revision 1.6 2005/09/29 13:22:47 colinmacleod
* Added read-only functionality to data object classes (with a check on each
* setter).
*
* Revision 1.5 2005/09/14 16:10:22 colinmacleod
* Removed unused local and class variables.
* Added serialVersionUID.
*
* Revision 1.4 2005/04/29 02:48:20 colinmacleod
* Data bugfixes.
* Changed primary key back to Integer.
*
* Revision 1.3 2005/04/10 20:09:48 colinmacleod
* Added new themes.
* Changed id type to String.
* Changed i tag to em and b tag to strong.
* Improved PicoContainerFactory with NanoContainer scripts.
*
* Revision 1.2 2005/04/09 17:19:57 colinmacleod
* Changed copyright text to GPL v2 explicitly.
*
* Revision 1.1.1.1 2005/03/10 17:51:42 colinmacleod
* Restructured ivata op around Hibernate/PicoContainer.
* Renamed ivata groupware.
*
* Revision 1.3 2004/12/31 19:28:04 colinmacleod
* Added override for displayValue.
*
* Revision 1.2 2004/11/03 16:10:10 colinmacleod
* Changed todo comments to TODO: all caps.
*
* Revision 1.1 2004/09/30 15:15:59 colinmacleod
* Split off addressbook elements into security subproject.
*
* Revision 1.2 2004/07/18 21:56:17 colinmacleod
* Removed person. This is a one-way relationship to make it faster.
*
* Revision 1.1 2004/07/13 19:15:26 colinmacleod
* Moved from business.addressbook to admin.security.
*
* Revision 1.3 2004/03/21 21:16:07 colinmacleod
* Shortened name to ivata op.
*
* Revision 1.2 2004/02/01 22:00:32 colinmacleod
* Added full names to author tags
*
* Revision 1.1.1.1 2004/01/27 20:57:52 colinmacleod
* Moved ivata openportal to SourceForge..
*
* Revision 1.8 2003/12/12 11:08:58 jano
* fixing aaddressbook functionaality
*
* Revision 1.7 2003/11/13 16:03:16 jano
* commitng everything to CVS
* can deploy and application is ruuning, can login into
*
* Revision 1.6 2003/11/03 11:28:24 jano
* commiting addressbook,
* tryinjg to fix deploying problem
*
* Revision 1.5 2003/10/17 12:36:12 jano
* fixing problems with building
* converting intranet -> portal
* Eclipse building
*
* Revision 1.4 2003/10/16 06:17:06 jano
* fixing comments
*
* Revision 1.3 2003/10/15 13:41:12 jano
* converting to XDoclet
*
* Revision 1.2 2003/10/15 13:18:02 colin
* fixing for XDoclet
*
* Revision 1.6 2003/09/11 13:10:48 jano
* fixing bugs with ranaming userName and with removing user from system
*
* Revision 1.5 2003/07/25 11:41:57 jano
* adding functionality for addressBook extension
*
* Revision 1.4 2003/05/01 12:13:22 jano
* tidy up names of sequeneces
*
* Revision 1.3 2003/04/09 08:52:14 jano
* handling data of removing user
*
* Revision 1.2 2003/02/25 14:38:13 colin
* implemented setModified methods on entity beans thro IvataEntityBean
* superclass
*
* Revision 1.1 2003/02/24 19:09:21 colin
* moved to business
*
* Revision 1.11 2003/02/04 17:43:45 colin
* copyright notice
*
* Revision 1.10 2003/01/09 13:32:51 jano
* I remove relationShip between user and Event
*
* Revision 1.9 2002/10/22 10:46:13 colin
* resurrected LibraryItemRight to fix problems when deleting library items
*
* Revision 1.8 2002/10/03 12:34:16 colin
* Removed LibraryItemRightBean - replaced with CMR on User
*
* Revision 1.7 2002/09/02 08:56:10 colin
* events relationship (dont know where it came from)
*
* Revision 1.6 2002/07/26 14:42:22 colin
* added a person CMR to the user
*
* Revision 1.5 2002/07/15 08:16:07 colin
* added person to create
*
* Revision 1.4 2002/07/04 12:29:28 jano
* i put readonly script to CVS and i will commit all SRC directory
*
* Revision 1.3 2002/06/28 13:15:23 colin
* first addressbook release
*
* Revision 1.2 2002/06/17 07:28:52 colin
* improved and extended javadoc documentation
* -----------------------------------------------------------------------------
*/
package com.ivata.groupware.admin.security.user;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import org.apache.log4j.Logger;
import com.ivata.groupware.admin.security.user.group.UserGroupConstants;
import com.ivata.groupware.admin.security.user.group.UserGroupDO;
import com.ivata.groupware.container.persistence.BaseDO;
import com.ivata.groupware.container.persistence.NamedDO;
/**
* <p>Each user within the system has a user name, and activation information
* such as a password. This class maintains this information.</p>
*
* @since 2002-05-05
* @author Colin MacLeod
* <a href='mailto:colin.macleod@ivata.com'>colin.macleod@ivata.com</a>
* @version $Revision: 1.9 $
*
* @hibernate.class
* table="person_user"
* @hibernate.cache
* usage="read-write"
*/
public class UserDO extends BaseDO implements NamedDO {
/**
* Logger for this class.
*/
private static final Logger logger = Logger.getLogger(UserDO.class);
/**
* Serialization version (for <code>Serializable</code> interface).
*/
private static final long serialVersionUID = 1L;
/**
* <p><code>true</code> if user was deleted, and created some data in system
* which we don't want to remove.</p>
*/
private boolean deleted;
/**
* Clear-text notes about this user. Useful to explain that the default
* administrator will always be an administrator.
*/
private String description;
/**
* <p>Find out if a user is enabled or disabled.</p>
*/
private boolean enabled;
/**
* <p>Each user is a member of several groups. By default, each user is a
* member of the group called "everyOne" </p>
*/
private Set groups = new HashSet();
/**
* <p>The user name. This name must uniquely identify the user
* within the system, and should only contain alphanumeric characters.</p>
*/
private String name;
/**
* <p>The user's password, if the authentication is not done through the
* <code>IMAP</code> webmail interface.</p>
*/
private String password;
/**
* Clear-text notes about this user. Useful to explain that the default
* administrator will always be an administrator.
*
* @return Clear text description of the user's purpose in life.
* @hibernate.property
*/
public String getDescription() {
if (logger.isDebugEnabled()) {
logger.debug("getDescription() - start");
}
if (logger.isDebugEnabled()) {
logger.debug("getDescription() - end - return value = "
+ description);
}
return description;
}
/**
* <p>If the user is deleted we will make new name.</p>
* @return userName
*/
public final String getDisplayName() {
if (logger.isDebugEnabled()) {
logger.debug("getDisplayName() - start");
}
if (isDeleted()) {
String returnString = this.getName() + " (deleted)";
if (logger.isDebugEnabled()) {
logger.debug("getDisplayName() - end - return value = "
+ returnString);
}
return returnString;
} else {
String returnString = this.getName();
if (logger.isDebugEnabled()) {
logger.debug("getDisplayName() - end - return value = "
+ returnString);
}
return returnString;
}
}
/**
* <p>
* For a user, the value displayed in a choice box is just the user name.
* </p>
*
* @see com.ivata.mask.valueobject.ValueObject#getDisplayValue()
*/
public final String getDisplayValue() {
if (logger.isDebugEnabled()) {
logger.debug("getDisplayValue() - start");
}
if (logger.isDebugEnabled()) {
logger.debug("getDisplayValue() - end - return value = " + name);
}
return name;
}
/**
* <p>Each user is a member of several groups. By default, each user is a
* member of the group called "everyOne" </p>
*
* @return All the groups this user is a member of, as a <code>List</code>
* of {@link UserGroupDO} instances.
*
* @hibernate.set
* role="user_group"
* table="user_group_member"
* @hibernate.collection-key
* column="person_user"
* @hibernate.collection-many-to-many
* class="com.ivata.groupware.admin.security.user.group.UserGroupDO"
* column="user_group"
*/
public final Set getGroups() {
if (logger.isDebugEnabled()) {
logger.debug("getGroups() - start");
}
if (logger.isDebugEnabled()) {
logger.debug("getGroups() - end - return value = " + groups);
}
return groups;
}
/**
* <p>
* Unique identifier of this data object.
* </p>
*
* NOTE: this is a hibernate one-to-one relationship with person, so we
* need no generator here...
* @return {@inheritDoc}
* @hibernate.id
* generator-class = "assigned"
*/
public final Integer getId() {
if (logger.isDebugEnabled()) {
logger.debug("getId() - start");
}
Integer returnInteger = super.getId();
if (logger.isDebugEnabled()) {
logger.debug("getId() - end - return value = " + returnInteger);
}
return returnInteger;
}
/**
* <p>Get the user name. This name must uniquely identify the user
* within the system, and should only contain alphanumeric characters.</p>
*
* @return new value for the user name. Should be unique within the intranet
* system.
*
* @hibernate.property
*/
public final String getName() {
if (logger.isDebugEnabled()) {
logger.debug("getName() - start");
}
if (logger.isDebugEnabled()) {
logger.debug("getName() - end - return value = " + name);
}
return name;
}
/**
* <p>Get the user's password, if the authentication is not done through the
* <code>IMAP</code> webmail interface.</p>
*
* @return new value of the user's password (encrypted).
*
* @hibernate.property
*/
public final String getPassword() {
if (logger.isDebugEnabled()) {
logger.debug("getPassword() - start");
}
if (logger.isDebugEnabled()) {
logger.debug("getPassword() - end - return value = " + password);
}
return password;
}
/**
* Check if the user is in a given group. This assumes the integrity of the
* groups collection!
*
* @return <code>true</code> if this user is a member of the administrator
* group.
*/
public boolean isAdministrator() {
if (logger.isDebugEnabled()) {
logger.debug("isAdministrator() - start");
}
boolean returnboolean = isMember(
UserGroupConstants.ADMINISTRATOR_GROUP);
if (logger.isDebugEnabled()) {
logger.debug("isAdministrator() - end - return value = "
+ returnboolean);
}
return returnboolean;
}
/**
* <p>If the user created data in some systems which we don't want to
* remove, she will be marked logically deleted when the order to remove
* is given. The user can no longer be used, but is marked as deleted.</p>
*
* @return <code>true</code> if this user was logically deleted
*
* @hibernate.property
*/
public boolean isDeleted() {
if (logger.isDebugEnabled()) {
logger.debug("isDeleted() - start");
}
if (logger.isDebugEnabled()) {
logger.debug("isDeleted() - end - return value = " + deleted);
}
return deleted;
}
/**
* <p>Find out if a user is enabled or disabled.</p>
*
* @return <code>true</code> if the user is currently enabled, or
* <code>false</code> if the user is prevented from accessing the
* system.
*
* TODO: change column to enabled
* @hibernate.property
* column="enable"
*/
public boolean isEnabled() {
if (logger.isDebugEnabled()) {
logger.debug("isEnabled() - start");
}
if (logger.isDebugEnabled()) {
logger.debug("isEnabled() - end - return value = " + enabled);
}
return enabled;
}
/**
* Check if the user is in a given group. This assumes the integrity of the
* groups collection!
*
* @param groupId The unique identifier of the group to check for
* membership.
* @return <code>true</code> if this user is a member of the given group.
*/
public boolean isMember(final Integer groupId) {
if (logger.isDebugEnabled()) {
logger.debug("isMember(Integer groupId = " + groupId + ") - start");
}
assert (groupId != null);
Iterator iterator = groups.iterator();
while (iterator.hasNext()) {
UserGroupDO userGroup = (UserGroupDO) iterator.next();
if (groupId.equals(userGroup.getId())) {
if (logger.isDebugEnabled()) {
logger.debug("isMember - end - return value = " + true);
}
return true;
}
}
// if it gets down here, no luck!
if (logger.isDebugEnabled()) {
logger.debug("isMember(Integer) - end - return value = " + false);
}
return false;
}
/**
* <copyDoc>Refer to {@link #isDeleted()}.</copyDoc>
*
* @param deletedParam
* <copyDoc>Refer to {@link #isDeleted()}.</copyDoc>
*/
public final void setDeleted(final boolean deletedParam) {
if (logger.isDebugEnabled()) {
logger.debug("setDeleted(boolean deleted = " + deletedParam
+ ") - start");
}
checkSetter();
this.deleted = deletedParam;
if (logger.isDebugEnabled()) {
logger.debug("setDeleted(boolean) - end");
}
}
/**
* Clear-text notes about this user. Useful to explain that the default
* administrator will always be an administrator.
*
* <copyDoc>Refer to {@link #getDescription}.</copyDoc>
* @param descriptionParam
* <copyDoc>Refer to {@link #getDescription}.</copyDoc>
*/
public void setDescription(final String descriptionParam) {
if (logger.isDebugEnabled()) {
logger.debug("setDescription(String descriptionParam = "
+ descriptionParam + ") - start");
}
description = descriptionParam;
if (logger.isDebugEnabled()) {
logger.debug("setDescription(String) - end");
}
}
/**
* <copyDoc>Refer to {@link #isEnabled()}.</copyDoc>
*
* @param enabledParam
* <copyDoc>Refer to {@link #isEnabled()}.</copyDoc>
*/
public final void setEnabled(final boolean enabledParam) {
if (logger.isDebugEnabled()) {
logger.debug("setEnabled(boolean enabled = " + enabledParam
+ ") - start");
}
checkSetter();
this.enabled = enabledParam;
if (logger.isDebugEnabled()) {
logger.debug("setEnabled(boolean) - end");
}
}
/**
* <copyDoc>Refer to {@link #getGroups()}.</copyDoc>
* @param groupsParam
* <copyDoc>Refer to {@link #getGroups()}.</copyDoc>
*/
public final void setGroups(final Set groupsParam) {
if (logger.isDebugEnabled()) {
logger.debug("setGroups(Set groups = " + groupsParam + ") - start");
}
checkSetter();
this.groups = groupsParam;
if (logger.isDebugEnabled()) {
logger.debug("setGroups(Set) - end");
}
}
/**
* <copyDoc>Refer to {@link #getName()}.</copyDoc>
*
* @param nameParam
* <copyDoc>Refer to {@link #getName()}.</copyDoc>
*/
public final void setName(final String nameParam) {
if (logger.isDebugEnabled()) {
logger.debug("setName(String name = " + nameParam + ") - start");
}
checkSetter();
this.name = nameParam;
if (logger.isDebugEnabled()) {
logger.debug("setName(String) - end");
}
}
/**
* <copyDoc>Refer to {@link #getPassword()}.</copyDoc>
*
* @param passwordParam
* <copyDoc>Refer to {@link #getPassword()}.</copyDoc>
*/
public final void setPassword(final String passwordParam) {
if (logger.isDebugEnabled()) {
logger.debug("setPassword(String password = " + passwordParam
+ ") - start");
}
checkSetter();
this.password = passwordParam;
if (logger.isDebugEnabled()) {
logger.debug("setPassword(String) - end");
}
}
}
|