1 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 ; 34 35 39 40 public class SecurityMapUtils { 41 42 private static ConnectorRegistry _registry = 43 ConnectorRegistry.getInstance(); 44 public static String USERMAP = "usermap"; 45 public static String GROUPMAP = "groupmap"; 46 47 54 55 public static RuntimeSecurityMap processSecurityMaps( 56 ConnectorSecurityMap[] securityMaps) { 57 if (securityMaps == null || securityMaps.length == 0) { 58 return new RuntimeSecurityMap(); 59 } 60 61 HashMap userMap = new HashMap (); 62 HashMap groupMap = new HashMap (); 63 for (int i = 0; i < securityMaps.length; i++) { 65 ConnectorSecurityMap map = securityMaps[i]; 66 ResourcePrincipal principal = generateResourcePrincipal(map); 67 68 String [] principalNames = map.getPrincipals(); 69 for (int j = 0; j < principalNames.length; j++) { 70 userMap.put(principalNames[j], principal); 71 } 72 73 String [] 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 name = securityMap.getName(); 99 String [] principal = securityMap.getPrincipal(); 100 String [] 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 114 115 private static ResourcePrincipal generateResourcePrincipal( 116 ConnectorSecurityMap securityMap) { 117 118 EisBackendPrincipal backendPrincipal = securityMap.getBackendPrincipal(); 119 String userName = backendPrincipal.getUserName(); 120 String 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 userName = principal.getUserName(); 128 String password = principal.getPassword(); 129 EisBackendPrincipal backendPrincipal = 130 new EisBackendPrincipal(userName, password); 131 return backendPrincipal; 132 } 133 134 } 135 136 | Popular Tags |