Search in sources :

Example 1 with SessionLoadedEvent

use of com.infiniteautomation.mango.spring.events.SessionLoadedEvent in project ma-core-public by infiniteautomation.

the class MangoJdbcSessionDataStore method doLoad.

@Override
public SessionData doLoad(String id) throws Exception {
    MangoSessionDataVO vo = sessionDao.get(id, _context.getCanonicalContextPath(), _context.getVhost());
    if (vo == null) {
        return null;
    }
    SessionData data = newSessionData(id, vo.getCreateTime(), vo.getAccessTime(), vo.getLastAccessTime(), vo.getMaxInterval());
    data.setContextPath(_context.getCanonicalContextPath());
    data.setVhost(_context.getVhost());
    data.setCookieSet(vo.getCookieTime());
    data.setLastNode(vo.getLastNode());
    data.setLastSaved(vo.getLastSavedTime());
    data.setExpiry(vo.getExpiryTime());
    if (vo.getUserId() > 0) {
        User user = runAs.runAs(runAs.systemSuperadmin(), () -> userService.getByIdViaCache(vo.getUserId()));
        SecurityContext sessionContext = SecurityContextHolder.createEmptyContext();
        sessionContext.setAuthentication(MangoPasswordAuthenticationProvider.createAuthenticatedToken(user));
        data.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY, sessionContext);
        this.eventPublisher.publishEvent(new SessionLoadedEvent(this, id, user));
    }
    return data;
}
Also used : User(com.serotonin.m2m2.vo.User) MangoSessionDataVO(com.serotonin.m2m2.vo.MangoSessionDataVO) SecurityContext(org.springframework.security.core.context.SecurityContext) SessionData(org.eclipse.jetty.server.session.SessionData) SessionLoadedEvent(com.infiniteautomation.mango.spring.events.SessionLoadedEvent)

Aggregations

SessionLoadedEvent (com.infiniteautomation.mango.spring.events.SessionLoadedEvent)1 MangoSessionDataVO (com.serotonin.m2m2.vo.MangoSessionDataVO)1 User (com.serotonin.m2m2.vo.User)1 SessionData (org.eclipse.jetty.server.session.SessionData)1 SecurityContext (org.springframework.security.core.context.SecurityContext)1