Search in sources :

Example 1 with MangoSessionDataVO

use of com.serotonin.m2m2.vo.MangoSessionDataVO in project ma-modules-public by infiniteautomation.

the class MangoSessionDataModelMapping method map.

@Override
public MangoSessionDataModel map(Object from, PermissionHolder user, RestModelMapper mapper) {
    MangoSessionDataVO source = (MangoSessionDataVO) from;
    MangoSessionDataModel result = new MangoSessionDataModel();
    result.setSessionId(source.getSessionId());
    result.setContextPath(source.getContextPath());
    result.setVirtualHost(source.getVirtualHost());
    result.setLastNode(source.getLastNode());
    result.setAccessTime(new Date(source.getAccessTime()));
    result.setLastAccessTime(new Date(source.getLastAccessTime()));
    result.setCreateTime(new Date(source.getCreateTime()));
    result.setCookieTime(new Date(source.getCookieTime()));
    result.setLastSavedTime(source.getLastSavedTime());
    result.setExpiryTime(new Date(source.getExpiryTime()));
    result.setMaxInterval(source.getMaxInterval());
    User owner = dao.get(source.getUserId());
    if (user != null) {
        result.setUsername(owner.getUsername());
    }
    return result;
}
Also used : User(com.serotonin.m2m2.vo.User) MangoSessionDataVO(com.serotonin.m2m2.vo.MangoSessionDataVO) Date(java.util.Date)

Example 2 with MangoSessionDataVO

use of com.serotonin.m2m2.vo.MangoSessionDataVO in project ma-modules-public by infiniteautomation.

the class MangoSessionDataModelMapping method unmap.

@Override
public MangoSessionDataVO unmap(Object from, PermissionHolder user, RestModelMapper mapper) {
    MangoSessionDataModel source = (MangoSessionDataModel) from;
    MangoSessionDataVO result = new MangoSessionDataVO();
    result.setSessionId(source.getSessionId());
    result.setContextPath(source.getContextPath());
    result.setVirtualHost(source.getVirtualHost());
    result.setLastNode(source.getLastNode());
    result.setAccessTime(source.getAccessTime() != null ? source.getAccessTime().getTime() : 0l);
    result.setLastAccessTime(source.getLastAccessTime() != null ? source.getLastAccessTime().getTime() : 0l);
    result.setCreateTime(source.getCreateTime() != null ? source.getCreateTime().getTime() : 0l);
    result.setCookieTime(source.getCookieTime() != null ? source.getCookieTime().getTime() : 0l);
    result.setLastSavedTime(source.getLastSavedTime());
    result.setExpiryTime(source.getExpiryTime() != null ? source.getExpiryTime().getTime() : 0l);
    result.setMaxInterval(source.getMaxInterval());
    User owner = dao.getByXid(source.getUsername());
    if (user != null) {
        result.setUserId(owner.getId());
    }
    return result;
}
Also used : User(com.serotonin.m2m2.vo.User) MangoSessionDataVO(com.serotonin.m2m2.vo.MangoSessionDataVO)

Example 3 with MangoSessionDataVO

use of com.serotonin.m2m2.vo.MangoSessionDataVO in project ma-core-public by infiniteautomation.

the class MangoSessionDataDao method mapRecord.

public MangoSessionDataVO mapRecord(Record record) {
    MangoSessionDataVO vo = new MangoSessionDataVO();
    vo.setSessionId(record.get(table.sessionId));
    vo.setContextPath(record.get(table.contextPath));
    vo.setVirtualHost(record.get(table.virtualHost));
    vo.setLastNode(record.get(table.lastNode));
    vo.setAccessTime(record.get(table.accessTime));
    vo.setLastAccessTime(record.get(table.lastAccessTime));
    vo.setCreateTime(record.get(table.createTime));
    vo.setCookieTime(record.get(table.cookieTime));
    vo.setLastSavedTime(record.get(table.lastSavedTime));
    vo.setExpiryTime(record.get(table.expiryTime));
    vo.setMaxInterval(record.get(table.maxInterval));
    vo.setUserId(record.get(table.userId));
    return vo;
}
Also used : MangoSessionDataVO(com.serotonin.m2m2.vo.MangoSessionDataVO)

Example 4 with MangoSessionDataVO

use of com.serotonin.m2m2.vo.MangoSessionDataVO in project ma-core-public by infiniteautomation.

the class MangoJdbcSessionDataStore method maybeSetUserId.

/**
 */
private void maybeSetUserId(MangoSessionDataVO vo, SessionData data) {
    Object context = data.getAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY);
    // Persist the user id to retrieve on load
    if (context instanceof SecurityContext) {
        SecurityContext securityContext = (SecurityContext) context;
        Authentication auth = securityContext.getAuthentication();
        if (auth != null) {
            Object principle = auth.getPrincipal();
            // this is correct as we do not want to store the user id for OAuth2 authenticated users
            if (principle instanceof User) {
                User user = (User) principle;
                vo.setUserId(user.getId());
            }
        }
    }
}
Also used : User(com.serotonin.m2m2.vo.User) Authentication(org.springframework.security.core.Authentication) SecurityContext(org.springframework.security.core.context.SecurityContext)

Example 5 with MangoSessionDataVO

use of com.serotonin.m2m2.vo.MangoSessionDataVO 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

MangoSessionDataVO (com.serotonin.m2m2.vo.MangoSessionDataVO)5 User (com.serotonin.m2m2.vo.User)4 SecurityContext (org.springframework.security.core.context.SecurityContext)2 SessionLoadedEvent (com.infiniteautomation.mango.spring.events.SessionLoadedEvent)1 Date (java.util.Date)1 SessionData (org.eclipse.jetty.server.session.SessionData)1 Authentication (org.springframework.security.core.Authentication)1