📄 ldapuser.java
字号:
public String getUserName()
{
String tmp = null;
try
{
tmp = (String) getPerm (User.USERNAME);
if ( tmp.length() == 0 )
{
tmp = null;
}
}
catch (Exception e)
{
logger.error("getUserName():" , e);
}
return tmp;
}
/**
* Returns the first name for this user. If this is defined, then
* the user is considered logged in.
*
* @return A String with the user's first name.
*/
public String getFirstName()
{
String tmp = null;
try
{
tmp = (String) getPerm (User.FIRST_NAME);
if (tmp.length() == 0)
{
tmp = null;
}
}
catch (Exception e)
{
logger.error("getFirstName():" , e);
}
return tmp;
}
/**
* Returns the last name for this user. If this is defined, then
* the user is considered logged in.
*
* @return A String with the user's last name.
*/
public String getLastName()
{
String tmp = null;
try
{
tmp = (String) getPerm (User.LAST_NAME);
if (tmp.length() == 0) tmp = null;
}
catch (Exception e)
{
logger.error("getLastName():" , e);
}
return tmp;
}
/**
* The user is considered logged in if they have not timed out.
*
* @return Whether the user has logged in.
*/
public boolean hasLoggedIn()
{
Boolean loggedIn = getHasLoggedIn();
return (loggedIn != null && loggedIn.booleanValue());
}
/**
* Returns the email address for this user.
*
* @return A String with the user's email address.
*/
public String getEmail()
{
return (String)getPerm(User.EMAIL);
}
/**
* Increments the permanent hit counter for the user.
*/
public void incrementAccessCounter()
{
setAccessCounter(getAccessCounter() + 1);
}
/**
* Increments the session hit counter for the user.
*/
public void incrementAccessCounterForSession()
{
setAccessCounterForSession(getAccessCounterForSession() + 1);
}
/**
* Remove an object from temporary storage and return the object.
*
* @param name The name of the object to remove.
* @return An Object.
*/
public Object removeTemp(String name)
{
return tempStorage.remove(name);
}
/**
* Sets the access counter for a user, saved in perm storage.
*
* @param cnt The new count.
*/
public void setAccessCounter(int cnt)
{
setPerm(User.ACCESS_COUNTER, new Integer(cnt));
}
/**
* Sets the session access counter for a user, saved in temp
* storage.
*
* @param cnt The new count.
*/
public void setAccessCounterForSession(int cnt)
{
setTemp(User.SESSION_ACCESS_COUNTER, new Integer(cnt));
}
/**
* Sets the last access date for this User. This is the last time
* that the user object was referenced.
*/
public void setLastAccessDate()
{
lastAccessDate = new java.util.Date();
}
/**
* Sets the create date for this User. This is the time at which
* the user object was created.
*
* @param date The create date.
*/
public void setCreateDate(java.util.Date date)
{
createDate = date;
}
/**
* Set last login date/time.
*
* @param date The last login date.
*/
public void setLastLogin(java.util.Date date)
{
setPerm(User.LAST_LOGIN, date);
}
/**
* Set password.
*
* @param password The new password.
*/
public void setPassword(String password)
{
setPerm(User.PASSWORD, password);
}
/**
* Put an object into permanent storage. If the value is null,
* it will convert that to a "" because the underlying storage
* mechanism within TurbineUser is currently a Hashtable and
* null is not a valid value.
*
* @param name The object's name.
* @param value The object.
*/
public void setPerm(String name, Object value)
{
ObjectUtils.safeAddToHashtable(getPermStorage(), name, value);
}
/**
* This should only be used in the case where we want to save the
* data to the database.
*
* @param stuff A Hashtable.
*/
public void setPermStorage(Hashtable stuff)
{
this.permStorage = stuff;
}
/**
* This should only be used in the case where we want to save the
* data to the database.
*
* @return A Hashtable.
*/
public Hashtable getTempStorage()
{
if (this.tempStorage == null)
{
this.tempStorage = new Hashtable(20);
}
return this.tempStorage;
}
/**
* This should only be used in the case where we want to save the
* data to the database.
*
* @param storage A Hashtable.
*/
public void setTempStorage(Hashtable storage)
{
this.tempStorage = storage;
}
/**
* This gets whether or not someone has logged in. hasLoggedIn()
* returns this value as a boolean. This is private because you
* should use hasLoggedIn() instead.
*
* @return True if someone has logged in.
*/
private Boolean getHasLoggedIn()
{
return (Boolean) getTemp (User.HAS_LOGGED_IN);
}
/**
* This sets whether or not someone has logged in. hasLoggedIn()
* returns this value.
*
* @param value Whether someone has logged in or not.
*/
public void setHasLoggedIn (Boolean value)
{
setTemp (User.HAS_LOGGED_IN, value);
}
/**
* Put an object into temporary storage. If the value is null,
* it will convert that to a "" because the underlying storage
* mechanism within TurbineUser is currently a Hashtable and
* null is not a valid value.
*
* @param name The object's name.
* @param value The object.
*/
public void setTemp(String name, Object value)
{
ObjectUtils.safeAddToHashtable(tempStorage, name, value);
}
/**
* Sets the username for this user.
*
* @param username The user's username.
*/
public void setUserName(String username)
{
setPerm (User.USERNAME, username);
}
/**
* Sets the first name for this user.
*
* @param firstName User's first name.
*/
public void setFirstName(String firstName)
{
setPerm(User.FIRST_NAME, firstName);
}
/**
* Sets the last name for this user.
*
* @param lastName User's last name.
*/
public void setLastName(String lastName)
{
setPerm(User.LAST_NAME, lastName);
}
/**
* Sets the email address.
*
* @param address The email address.
*/
public void setEmail(String address)
{
setPerm(User.EMAIL, address);
}
/**
* This method reports whether or not the user has been confirmed
* in the system by checking the User.CONFIRM_VALUE
* column in the users record to see if it is equal to
* User.CONFIRM_DATA.
*
* @return True if the user has been confirmed.
*/
public boolean isConfirmed()
{
String value = getConfirmed();
return (value != null && value.equals(User.CONFIRM_DATA));
}
/**
* Sets the confirmation value. The value should
* be either a random string or User.CONFIRM_DATA
*
* @param value The confirmation key value.
*/
public void setConfirmed(String value)
{
String val = "";
if (value != null)
{
val = value;
}
setPerm(User.CONFIRM_VALUE, val);
}
/**
* Gets the confirmation value.
*
* @return status The confirmation value for this User
*/
public String getConfirmed()
{
return (String)getPerm(User.CONFIRM_VALUE);
}
/**
* Updates the last login date in the database.
*
* @exception Exception, a generic exception.
*/
public void updateLastLogin()
throws Exception
{
setPerm( User.LAST_LOGIN, new java.util.Date() );
}
/**
* Implement this method if you wish to be notified when the User
* has been Bound to the session.
*
* @param hsbe The HttpSessionBindingEvent.
*/
public void valueBound(HttpSessionBindingEvent hsbe)
{
}
/**
* Implement this method if you wish to be notified when the User
* has been Unbound from the session.
*
* @param hsbe The HttpSessionBindingEvent.
*/
public void valueUnbound(HttpSessionBindingEvent hsbe)
{
try
{
java.util.Date now = new java.util.Date();
if (this.hasLoggedIn())
{
if ( JetspeedResources.getBoolean("automatic.logout.save", false) )
{
JetspeedUserManagement.saveUser(this);
}
JetspeedAuthentication.logout();
}
}
catch ( Exception e )
{
logger.error("LDAPUser.valueUnbound(): " + e.getMessage(), e);
// To prevent messages being lost in case the logging system
// goes away before sessions get unbound on servlet container
// shutdown, print the stcktrace to the container's console.
ByteArrayOutputStream ostr = new ByteArrayOutputStream();
e.printStackTrace(new PrintWriter(ostr,true));
String stackTrace = ostr.toString();
System.out.println(stackTrace);
}
}
/**
* Saves this object to the data store.
*/
public void save()
throws Exception
{
if (this.isNew())
{
JetspeedUserManagement.saveUser(this);
}
else
{
JetspeedUserManagement.addUser(this);
}
}
/**
* Returns the disabled status for the user
*
* @return True when the account is disabled
*/
public boolean getDisabled()
{
boolean disabled = false;
try
{
String tmp = (String) getPerm (JetspeedUser.DISABLED);
if ( tmp != null && tmp.length() > 0 )
{
if (tmp.equalsIgnoreCase("T"))
disabled = true;
}
}
catch (Exception e)
{
logger.error("getDisabled():" , e);
}
return disabled;
}
public void setDisabled(boolean disabled)
{
setPerm(JetspeedUser.DISABLED, (disabled) ? "T" : "F");
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
public boolean isNew()
{
return isNew;
}
void setNew(boolean isNew)
{
this.isNew = isNew;
}
/**
* Returns the date of last password change
*
* @return date
*/
public Date getPasswordChanged()
{
return this.passwordChanged;
}
/**
* Sets the date of last password change
*
* @param value Date
*/
public void setPasswordChanged(Date value)
{
this.passwordChanged = value;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -