View Javadoc

1   /* Copyright 2004, 2005 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package org.acegisecurity.userdetails.memory;
17  
18  import java.util.List;
19  import java.util.Vector;
20  
21  import org.acegisecurity.GrantedAuthority;
22  import org.acegisecurity.GrantedAuthorityImpl;
23  
24  
25  /***
26   * Used by {@link InMemoryDaoImpl} to temporarily store the attributes
27   * associated with a user.
28   *
29   * @author Ben Alex
30   * @version $Id: UserAttribute.java,v 1.3 2005/11/29 13:10:09 benalex Exp $
31   */
32  public class UserAttribute {
33      //~ Instance fields ========================================================
34  
35      private List authorities = new Vector();
36      private String password;
37      private boolean enabled = true;
38  
39      //~ Constructors ===========================================================
40  
41      public UserAttribute() {
42          super();
43      }
44  
45      //~ Methods ================================================================
46  
47      public GrantedAuthority[] getAuthorities() {
48          GrantedAuthority[] toReturn = {new GrantedAuthorityImpl("demo")};
49  
50          return (GrantedAuthority[]) this.authorities.toArray(toReturn);
51      }
52  
53      public void setEnabled(boolean enabled) {
54          this.enabled = enabled;
55      }
56  
57      public boolean isEnabled() {
58          return enabled;
59      }
60  
61      public void setPassword(String password) {
62          this.password = password;
63      }
64  
65      public String getPassword() {
66          return password;
67      }
68  
69      public boolean isValid() {
70          if ((this.password != null) && (authorities.size() > 0)) {
71              return true;
72          } else {
73              return false;
74          }
75      }
76  
77      public void addAuthority(GrantedAuthority newAuthority) {
78          this.authorities.add(newAuthority);
79      }
80  }