PageRenderTime 137ms CodeModel.GetById 71ms app.highlight 15ms RepoModel.GetById 46ms app.codeStats 0ms

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