Search in sources :

Example 36 with PermissionHolder

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

the class MaintenanceEventsService method update.

@Override
protected MaintenanceEventVO update(MaintenanceEventVO existing, MaintenanceEventVO vo) throws PermissionException, ValidationException {
    PermissionHolder user = Common.getUser();
    ensureEditPermission(user, existing);
    vo.setId(existing.getId());
    ensureValid(existing, vo);
    RTMDefinition.instance.saveMaintenanceEvent(vo);
    return vo;
}
Also used : PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 37 with PermissionHolder

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

the class MaintenanceEventsService method delete.

/**
 * Delete an event
 */
@Override
protected MaintenanceEventVO delete(MaintenanceEventVO vo) throws PermissionException, NotFoundException {
    PermissionHolder user = Common.getUser();
    ensureEditPermission(user, vo);
    RTMDefinition.instance.deleteMaintenanceEvent(vo.getId());
    return vo;
}
Also used : PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 38 with PermissionHolder

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

the class TemporaryResourceManager method newTemporaryResource.

/**
 * Creates a new temporary resource, how the task is executed depends on the manager implementation.
 *
 * @param resourceType unique type string assigned to each resource type e.g. BULK_DATA_POINT
 * @param id if null will be assigned a UUID
 * @param expiration time after the resource completes that it will be removed (milliseconds). If null or less than zero, it will be set to the default DEFAULT_EXPIRATION_MILLISECONDS
 * @param timeout time after the resource starts that it will be timeout if not complete (milliseconds). If null or less than zero, it will be set to the default DEFAULT_TIMEOUT_MILLISECONDS
 * @param task the task to be run
 */
public final TemporaryResource<T, E> newTemporaryResource(String resourceType, String id, Long expiration, Long timeout, ResourceTask<T, E> task) {
    if (expiration == null || expiration < 0) {
        expiration = Common.getMillis(Common.TIME_PERIOD_CODES.getId(environment.getProperty("rest.temporaryResource.expirationPeriodType", "HOURS")), environment.getProperty("rest.temporaryResource.expirationPeriods", Integer.class, 4));
    }
    if (timeout == null || timeout < 0) {
        timeout = Common.getMillis(Common.TIME_PERIOD_CODES.getId(environment.getProperty("rest.temporaryResource.timeoutPeriodType", "HOURS")), environment.getProperty("rest.temporaryResource.timeoutPeriods", Integer.class, 3));
    }
    PermissionHolder user = Common.getUser();
    TemporaryResource<T, E> resource = new TemporaryResource<T, E>(resourceType, id, user, expiration, timeout, task, this);
    synchronized (resource) {
        this.add(resource);
        resource.schedule();
        return resource;
    }
}
Also used : PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 39 with PermissionHolder

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

the class UserModelMapping method map.

@Override
public UserModel map(Object o, PermissionHolder currentUser, RestModelMapper mapper) {
    User user = (User) o;
    UserModel model = new UserModel(user);
    List<LinkedAccountModel> linkedAccounts = usersService.getLinkedAccounts(user).stream().map(account -> mapper.map(account, LinkedAccountModel.class, currentUser)).collect(Collectors.toList());
    model.setLinkedAccounts(linkedAccounts);
    return model;
}
Also used : List(java.util.List) Component(org.springframework.stereotype.Component) RestModelMapping(com.infiniteautomation.mango.rest.latest.model.RestModelMapping) UsersService(com.infiniteautomation.mango.spring.service.UsersService) Autowired(org.springframework.beans.factory.annotation.Autowired) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) Collectors(java.util.stream.Collectors) User(com.serotonin.m2m2.vo.User) RestModelMapper(com.infiniteautomation.mango.rest.latest.model.RestModelMapper) User(com.serotonin.m2m2.vo.User)

Example 40 with PermissionHolder

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

the class MangoWebSocketHandler method afterConnectionEstablished.

@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
    PermissionHolder user = getUser(session);
    if (!permissionService.hasPermission(user, requiredPermission())) {
        session.close(MangoWebSocketHandler.NOT_AUTHORIZED);
        return;
    }
    // Used to close the socket after user's HttpSession is invalidated or when the authentication token expires.
    this.sessionTracker.afterConnectionEstablished(session);
    if (this.pingPongTimeoutMs > 0) {
        this.startPingPong(session);
    }
}
Also used : PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Aggregations

PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)120 ApiOperation (io.swagger.annotations.ApiOperation)97 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)97 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)64 ResponseEntity (org.springframework.http.ResponseEntity)53 HttpHeaders (org.springframework.http.HttpHeaders)50 URI (java.net.URI)48 ArrayList (java.util.ArrayList)37 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)34 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)29 List (java.util.List)27 User (com.serotonin.m2m2.vo.User)25 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)24 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)24 BadRequestException (com.infiniteautomation.mango.rest.latest.exception.BadRequestException)19 HashMap (java.util.HashMap)19 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)18 Common (com.serotonin.m2m2.Common)18 Collectors (java.util.stream.Collectors)17 Role (com.serotonin.m2m2.vo.role.Role)16