001: package com.jat.business;
002:
003: import com.jat.business.authentication.AuthenticationException;
004: import com.jat.business.privileges.PrivilegeFactory;
005: import com.jat.business.privileges.PrivilegeList;
006: import com.jat.core.log.LogManager;
007:
008: /**
009: * <p>Title: JAT</p>
010: * <p>Description: </p>
011: * <p>Copyright: Copyright (c) 2004 -2005 Stefano Fratini (stefano.fratini@gmail.com)</p>
012: * <p>Distributed under the terms of the GNU Lesser General Public License, v2.1 or later</p>
013: * @author stf
014: * @version 1.2
015: * @since 1.0
016: */
017:
018: public abstract class JatUser extends BusinessObject {
019:
020: public final static String JAT_USER = "JAT_USER";
021:
022: public static String FIRST_NAME = "FIRST_NAME";
023: public static String LAST_NAME = "LAST_NAME";
024: public static String USERNAME = "USERNAME";
025: public static String PASSWORD = "PASSWORD";
026: public static String PROFILE = "PROFILE";
027:
028: public JatUser(String dataSourceName)
029: throws AuthenticationException {
030: super (dataSourceName);
031: try {
032: } catch (Exception ex) {
033: LogManager.sendError(this .getClass().getName()
034: + ":: init privilege loader exception: " + ex);
035: throw new AuthenticationException(this .getClass().getName()
036: + ":: init privilege loader exception: "
037: + ex.getMessage());
038: }
039: }
040:
041: public boolean hasPrivilege(String functionality, Object object)
042: throws BusinessException {
043: boolean ret = true;
044: try {
045: if (this .getProfile() != null)
046: ret = this .getPrivileges().hasPrivilege(functionality,
047: this , object);
048: } finally {
049: LogManager.sendDebug(this .getClass().getName()
050: + "::hasPrivilege: user '" + this .getUsername()
051: + "' profile: '" + this .getProfile() + "' "
052: + (ret ? "" : "not ") + "has privilege for '"
053: + functionality + "' and for object: " + object);
054: return ret;
055: }
056: }
057:
058: public String getUsername() {
059: return this .getField(USERNAME);
060: }
061:
062: public String getFirstName() {
063: return this .getField(FIRST_NAME);
064: }
065:
066: public String getLastName() {
067: return this .getField(LAST_NAME);
068: }
069:
070: public long getAuthenticationTime() {
071: return this .authenticationTime;
072: }
073:
074: public String getProfile() {
075: String profile = this .getField(PROFILE);
076: if (profile == null || profile.trim().equals(""))
077: profile = "guess";
078: return profile;
079: }
080:
081: public PrivilegeList getPrivileges() throws BusinessException {
082: if (this .privileges == null)
083: this .privileges = PrivilegeFactory.getDefault()
084: .getPrivileges(this );
085: return this .privileges;
086: }
087:
088: public String toString() {
089: String privileges = "''";
090: try {
091: privileges = this .getPrivileges().toString();
092: } catch (BusinessException ex) {
093: }
094: return super .toString() + " privileges: " + privileges;
095: }
096:
097: protected void setProfile(String profile)
098: throws AuthenticationException {
099: if (profile == null || profile.trim().equals(""))
100: throw new AuthenticationException("Not validofile");
101: this .putField(PROFILE, profile);
102: }
103:
104: protected String getPassword() {
105: return this .getField(PASSWORD);
106: }
107:
108: protected void setUsername(String username)
109: throws AuthenticationException {
110: if (username == null || username.trim().equals(""))
111: throw new AuthenticationException("Not valid username");
112: this .putField(USERNAME, username);
113: }
114:
115: protected void setPassword(String password)
116: throws AuthenticationException {
117: if (password == null || password.trim().equals(""))
118: throw new AuthenticationException("Not valid password");
119: this .putField(PASSWORD, password);
120: }
121:
122: private long authenticationTime;
123: private PrivilegeList privileges = null;
124: }
|