Example usage for org.springframework.security.core.context SecurityContextImpl getAuthentication

List of usage examples for org.springframework.security.core.context SecurityContextImpl getAuthentication

Introduction

In this page you can find the example usage for org.springframework.security.core.context SecurityContextImpl getAuthentication.

Prototype

@Override
    public Authentication getAuthentication() 

Source Link

Usage

From source file:eu.supersede.fe.security.redis.session.AuthenticationSuccessListenerRedisSession.java

@Override
public void onApplicationEvent(SessionCreatedEvent event) {
    log.debug("created session id: " + event.getSessionId());

    MapSession ms = (MapSession) event.getSession();
    Session s = new Session();
    s.setId(ms.getId());/*from w  w  w.ja v  a  2 s  .c o m*/
    s.setCreationTime(new Date(ms.getCreationTime()));
    s.setLastAccessTime(new Date(ms.getLastAccessedTime()));

    Object securetyContext = sessionObjectTemplate.opsForHash().get("spring:session:sessions:" + s.getId(),
            "sessionAttr:SPRING_SECURITY_CONTEXT");
    if (securetyContext != null) {
        SecurityContextImpl sCI = (SecurityContextImpl) securetyContext;
        DatabaseUser dbU = (DatabaseUser) sCI.getAuthentication().getPrincipal();
        s.setDatabaseUser(dbU);
    }

    sessionTemplate.opsForValue().set(Session.SUPERSEDE_SESSION_PREFIX + s.getId(), s);
}