2016-03-09 22 views
3

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

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注入,但是我无法让它工作。

+0

'RemoteAuthenticationManager(Impl)'用于RPC。它在这方面看起来错位。你想达到什么目的? – holmis83

+0

噢,谢谢。我有一个使用用户名和密码的grails应用程序,另一个没有它们。我试图将该服务器上的登录尝试转发给其他服务器,以便可以对其进行身份验证。然后它应该返回授予的权限并在缺少凭证的服务器上登录用户。 – nhaesler

+0

我正在努力的主要部分是如何在给定用户名和密码的情况下对我的api中的用户进行身份验证。因为我实际上并没有使用Spring的内部工作方式,所以我不知道该怎么做,也没有亲自实现整个过程。这似乎不是正确的做法。你可能有一个想法,我怎么能做到这一点? – nhaesler

回答

0

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