KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > auth > ExternalUserRolesConfig


1 /**
2 * Copyright (c) 2004-2005 jManage.org
3 *
4 * This is a free software; you can redistribute it and/or
5 * modify it under the terms of the license at
6 * http://www.jmanage.org.
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */

14 package org.jmanage.core.auth;
15
16 import org.jmanage.core.util.Loggers;
17 import org.jmanage.core.util.CoreUtils;
18
19 import java.util.Properties JavaDoc;
20 import java.util.logging.Logger JavaDoc;
21 import java.util.logging.Level JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.io.FileInputStream JavaDoc;
24
25 /**
26  * @author shashank
27  * Date: Sep 27, 2005
28  */

29 public class ExternalUserRolesConfig extends Properties JavaDoc{
30     private static final Logger JavaDoc logger =
31             Loggers.getLogger(ExternalUserRolesConfig.class);
32
33     private String JavaDoc EXTERNAL_USER_ROLES_CONFIG_FILE = CoreUtils.getConfigDir() +
34             "/external-user-roles.properties";
35
36     private final String JavaDoc ASTERIX = "*";
37
38     /* The only instance */
39     private static ExternalUserRolesConfig instance =
40             new ExternalUserRolesConfig();
41
42     /**
43      *
44      */

45     private ExternalUserRolesConfig(){
46       super();
47       try{
48         InputStream JavaDoc property =
49                 new FileInputStream JavaDoc(EXTERNAL_USER_ROLES_CONFIG_FILE);
50         load(property);
51       }catch(Exception JavaDoc e){
52           logger.log(Level.SEVERE, "Error reading " +
53                   EXTERNAL_USER_ROLES_CONFIG_FILE, e);
54           CoreUtils.exitSystem();
55       }
56     }
57
58     public static ExternalUserRolesConfig getInstance(){
59         return instance;
60     }
61
62     public String JavaDoc getUserRole(String JavaDoc username){
63         String JavaDoc role = instance.getProperty(username);
64         return role != null ? role : instance.getProperty(ASTERIX);
65     }
66 }
67
Popular Tags