use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class MangoWebSocketHandshakeInterceptor method beforeHandshake.
@Override
public boolean beforeHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler wsHandler, Map<String, Object> attributes) throws Exception {
HttpSession session = getSession(request);
if (session != null) {
attributes.put(HTTP_SESSION_ID_ATTR, session.getId());
}
// get the user at the time of HTTP -> websocket upgrade
Principal principal = request.getPrincipal();
if (principal instanceof Authentication) {
Authentication authentication = (Authentication) principal;
attributes.put(AUTHENTICATION_ATTR, authentication);
Object authenticationPrincipal = authentication.getPrincipal();
if (authenticationPrincipal instanceof PermissionHolder) {
attributes.put(USER_ATTR, authenticationPrincipal);
}
}
return true;
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class TemporaryResourceWebSocketHandler method notifySession.
private void notifySession(WebSocketSession session, CrudNotificationType type, TemporaryResource<?, ?> resource) throws JsonProcessingException, IOException {
PermissionHolder user = this.getUser(session);
TemporaryResourceSubscription subscription = (TemporaryResourceSubscription) session.getAttributes().get(SUBSCRIPTION_ATTRIBUTE);
boolean hasAccess = permissionService.hasAccessToResource(user, resource);
boolean isOwner = resource.isOwnedBy(user);
if (hasAccess && (!subscription.isOwnResourcesOnly() || isOwner)) {
Set<TemporaryResourceStatus> statuses = subscription.getStatuses();
Set<String> resourceTypes = subscription.getResourceTypes();
if ((subscription.isAnyStatus() || statuses.contains(resource.getStatus())) && (subscription.isAnyResourceType() || resourceTypes.contains(resource.getResourceType()))) {
WebSocketNotification<TemporaryResource<?, ?>> notificationMessage = new WebSocketNotification<>(type, resource);
boolean showResult = !resource.isComplete() && subscription.isShowResultWhenIncomplete() || resource.isComplete() && subscription.isShowResultWhenComplete();
if (type == CrudNotificationType.DELETE) {
showResult = false;
}
Class<?> view = showResult ? TemporaryResourceViews.ShowResult.class : Object.class;
if (log.isTraceEnabled()) {
log.trace("Notifying session " + session.getId() + " of change to resource " + resource);
}
try {
this.sendRawMessageUsingView(session, notificationMessage, view);
} catch (Exception e) {
if (log.isWarnEnabled()) {
log.warn("Error notifying session " + session.getId() + " of change to resource " + resource, e);
}
}
}
}
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.
the class RoleModelMapping method map.
@Override
public RoleModel map(Object from, PermissionHolder user, RestModelMapper mapper) {
RoleVO role = (RoleVO) from;
RoleModel model = new RoleModel(role);
if (role.getInherited() != null) {
Set<String> inherited = new HashSet<>(role.getInherited().size());
model.setInherited(inherited);
for (Role inheritedRole : role.getInherited()) {
inherited.add(inheritedRole.getXid());
}
}
return model;
}
use of com.serotonin.m2m2.vo.permission.PermissionHolder 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.permission.PermissionHolder 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;
}
Aggregations