【问题标题】:How to get instances of inner Spring objects如何获取内部 Spring 对象的实例
【发布时间】:2016-06-24 01:26:00
【问题描述】:

我有一个 Grails 应用程序,需要访问 Spring 的 AuthenticationManager/ProviderManager 实例,以便我可以将它提供给我的 RemoteAuthenticationProviderImpl 实例。 我的 ApiController.groovy 中有以下代码,我想在其中验证远程客户端,这些客户端正在登录另一个 Grails 应用程序并发回其授予的权限。

def remoteAuthentication() {
    def authHeader = request.getHeader('Authorization')
    if (authHeader && apiService.validate(authHeader)) {
        try {
            def remoteAuthenticationManager = new RemoteAuthenticationManagerImpl()
            def response = remoteAuthenticationManager.attemptAuthentication("admin", "password1")
        } catch (Exception) {}
        render response as JSON
    }
    response.status = 401
    render(status: 401, text: 'Failed to authenticate.')
}

RemoteAuthenticationManagerImpl 记录在 here。可以看出,我需要提供一个AuthenticationManager。我想我需要通过 bean 注入它,但我无法让它工作。

【问题讨论】:

  • RemoteAuthenticationManager(Impl) 用于 RPC。在这种情况下,它看起来错位了。你想完成什么?
  • 哦,好的,谢谢。我有一个带有用户名和密码的 grails 应用程序,而另一个没有它们。我正在尝试将该服务器上的登录尝试转发到另一台服务器,以便可以对其进行身份验证。然后它应该返回授予的权限并在缺少凭据的服务器上登录用户。
  • 我正在努力解决的主要部分是如何在给定用户名和密码的情况下在我的 api 中对用户进行身份验证。因为我并没有真正接触到 Spring 的内部工作原理,所以我不知道该怎么做,除了自己实现整个过程。这似乎不是正确的方法。您可能有一个想法,我该如何实现?

标签: spring grails spring-security


【解决方案1】:

我自己解决了这个问题。我的错误是,我放了一个 <ref local="authenticationManager" /> 而不是 <ref bean="authenticationManager" /> 进入我的 resources.xml。

【讨论】:

    猜你喜欢
    • 2011-01-10
    • 2015-08-19
    • 1970-01-01
    • 2011-01-28
    • 1970-01-01
    • 2011-10-26
    • 1970-01-01
    • 2022-06-16
    • 1970-01-01
    相关资源
    最近更新 更多