spring security (3.0.x) and user impersonation

前端 未结 3 1482
Happy的楠姐
Happy的楠姐 2020-12-31 18:40

In my web application, there are times when an authenticated admin might want to impersonate another valid user of a system without having to know that user\'s password.

相关标签:
3条回答
  • 2020-12-31 19:05

    If you want an admin user to be able to impersonate another user (eg for QA/Testing purposes), have a look at the SwitchUserFilter

    A decent example of the XML config you need is provided here

    0 讨论(0)
  • 2020-12-31 19:09

    I believe the recommended way to do this in Spring Security is with the Domain Access Control lists, see GrantedAuthoritySid @

    http://static.springsource.org/spring-security/site/docs/3.1.x/reference/domain-acls.html

    However, impersonating another user is more than just having a "delegate identity", you should also consider the implications on logging:

    • Do you want your logging to appear as Original User or Impersonated User (or both?)
    • Do you want the "impersonation" to show only what the impersonated user sees, or the superset of permissions of the Original User and Impersonated User?

    Yet another possibility is to create a "log in as" feature, which essentially changes the principal identity of the current session - or starts a new session with the impersonated identity.

    In all of the above, you may inadvertantly open up a security issue - so I think this is why impersonate-style features are not that common place. Rather, designs trend towards Role Based Access Control (RBAC) or Attribute Based Access Control (ABAC). Using RBAC / ABAC, you could create a delegate style feature where you create delegate attributes/roles - and in the special cases where you need to show the source/target of the delegation (e.g. for audit logs), you handle those as corner cases.

    0 讨论(0)
  • 2020-12-31 19:10

    It's in the Spring Security 3 and Spring Security 4 docs aptly named, "Run-As Authentication Replacement."

    The AbstractSecurityInterceptor is able to temporarily replace the Authentication object in the SecurityContext and SecurityContextHolder during the secure object callback phase.

    0 讨论(0)
提交回复
热议问题