View Javadoc

1   /*
2    * Copyright (c) 2004 UNINETT FAS
3    *
4    * This program is free software; you can redistribute it and/or modify it
5    * under the terms of the GNU General Public License as published by the Free
6    * Software Foundation; either version 2 of the License, or (at your option)
7    * any later version.
8    *
9    * This program is distributed in the hope that it will be useful, but WITHOUT
10   * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11   * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12   * more details.
13   *
14   * You should have received a copy of the GNU General Public License along with
15   * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
16   * Place - Suite 330, Boston, MA 02111-1307, USA.
17   *
18   * $Id: CachedUserData.java,v 1.10 2005/11/24 14:28:50 catoolsen Exp $
19   */
20  
21  package no.feide.moria.store;
22  
23  import java.util.HashMap;
24  
25  /***
26   * This class is a container for userdata that persists across logins (for SSO
27   * Light and Proxy authentication).
28   * @author Bjørn Ola Smievoll <b.o@smievoll.no>
29   * @version $Revision: 1.10 $
30   */
31  public final class CachedUserData
32  implements MoriaStoreData {
33  
34      /*** The internal hashmap used to store the attributes. */
35      private final HashMap attributes;
36  
37  
38      /***
39       * Constructs a new instance encapsulating the userdata given as argument.
40       * @param attributes
41       *            A hashmap containing the user attributes.
42       */
43      public CachedUserData(final HashMap attributes) {
44  
45          if (attributes == null)
46              throw new IllegalArgumentException("Argument can not be null");
47          this.attributes = attributes;
48      }
49  
50  
51      /***
52       * Adds an attribute. Needed to add ticket granting tickets to cache.
53       * @param name
54       *            Attribute name.
55       * @param data
56       *            Attribute data.
57       */
58      public void addAttribute(final String name, final Object data) {
59  
60          this.attributes.put(name, data);
61      }
62  
63  
64      /***
65       * Remove an attribute. Needed to purge non-SSO-enabled attributes.
66       * @param name
67       *            Attribute name.
68       */
69      public void removeAttribute(final String name) {
70  
71          attributes.remove(name);
72  
73      }
74  
75  
76      /***
77       * Gets a map containing the attributes.
78       * @return A clone of the internal attribute map.
79       */
80      public HashMap getAttributes() {
81  
82          return (HashMap) attributes.clone();
83      }
84  }