1. A method for applying a security policy to an application session, comprising: determining, by a security gateway, a first user identity and a second user identity from a data packet for an application session, the determining comprising: inspecting, by the security gateway, the data packet for the application session and storing a host identity and an application session time in an application session record; determining, by the security gateway, from the data packet for the application session a user identity and storing the user identity in the application session record; determining, by the security gateway, a second user identity by matching an access session record of an access session accessed during the application session that comprises the second user identity, a second host identity, and an access session time, wherein the second host identity, and the access session time match the host identity and the application session time of the application session record; storing the second user identity in the application session record; obtaining, by the security gateway, a security policy for the application session based on the first user identity or the second user identity; and applying the security policy to the application session by the security gateway.