1,5 → 1,6 |
package ak.hostadmiral.core.model; |
|
import java.util.Iterator; |
import java.util.Collection; |
import java.util.Collections; |
import java.util.HashSet; |
6,7 → 7,6 |
import java.util.Locale; |
import java.util.StringTokenizer; |
|
import ak.hostadmiral.util.Digest; |
import ak.hostadmiral.util.ModelException; |
import ak.hostadmiral.util.ModelSecurityException; |
|
17,8 → 17,10 |
public class User |
extends GeneralModelObject |
{ |
public static final String DEFAULT_PASSWORD_STORE = "MD5"; |
|
private String login; |
private String password; |
private Collection passwords; // Collection(PasswordStore) |
private User boss; |
private Boolean superuser; |
private Locale locale = Locale.getDefault(); |
32,11 → 34,17 |
protected User(User origin) |
{ |
super(origin); |
this.login = origin.login; |
this.password = origin.password; |
this.boss = origin.boss; |
this.login = origin.login; |
|
if(origin.passwords == null) |
this.passwords = null; |
else |
this.passwords = new HashSet(origin.passwords); |
|
this.boss = origin.boss; |
this.superuser = origin.superuser; |
this.locale = origin.locale; |
this.locale = origin.locale; |
|
if(origin.loginHistory == null) |
this.loginHistory = null; |
else |
81,20 → 89,39 |
this.login = login; |
} |
|
/** |
* |
* @hibernate.property |
*/ |
protected String getPassword() |
protected void addPasswordStore(PasswordStore ps) |
{ |
return password; |
if(passwords == null) passwords = new HashSet(); |
passwords.add(ps); |
} |
|
protected void setPassword(String password) |
protected PasswordStore getDefaultPasswordStore() |
throws ModelException |
{ |
this.password = password; |
if(passwords == null) |
throw new ModelException("No password store"); |
|
for(Iterator i = passwords.iterator(); i.hasNext(); ) { |
Object o = i.next(); |
if(!(o instanceof PasswordStore)) |
throw new ModelException("It's not a password store"); |
PasswordStore ps = (PasswordStore)o; |
if(DEFAULT_PASSWORD_STORE.equals(ps.getDigest())) |
return ps; |
} |
|
throw new ModelException("No password store for digest " + DEFAULT_PASSWORD_STORE); |
} |
|
public String getPassword(User editor) |
throws ModelException |
{ |
if(!partEditableBy(editor)) |
throw new ModelSecurityException(); |
|
return getDefaultPasswordStore().getPassword(); |
} |
|
public void setPassword(User editor, String password) |
throws ModelException |
{ |
105,20 → 132,38 |
throw new NullPointerException("Null password"); |
|
backupMe(); |
this.password = Digest.encode(password); |
|
for(Iterator i = passwords.iterator(); i.hasNext(); ) { |
Object o = i.next(); |
if(!(o instanceof PasswordStore)) |
throw new ModelException("It's not a password store"); |
((PasswordStore)o).setNewPassword(password); |
} |
} |
|
public boolean checkPassword(String password) |
throws ModelException |
{ |
if(password == null) |
throw new NullPointerException("Null password"); |
|
return checkMd5Password(Digest.encode(password)); |
return getDefaultPasswordStore().checkPassword(password); |
} |
|
public boolean checkMd5Password(String password) |
/** |
* |
* @hibernate.set cascade="all" |
* @hibernate.collection-key column="obj" |
* @hibernate.collection-one-to-many class="ak.hostadmiral.core.model.PasswordStoreAbstract" |
*/ |
protected Collection getPasswords() |
{ |
return passwords; |
} |
|
protected void setPasswords(Collection passwords) |
{ |
return this.password.equals(password); |
this.passwords = passwords; |
} |
|
/** |