Search in sources :

Example 21 with EJBContext

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;
}
Also used : EJBContext(javax.ejb.EJBContext) ComponentInvocation(org.glassfish.api.invocation.ComponentInvocation) EJBInvocation(org.glassfish.ejb.api.EJBInvocation) Principal(java.security.Principal)

Aggregations

EJBContext (javax.ejb.EJBContext)21 InitialContext (javax.naming.InitialContext)15 EJBException (javax.ejb.EJBException)13 SessionContext (javax.ejb.SessionContext)12 AssertionFailedError (junit.framework.AssertionFailedError)12 TestFailureException (org.apache.openejb.test.TestFailureException)12 RemoteException (java.rmi.RemoteException)11 JMSException (javax.jms.JMSException)10 NamingException (javax.naming.NamingException)10 Context (javax.naming.Context)6 BeanContext (org.apache.openejb.BeanContext)5 OpenEJBException (org.apache.openejb.OpenEJBException)5 MBeanServer (javax.management.MBeanServer)4 ObjectName (javax.management.ObjectName)4 ApplicationException (org.apache.openejb.ApplicationException)4 SystemException (org.apache.openejb.SystemException)4 InstanceContext (org.apache.openejb.core.InstanceContext)4 ThreadContext (org.apache.openejb.core.ThreadContext)4 InterceptorData (org.apache.openejb.core.interceptor.InterceptorData)4 LocalMBeanServer (org.apache.openejb.monitoring.LocalMBeanServer)4