0

I have grails app developed with spring security plugin.Now i need to make it web service so installed xfire plugin.Now i want to have a service which has a method with parameters username and password then need to call login controller auth action (spring security plugin generated),now how to do that? can call service from controller but how to call controller action from service?

With advance thanks, Laxmi.p

laxmi
  • 107
  • 5

1 Answers1

1

You should not call controller actions from anywhere - except for other controller actions. See this question: Grails Invoke a controller method from a scheduled job

To programmatically login a user, you can do this:

void login(String username, String password) {
    def authToken = new UsernamePasswordAuthenticationToken(username, password)
    def newauth = authenticationManager.authenticate(authToken)
    SecurityContextHolder.getContext().setAuthentication(newauth)
}
Community
  • 1
  • 1
Victor Sergienko
  • 13,115
  • 3
  • 57
  • 91