How to get instances of inner Spring objects

Viewed 57

I have a Grails app and need to get access to Spring's instance of the AuthenticationManager/ProviderManager so I can provide it to my instance of RemoteAuthenticationProviderImpl. I have the following code in my ApiController.groovy, where I want to authenticate remote clients, which are logging into another Grails app and send back their granted authorities.

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 is documented here. It can be seen, that I need to provide an AuthenticationManager. I think I need to inject this via a bean, but I can't get that to work.

1 Answers
Related