KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > acl > RoleMapperFactory


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.security.acl;
25
26 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapperFactory;
27 import com.sun.enterprise.deployment.interfaces.SecurityRoleMapper;
28 import java.util.Map JavaDoc;
29 import java.util.HashMap JavaDoc;
30 /**
31  *
32  * @author Jerome Dochez
33  */

34 public class RoleMapperFactory implements SecurityRoleMapperFactory {
35     private static Map JavaDoc CONTEXT_TO_APPNAME = new HashMap JavaDoc();
36     /** Creates a new instance of RoleMapperFactory */
37     public RoleMapperFactory() {
38     }
39     
40     /** Returns a RoleMapper corresponding to the AppName.
41      * @param The Application Name of this RoleMapper.
42      *
43      */

44     public SecurityRoleMapper getRoleMapper(String JavaDoc appName) {
45         // if the appName is not appname but contextid for
46
// web apps then get the appname
47
String JavaDoc contextId = appName;
48         String JavaDoc appname = getAppNameForContext(appName);
49         SecurityRoleMapper srm = null;
50         if(appname != null)
51             srm = RoleMapper.getRoleMapper(appname);
52         if(srm == null){
53             srm = RoleMapper.getRoleMapper(contextId);
54         }
55         return srm;
56     }
57      
58     /**
59      * remove the RoleMapping associated with this application
60      * @param the application name for this RoleMapper
61      */

62     public void removeRoleMapper(String JavaDoc appName) {
63         RoleMapper.removeRoleMapper(appName);
64     }
65     
66     /**
67      * Sets a new RoleMapper for a particular Application
68      * @param the application name
69      * @param the new role mapper
70      */

71     public void setRoleMapper(String JavaDoc appName, SecurityRoleMapper rmap) {
72         RoleMapper.setRoleMapper(appName, rmap);
73     }
74     
75     public String JavaDoc getAppNameForContext(String JavaDoc contextId) {
76         return (String JavaDoc)CONTEXT_TO_APPNAME.get(contextId);
77     }
78     
79     public void setAppNameForContext(String JavaDoc appName, String JavaDoc contextId) {
80         CONTEXT_TO_APPNAME.put(contextId, appName);
81     }
82     
83     public void removeAppNameForContext(String JavaDoc contextId) {
84         CONTEXT_TO_APPNAME.remove(contextId);
85     }
86     
87 }
88
Popular Tags