/src/groovy/general/BaseIntegrationTest.groovy

http://github.com/jdmr/mateo · Groovy · 33 lines · 27 code · 6 blank · 0 comment · 0 complexity · adb36b56fc562746fdcafb2e18e9625c MD5 · raw file

  1. package general
  2. import org.springframework.security.core.GrantedAuthority
  3. import org.springframework.security.core.authority.GrantedAuthorityImpl
  4. import org.codehaus.groovy.grails.plugins.springsecurity.GrailsUser
  5. import org.springframework.security.core.context.SecurityContextHolder as SCH
  6. import org.springframework.security.authentication.TestingAuthenticationToken
  7. class BaseIntegrationTest extends GroovyTestCase {
  8. def authenticateAdmin() {
  9. def credentials = 'test'
  10. def user = new Usuario(
  11. username:'admin'
  12. ,password:credentials
  13. )
  14. def authorities = [new GrantedAuthorityImpl('ROLE_ADMIN')]
  15. def principal = new GrailsUser(user.username,credentials,true,true,true,true,authorities,1)
  16. authenticate(principal,credentials,authorities)
  17. }
  18. def authenticate(principal, credentials, authorities) {
  19. def authentication = new TestingAuthenticationToken(principal, credentials, authorities as GrantedAuthority[])
  20. authentication.authenticated = true
  21. SCH.context.authentication = authentication
  22. return authentication
  23. }
  24. def logout() {
  25. SCH.context.authentication = null
  26. }
  27. }