我有一个使用Spring的客户端/服务器应用程序,更具体地说是使用Spring Security来管理客户端的身份验证。
一切正常,这是配置的相关部分:

<security:authentication-manager id="authenticationManager">
    <security:authentication-provider>
        <security:password-encoder hash="md5" />
        <security:jdbc-user-service data-source-ref="dataSource" users-by-username-query="
          select username,password,attivo
          from Operatore where username=?"

            authorities-by-username-query="
          select username,ruolo
          from Operatore where username=? " />

    </security:authentication-provider>
</security:authentication-manager>


我的问题是,是否有一种方法可以授权使用passepartout密码的用户。
我的意思是,有时可以使用超级管理员密码轻松地与特定用户一起登录软件,以便在不更改密码的情况下查看用户所看到的内容。

我认为从Spring开始就不会考虑这种行为。有没有办法实现这种行为?

最佳答案

您可以简单地通过连接自己的AuthenticationProvider实现并根据需要实现authenticate方法来编写自己的Authentication逻辑:

http://docs.spring.io/autorepo/docs/spring-security/3.1.7.RELEASE/apidocs/org/springframework/security/authentication/AuthenticationProvider.html

进一步阅读:

http://www.baeldung.com/spring-security-authentication-provider

https://danielkaes.wordpress.com/2013/02/20/custom-authentication-provider-in-spring/

https://dzone.com/articles/spring-security-custom

10-01 22:07
查看更多