This project has retired. For details please refer to its Attic page.
User xref
View Javadoc

1   package org.apache.archiva.redback.rest.api.model;
2   
3   import org.apache.archiva.redback.integration.util.DateUtils;
4   
5   import javax.xml.bind.annotation.XmlRootElement;
6   import java.io.Serializable;
7   import java.util.List;
8   
9   /*
10   * Licensed to the Apache Software Foundation (ASF) under one
11   * or more contributor license agreements.  See the NOTICE file
12   * distributed with this work for additional information
13   * regarding copyright ownership.  The ASF licenses this file
14   * to you under the Apache License, Version 2.0 (the
15   * "License"); you may not use this file except in compliance
16   * with the License.  You may obtain a copy of the License at
17   *
18   * http://www.apache.org/licenses/LICENSE-2.0
19   *
20   * Unless required by applicable law or agreed to in writing,
21   * software distributed under the License is distributed on an
22   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23   * KIND, either express or implied.  See the License for the
24   * specific language governing permissions and limitations
25   * under the License.
26   */
27  
28  @XmlRootElement( name = "user" )
29  public class User
30      implements Serializable
31  {
32      private String username;
33  
34      private String fullName;
35  
36      private String email;
37  
38      private boolean validated;
39  
40      private boolean locked;
41  
42      private String password;
43  
44      private boolean passwordChangeRequired;
45  
46      private boolean permanent;
47  
48      private String confirmPassword;
49  
50      // Display Only Fields.
51      private String timestampAccountCreation;
52  
53      private String timestampLastLogin;
54  
55      private String timestampLastPasswordChange;
56  
57      /**
58       * for password change only
59       *
60       * @since 1.4
61       */
62      private String previousPassword;
63  
64      /**
65       * for roles update only <b>not return on user read</b>
66       *
67       * @since 2.0
68       */
69      private List<String> assignedRoles;
70  
71      /**
72       * with some userManagerImpl it's not possible to edit users;
73       * @since 2.1
74       */
75      private boolean readOnly;
76  
77      /**
78       * as we can user multiple userManagers implementation we must track from which one this one comes.
79       * @since 2.1
80       * @return userManager id
81       */
82      private String userManagerId;
83  
84      public User()
85      {
86          // no op
87      }
88  
89      public User( String username, String fullName, String email, boolean validated, boolean locked )
90      {
91          this.username = username;
92          this.fullName = fullName;
93          this.email = email;
94          this.validated = validated;
95          this.locked = locked;
96      }
97  
98      public User( org.apache.archiva.redback.users.User user )
99      {
100         setUsername( user.getUsername() );
101         this.setEmail( user.getEmail() );
102         this.setFullName( user.getFullName() );
103         this.setLocked( user.isLocked() );
104         this.setPassword( user.getPassword() );
105         this.setValidated( user.isValidated() );
106         this.setPasswordChangeRequired( user.isPasswordChangeRequired() );
107         this.setPermanent( user.isPermanent() );
108         this.setUserManagerId( user.getUserManagerId() );
109 
110         setTimestampAccountCreation( DateUtils.formatWithAge( user.getAccountCreationDate(), "ago" ) );
111         setTimestampLastLogin( DateUtils.formatWithAge( user.getLastLoginDate(), "ago" ) );
112         setTimestampLastPasswordChange( DateUtils.formatWithAge( user.getLastPasswordChange(), "ago" ) );
113     }
114 
115 
116     public String getUsername()
117     {
118         return username;
119     }
120 
121     public void setUsername( String username )
122     {
123         this.username = username;
124     }
125 
126     public String getFullName()
127     {
128         return fullName;
129     }
130 
131     public void setFullName( String fullName )
132     {
133         this.fullName = fullName;
134     }
135 
136     public String getEmail()
137     {
138         return email;
139     }
140 
141     public void setEmail( String email )
142     {
143         this.email = email;
144     }
145 
146     public boolean isValidated()
147     {
148         return validated;
149     }
150 
151     public void setValidated( boolean validated )
152     {
153         this.validated = validated;
154     }
155 
156     public boolean isLocked()
157     {
158         return locked;
159     }
160 
161     public void setLocked( boolean isLocked )
162     {
163         this.locked = isLocked;
164     }
165 
166     public String getPassword()
167     {
168         return password;
169     }
170 
171     public void setPassword( String password )
172     {
173         this.password = password;
174     }
175 
176     public boolean isPasswordChangeRequired()
177     {
178         return passwordChangeRequired;
179     }
180 
181     public void setPasswordChangeRequired( boolean passwordChangeRequired )
182     {
183         this.passwordChangeRequired = passwordChangeRequired;
184     }
185 
186     public boolean isPermanent()
187     {
188         return permanent;
189     }
190 
191     public void setPermanent( boolean permanent )
192     {
193         this.permanent = permanent;
194     }
195 
196     public String getConfirmPassword()
197     {
198         return confirmPassword;
199     }
200 
201     public void setConfirmPassword( String confirmPassword )
202     {
203         this.confirmPassword = confirmPassword;
204     }
205 
206     public String getTimestampAccountCreation()
207     {
208         return timestampAccountCreation;
209     }
210 
211     public void setTimestampAccountCreation( String timestampAccountCreation )
212     {
213         this.timestampAccountCreation = timestampAccountCreation;
214     }
215 
216     public String getTimestampLastLogin()
217     {
218         return timestampLastLogin;
219     }
220 
221     public void setTimestampLastLogin( String timestampLastLogin )
222     {
223         this.timestampLastLogin = timestampLastLogin;
224     }
225 
226     public String getTimestampLastPasswordChange()
227     {
228         return timestampLastPasswordChange;
229     }
230 
231     public void setTimestampLastPasswordChange( String timestampLastPasswordChange )
232     {
233         this.timestampLastPasswordChange = timestampLastPasswordChange;
234     }
235 
236     public String getPreviousPassword()
237     {
238         return previousPassword;
239     }
240 
241     public void setPreviousPassword( String previousPassword )
242     {
243         this.previousPassword = previousPassword;
244     }
245 
246     public List<String> getAssignedRoles()
247     {
248         return assignedRoles;
249     }
250 
251     public void setAssignedRoles( List<String> assignedRoles )
252     {
253         this.assignedRoles = assignedRoles;
254     }
255 
256     public boolean isReadOnly()
257     {
258         return readOnly;
259     }
260 
261     public void setReadOnly( boolean readOnly )
262     {
263         this.readOnly = readOnly;
264     }
265 
266     public String getUserManagerId()
267     {
268         return userManagerId;
269     }
270 
271     public void setUserManagerId( String userManagerId )
272     {
273         this.userManagerId = userManagerId;
274     }
275 
276     @Override
277     public String toString()
278     {
279         return "User{" +
280             "username='" + username + '\'' +
281             ", fullName='" + fullName + '\'' +
282             ", email='" + email + '\'' +
283             ", validated=" + validated +
284             ", locked=" + locked +
285             //", password='" + password + '\'' +
286             ", passwordChangeRequired=" + passwordChangeRequired +
287             ", permanent=" + permanent +
288             ", confirmPassword='" + confirmPassword + '\'' +
289             ", timestampAccountCreation='" + timestampAccountCreation + '\'' +
290             ", timestampLastLogin='" + timestampLastLogin + '\'' +
291             ", timestampLastPasswordChange='" + timestampLastPasswordChange + '\'' +
292             ", previousPassword='" + previousPassword + '\'' +
293             ", assignedRoles=" + assignedRoles +
294             ", readOnly=" + readOnly +
295             ", userManagerId='" + userManagerId + '\'' +
296             '}';
297     }
298 
299     @Override
300     public boolean equals( Object o )
301     {
302         if ( this == o )
303         {
304             return true;
305         }
306         if ( !( o instanceof User ) )
307         {
308             return false;
309         }
310 
311         User user = (User) o;
312 
313         if ( !username.equals( user.username ) )
314         {
315             return false;
316         }
317 
318         return true;
319     }
320 
321     @Override
322     public int hashCode()
323     {
324         return username.hashCode();
325     }
326 }