use of javax.ejb.EJBContext in project Payara by payara.
the class BasicPasswordAuthenticationService method doMap.
/**
* Performs the actual mapping of the principal/userGroup to the
* backendPrincipal by checking at the connector registry for all the
* existing mapping. If a map is found the backendPrincipal is
* returned else null is returned .
*/
private Principal doMap(String principalName, List groupNames, String roleName, RuntimeSecurityMap runtimeSecurityMap) {
// Policy:
// user_1, user_2, ... user_n
// group_1/role_1, group_2/role_2, ... group_n/role_n
// user contains *
// role/group contains *
HashMap userNameSecurityMap = (HashMap) runtimeSecurityMap.getUserMap();
HashMap groupNameSecurityMap = (HashMap) runtimeSecurityMap.getGroupMap();
// Check if caller's user-name is preset in the User Map
if (userNameSecurityMap.containsKey(principalName)) {
return (Principal) userNameSecurityMap.get(principalName);
}
// Check if caller's role is present in the Group Map
if (isContainerContextAWebModuleObject() && roleName != null) {
if (groupNameSecurityMap.containsKey(roleName)) {
return (Principal) groupNameSecurityMap.get(roleName);
}
}
// If ejb, use isCallerInRole
if (isContainerContextAEJBContainerObject() && roleName == null) {
ComponentInvocation componentInvocation = ConnectorRuntime.getRuntime().getInvocationManager().getCurrentInvocation();
EJBInvocation ejbInvocation = (EJBInvocation) componentInvocation;
EJBContext ejbcontext = ejbInvocation.getEJBContext();
Set<Map.Entry> s = (Set<Map.Entry>) groupNameSecurityMap.entrySet();
Iterator i = s.iterator();
while (i.hasNext()) {
Map.Entry mapEntry = (Map.Entry) i.next();
String key = (String) mapEntry.getKey();
Principal entry = (Principal) mapEntry.getValue();
boolean isInRole = false;
try {
isInRole = ejbcontext.isCallerInRole(key);
} catch (Exception ex) {
if (_logger.isLoggable(Level.FINE)) {
_logger.log(Level.FINE, "BasicPasswordAuthentication::caller not in role " + key);
}
}
if (isInRole) {
return entry;
}
}
}
// Check if caller's group(s) is/are present in the Group Map
for (int j = 0; j < groupNames.size(); j++) {
String groupName = (String) groupNames.get(j);
if (groupNameSecurityMap.containsKey(groupName)) {
return (Principal) groupNameSecurityMap.get(groupName);
}
}
// Check if user name is * in Security Map
if (userNameSecurityMap.containsKey(ConnectorConstants.SECURITYMAPMETACHAR)) {
return (Principal) userNameSecurityMap.get(ConnectorConstants.SECURITYMAPMETACHAR);
}
// Check if role/group name is * in Security Map
if (groupNameSecurityMap.containsKey(ConnectorConstants.SECURITYMAPMETACHAR)) {
return (Principal) groupNameSecurityMap.get(ConnectorConstants.SECURITYMAPMETACHAR);
}
return null;
}
Aggregations