Subversion Repositories general

Compare Revisions

Ignore whitespace Rev 949 → Rev 950

/sun/hostadmiral/trunk/src/ak/hostadmiral/core/model/User.java
2,6 → 2,8
 
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
import java.util.StringTokenizer;
 
import ak.hostadmiral.util.Digest;
import ak.hostadmiral.util.ModelException;
18,6 → 20,7
private String password;
private User boss;
private Boolean superuser;
private Locale locale = Locale.getDefault();
private Collection loginHistory;
 
protected User()
64,7 → 67,7
public void setPassword(User editor, String password)
throws ModelException
{
if(!mayChangePassword(editor))
if(!partEditableBy(editor))
throw new ModelSecurityException();
 
if(password == null)
139,6 → 142,57
 
/**
*
* @hibernate.property column="locale"
*/
protected String getLocaleName()
{
return locale.toString();
}
 
protected void setLocaleName(String localeName)
{
String language = null;
String country = null;
 
if(localeName != null) {
StringTokenizer t = new StringTokenizer(localeName, "_");
if(t.hasMoreTokens()) language = t.nextToken();
if(t.hasMoreTokens()) country = t.nextToken();
}
 
if(language == null)
this.locale = Locale.getDefault();
else if(country == null)
this.locale = new Locale(language);
else
this.locale = new Locale(language, country);
}
 
public void setLocaleName(User editor, String localeName)
throws ModelException
{
if(!partEditableBy(editor))
throw new ModelSecurityException();
 
setLocaleName(localeName);
}
 
public Locale getLocale()
{
return locale;
}
 
public void setLocale(User editor, Locale locale)
throws ModelException
{
if(!partEditableBy(editor))
throw new ModelSecurityException();
 
this.locale = locale;
}
 
/**
*
* @hibernate.set lazy="true"
* @hibernate.collection-key column="usr"
* @hibernate.collection-one-to-many class="ak.hostadmiral.core.model.UserLogin"
166,6 → 220,14
return (getId() != null) && (u.getId() != null) && (getId().equals(u.getId()));
}
 
protected void update(User origin)
{
this.login = origin.login;
this.boss = origin.boss;
this.superuser = origin.superuser;
this.locale = origin.locale;
}
 
public int hashCode()
{
if(getId() == null)
204,7 → 266,8
return !user.equals(this) && (user.isSuperuser() || user.equals(boss));
}
 
public boolean mayChangePassword(User user)
// editor is allowed to change some additional properties
public boolean partEditableBy(User user)
{
return user.isSuperuser() || user.equals(boss) || user.equals(this);
}