KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sslexplorer > activedirectory > UserContainer


1 /*
2  * SSL-Explorer
3  *
4  * Copyright (C) 2003-2006 3SP LTD. All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  */

19             
20 package com.sslexplorer.activedirectory;
21
22 import java.util.Collection JavaDoc;
23
24 public final class UserContainer extends PrincipalContainer<ActiveDirectoryUser> {
25     private static final String JavaDoc USERS_CACHE_PREFIX = "users";
26     private static final String JavaDoc CACHE_FULL_MESSAGE = "activeDirectory.cache.user.full";
27     public static final UserContainer EMPTY_CACHE = new UserContainer(0, true, false);
28     private final boolean usernamesAreCaseSensitive;
29     
30     UserContainer(int cacheSize, boolean inMemoryCache, boolean usernamesAreCaseSensitive) {
31         super(cacheSize, inMemoryCache, USERS_CACHE_PREFIX, CACHE_FULL_MESSAGE);
32         this.usernamesAreCaseSensitive = usernamesAreCaseSensitive;
33     }
34
35     @Override JavaDoc
36     synchronized boolean containsPrincipal(String JavaDoc principalName) {
37         principalName = fixUpUsername(principalName);
38         return super.containsPrincipal(principalName);
39     }
40
41     @Override JavaDoc
42     synchronized ActiveDirectoryUser retrievePrincipal(String JavaDoc principalName) {
43         principalName = fixUpUsername(principalName);
44         return super.retrievePrincipal(principalName);
45     }
46
47     @Override JavaDoc
48     synchronized Collection JavaDoc<ActiveDirectoryUser> retrievePrincipals(String JavaDoc filter) {
49         filter = fixUpUsername(filter);
50         return super.retrievePrincipals(filter);
51     }
52
53     @Override JavaDoc
54     synchronized String JavaDoc storePrincipal(ActiveDirectoryUser principal) {
55         String JavaDoc fixUpUsername = fixUpUsername(principal.getPrincipalName());
56         storePrinciple(fixUpUsername, principal);
57         return fixUpUsername;
58     }
59
60     @Override JavaDoc
61     void removePrincipal(String JavaDoc principleName) {
62         String JavaDoc fixUpUsername = fixUpUsername(principleName);
63         super.removePrincipal(fixUpUsername);
64     }
65
66     private String JavaDoc fixUpUsername(String JavaDoc username) {
67         return usernamesAreCaseSensitive ? username : username.toLowerCase();
68     }
69 }
Free Books   Free Magazines  
Popular Tags