KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > connectors > util > SecurityMapUtils


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.connectors.util;
25
26 import com.sun.enterprise.config.serverbeans.BackendPrincipal;
27 import com.sun.enterprise.connectors.ConnectorRegistry;
28 import com.sun.enterprise.deployment.ResourcePrincipal;
29 import com.sun.enterprise.connectors.authentication.RuntimeSecurityMap;
30 import com.sun.enterprise.connectors.authentication.EisBackendPrincipal;
31 import com.sun.enterprise.connectors.authentication.ConnectorSecurityMap;
32 import com.sun.enterprise.config.serverbeans.SecurityMap;
33 import java.util.HashMap JavaDoc;
34
35 /** This is class performs the task of adding/deleting and updating the
36  * security maps to the connector registry.
37  * @author Srikanth P
38  */

39
40 public class SecurityMapUtils {
41
42     private static ConnectorRegistry _registry =
43                         ConnectorRegistry.getInstance();
44     public static String JavaDoc USERMAP = "usermap";
45     public static String JavaDoc GROUPMAP = "groupmap";
46
47     /** Updates the registry with the security map. If a security map already
48      * exists it deletes that map completely before adding the mew security
49      * map.
50      * @param securityMaps Array of securityMaps to be updated.
51      * @return Hash Map containing 1 - 1 mappings of principal and
52      * Resource Principal
53      */

54   
55     public static RuntimeSecurityMap processSecurityMaps(
56             ConnectorSecurityMap[] securityMaps) {
57         if (securityMaps == null || securityMaps.length == 0) {
58             return new RuntimeSecurityMap();
59         }
60
61         HashMap JavaDoc userMap = new HashMap JavaDoc();
62         HashMap JavaDoc groupMap = new HashMap JavaDoc();
63         // Add user-backendPrincipal mappings to Map1
64
for (int i = 0; i < securityMaps.length; i++) {
65             ConnectorSecurityMap map = securityMaps[i];
66             ResourcePrincipal principal = generateResourcePrincipal(map);
67
68             String JavaDoc[] principalNames = map.getPrincipals();
69             for (int j = 0; j < principalNames.length; j++) {
70                 userMap.put(principalNames[j], principal);
71             }
72
73             String JavaDoc[] groupNames = map.getUserGroups();
74             for (int j = 0; j < groupNames.length; j++) {
75                 groupMap.put(groupNames[j], principal);
76             }
77         }
78
79         RuntimeSecurityMap runtimeSecurityMap = new RuntimeSecurityMap(userMap,
80                 groupMap);
81
82         return runtimeSecurityMap;
83     }
84
85     public static ConnectorSecurityMap[] getConnectorSecurityMaps(
86             SecurityMap[] securityMaps) {
87
88         ConnectorSecurityMap[] maps = new ConnectorSecurityMap[securityMaps.length];
89         for (int i = 0; i < securityMaps.length; i++) {
90             maps[i] = convertSecurityMapConfigBeanToSecurityMap(securityMaps[i]);
91         }
92         return maps;
93     }
94
95     private static ConnectorSecurityMap convertSecurityMapConfigBeanToSecurityMap(
96             SecurityMap securityMap) {
97
98         String JavaDoc name = securityMap.getName();
99         String JavaDoc[] principal = securityMap.getPrincipal();
100         String JavaDoc[] userGroup = securityMap.getUserGroup();
101         EisBackendPrincipal backendPrincipal = transformBackendPrincipal(securityMap
102                 .getBackendPrincipal());
103         ConnectorSecurityMap convertedSecurityMap = new ConnectorSecurityMap(
104                 name, principal, userGroup, backendPrincipal);
105
106         return convertedSecurityMap;
107     }
108
109     /**
110      * Creates the ResourcePrincipal object from the given securityMap
111      * @param securityMap SecurityMap
112      * @return created ResourcePrincipal object
113      */

114
115     private static ResourcePrincipal generateResourcePrincipal(
116                  ConnectorSecurityMap securityMap) {
117
118         EisBackendPrincipal backendPrincipal = securityMap.getBackendPrincipal();
119         String JavaDoc userName = backendPrincipal.getUserName();
120         String JavaDoc password = backendPrincipal.getPassword();
121         ResourcePrincipal resPrincipal =
122                       new ResourcePrincipal(userName,password);
123         return resPrincipal;
124     }
125     
126     private static EisBackendPrincipal transformBackendPrincipal(BackendPrincipal principal){
127         String JavaDoc userName = principal.getUserName();
128         String JavaDoc password = principal.getPassword();
129         EisBackendPrincipal backendPrincipal =
130                       new EisBackendPrincipal(userName, password);
131         return backendPrincipal;
132     }
133
134 }
135
136
Popular Tags