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;
}
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;
}
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;
}
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());
}
}
}
}
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;
}
Aggregations