Skip to content

Instantly share code, notes, and snippets.

@sergiomichels
Forked from anonymous/AuthFilters.groovy
Created July 20, 2013 01:42
Show Gist options
  • Save sergiomichels/6043494 to your computer and use it in GitHub Desktop.
Save sergiomichels/6043494 to your computer and use it in GitHub Desktop.
import org.springframework.security.core.Authentication
import org.springframework.security.core.context.SecurityContextHolder
class AuthFilters {
def springSecurityService
def dataSource
def filters = {
databaseConn(controller: '*', action: '*') {
before = {
if(!(controllerName in ['login','logout','password']) && springSecurityService.isLoggedIn()) {
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
String username = auth.getName(); //get logged in username
String password = (String)auth.getCredentials();
dataSource.setCredentialsForCurrentThread(username, password)
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment