Film opisujący co i jak http://www.youtube.com/watch?v=PAeLK6Yp2P0 Update: plugin do firefoxa
Rapid development z Liveview
Film opisujący co i jak
Update: plugin do firefoxa
class BootStrap {
def init = { servletContext ->
servletContext.addListener(OurListenerClass)
}
}
beans = {
customTimeoutSessionListener(CustomTimeoutSessionListener) {
configService = ref('configService')
}
}
class BootStrap {
def customTimeoutSessionListener
def init = { servletContext ->
servletContext.addListener(customTimeoutSessionListener)
}
}
import javax.servlet.http.HttpSessionEventHaving at hand all power of the Spring IoC this is surely a good place to load some persisted user’s account stuff into the session or to notify any other adequate bean about user presence.
import javax.servlet.http.HttpSessionListener
import your.app.ConfigService
class CustomTimeoutSessionListener implements HttpSessionListener {
ConfigService configService
@Override
void sessionCreated(HttpSessionEvent httpSessionEvent) {
httpSessionEvent.session.maxInactiveInterval = configService.sessionTimeoutSeconds
}
@Override
void sessionDestroyed(HttpSessionEvent httpSessionEvent) { /* nothing to implement */ }
}
import org.springframework.security.core.context.SecurityContextHolderThis example is simplified. Does not contain much of defensive programming. Just an assumption that principal is already set and is a String - unique username. Thanks to Grails convention our ConfigService is transactional so the Account domain class can use GORM dynamic finder.
class ConfigService {
static final int 3H = 3 * 60 * 60
static final int QUARTER = 15 * 60
int getSessionTimeoutSeconds() {
String username = SecurityContextHolder.context?.authentication?.principal
def account = Account.findByUsername(username)
return account?.premium ? 3H : QUARTER
}
}
def init = { servletContext ->An unnecessary obstacle if you ask me. Should I submit a Jira issue about that?
if (Environment.current != Environment.TEST) {
servletContext.addListener(customTimeoutSessionListener)
}
}