001: /*
002: * Copyright 2006-2007 Luca Garulli (luca.garulli@assetdata.it)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.romaframework.module.users.domain;
018:
019: import java.io.Serializable;
020: import java.security.NoSuchAlgorithmException;
021: import java.util.Date;
022:
023: import org.romaframework.aspect.authentication.AuthenticationAspect;
024: import org.romaframework.aspect.core.annotation.AnnotationConstants;
025: import org.romaframework.aspect.core.annotation.CoreClass;
026: import org.romaframework.aspect.session.SessionAccount;
027: import org.romaframework.aspect.view.annotation.ViewField;
028: import org.romaframework.core.flow.ObjectContext;
029: import org.romaframework.module.admin.domain.Info;
030:
031: /**
032: * Class that rapresents an account
033: *
034: * @author Luca Garulli (luca.garulli@assetdata.it)
035: */
036: @CoreClass(orderFields="name status profile signedOn lastModified notes password changePasswordNextLogin")
037: public class BaseAccount implements SessionAccount, Serializable {
038:
039: @ViewField(required=AnnotationConstants.TRUE)
040: protected String name;
041:
042: protected BaseProfile profile;
043:
044: @ViewField(enabled=AnnotationConstants.FALSE)
045: protected Date signedOn;
046: @ViewField(enabled=AnnotationConstants.FALSE)
047: protected Date lastModified;
048:
049: @ViewField(required=AnnotationConstants.TRUE,render="password")
050: protected String password;
051:
052: @ViewField(render="textarea")
053: protected String notes;
054:
055: @ViewField(visible=AnnotationConstants.FALSE)
056: private Info status;
057:
058: private Boolean changePasswordNextLogin;
059:
060: private String email;
061:
062: public BaseAccount() {
063: }
064:
065: public BaseAccount(String name, String password,
066: BaseProfile iProfile, Info iStatus)
067: throws NoSuchAlgorithmException {
068: this .name = name;
069: setPassword(password);
070: this .status = iStatus;
071: this .profile = iProfile;
072: signedOn = new Date();
073: lastModified = signedOn;
074: }
075:
076: @Override
077: public boolean equals(Object obj) {
078: if (!(obj instanceof BaseAccount))
079: return false;
080:
081: BaseAccount other = (BaseAccount) obj;
082: return name.equals(other.name);
083: }
084:
085: @Override
086: public String toString() {
087: return name;
088: }
089:
090: public String getName() {
091: return name;
092: }
093:
094: public void setName(String name) {
095: this .name = name;
096: }
097:
098: public BaseProfile getProfile() {
099: return profile;
100: }
101:
102: public void setProfile(Object iProfile) {
103: this .profile = (BaseProfile) iProfile;
104: }
105:
106: public void setProfile(BaseProfile iProfile) {
107: this .profile = iProfile;
108: }
109:
110: public String getPassword() {
111: return password;
112: }
113:
114: public void setPassword(String iPassword)
115: throws NoSuchAlgorithmException {
116: if (iPassword != null && iPassword.equals(this .password))
117: return; //you are not changing password...
118: this .password = ObjectContext.getInstance().getComponent(
119: AuthenticationAspect.class).encryptPassword(iPassword);
120: }
121:
122: public Date getLastModified() {
123: return lastModified;
124: }
125:
126: public void setLastModified(Date lastModified) {
127: this .lastModified = lastModified;
128: }
129:
130: public Date getSignedOn() {
131: return signedOn;
132: }
133:
134: public void setSignedOn(Date signedOn) {
135: this .signedOn = signedOn;
136: }
137:
138: public Info getStatus() {
139: return status;
140: }
141:
142: public void setStatus(Info status) {
143: this .status = status;
144: }
145:
146: public String getNotes() {
147: return notes;
148: }
149:
150: public void setNotes(String notes) {
151: this .notes = notes;
152: }
153:
154: public Boolean isChangePasswordNextLogin() {
155: return changePasswordNextLogin;
156: }
157:
158: public void setChangePasswordNextLogin(
159: Boolean changePasswordAtNextLogin) {
160: this .changePasswordNextLogin = changePasswordAtNextLogin;
161: }
162:
163: public String getEmail() {
164: return email;
165: }
166:
167: public void setEmail(String email) {
168: this.email = email;
169: }
170: }
|