|
|
@ -26,11 +26,13 @@ import org.springframework.context.ApplicationEventPublisher; |
|
|
import org.springframework.http.HttpStatus; |
|
|
import org.springframework.http.HttpStatus; |
|
|
import org.springframework.security.access.prepost.PreAuthorize; |
|
|
import org.springframework.security.access.prepost.PreAuthorize; |
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal; |
|
|
import org.springframework.security.core.annotation.AuthenticationPrincipal; |
|
|
|
|
|
import org.springframework.web.bind.annotation.DeleteMapping; |
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
import org.springframework.web.bind.annotation.GetMapping; |
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
import org.springframework.web.bind.annotation.PathVariable; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
import org.springframework.web.bind.annotation.PostMapping; |
|
|
import org.springframework.web.bind.annotation.PutMapping; |
|
|
import org.springframework.web.bind.annotation.PutMapping; |
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
import org.springframework.web.bind.annotation.RequestBody; |
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestHeader; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMapping; |
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
import org.springframework.web.bind.annotation.RequestMethod; |
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
import org.springframework.web.bind.annotation.RequestParam; |
|
|
@ -42,7 +44,6 @@ import org.thingsboard.rule.engine.api.MailService; |
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
import org.thingsboard.server.common.data.EntityType; |
|
|
import org.thingsboard.server.common.data.User; |
|
|
import org.thingsboard.server.common.data.User; |
|
|
import org.thingsboard.server.common.data.UserEmailInfo; |
|
|
import org.thingsboard.server.common.data.UserEmailInfo; |
|
|
import org.thingsboard.server.common.data.UserMobileInfo; |
|
|
|
|
|
import org.thingsboard.server.common.data.alarm.Alarm; |
|
|
import org.thingsboard.server.common.data.alarm.Alarm; |
|
|
import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
|
|
import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
|
|
import org.thingsboard.server.common.data.exception.ThingsboardException; |
|
|
import org.thingsboard.server.common.data.exception.ThingsboardException; |
|
|
@ -51,6 +52,7 @@ import org.thingsboard.server.common.data.id.CustomerId; |
|
|
import org.thingsboard.server.common.data.id.DashboardId; |
|
|
import org.thingsboard.server.common.data.id.DashboardId; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.data.id.UserId; |
|
|
import org.thingsboard.server.common.data.id.UserId; |
|
|
|
|
|
import org.thingsboard.server.common.data.mobile.MobileSessionInfo; |
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
import org.thingsboard.server.common.data.page.PageLink; |
|
|
import org.thingsboard.server.common.data.query.EntityDataPageLink; |
|
|
import org.thingsboard.server.common.data.query.EntityDataPageLink; |
|
|
@ -83,7 +85,6 @@ import java.util.Arrays; |
|
|
import java.util.Collections; |
|
|
import java.util.Collections; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
import java.util.Map; |
|
|
import java.util.Map; |
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
|
|
|
import static org.thingsboard.server.common.data.query.EntityKeyType.ENTITY_FIELD; |
|
|
import static org.thingsboard.server.common.data.query.EntityKeyType.ENTITY_FIELD; |
|
|
import static org.thingsboard.server.controller.ControllerConstants.ALARM_ID_PARAM_DESCRIPTION; |
|
|
import static org.thingsboard.server.controller.ControllerConstants.ALARM_ID_PARAM_DESCRIPTION; |
|
|
@ -120,6 +121,7 @@ public class UserController extends BaseController { |
|
|
public static final String PATHS = "paths"; |
|
|
public static final String PATHS = "paths"; |
|
|
public static final String YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION = "You don't have permission to perform this operation!"; |
|
|
public static final String YOU_DON_T_HAVE_PERMISSION_TO_PERFORM_THIS_OPERATION = "You don't have permission to perform this operation!"; |
|
|
public static final String ACTIVATE_URL_PATTERN = "%s/api/noauth/activate?activateToken=%s"; |
|
|
public static final String ACTIVATE_URL_PATTERN = "%s/api/noauth/activate?activateToken=%s"; |
|
|
|
|
|
public static final String MOBILE_TOKEN_HEADER = "X-Mobile-Token"; |
|
|
|
|
|
|
|
|
@Value("${security.user_token_access_enabled}") |
|
|
@Value("${security.user_token_access_enabled}") |
|
|
private boolean userTokenAccessEnabled; |
|
|
private boolean userTokenAccessEnabled; |
|
|
@ -588,17 +590,25 @@ public class UserController extends BaseController { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
@GetMapping("/user/mobile/info") |
|
|
@GetMapping("/user/mobile/session") |
|
|
public UserMobileInfo getMobileInfo(@AuthenticationPrincipal SecurityUser securityUser) { |
|
|
public MobileSessionInfo getMobileSession(@RequestHeader(MOBILE_TOKEN_HEADER) String mobileToken, |
|
|
return Optional.ofNullable(userService.findMobileInfo(securityUser.getTenantId(), securityUser.getId())) |
|
|
@AuthenticationPrincipal SecurityUser user) { |
|
|
.orElseGet(UserMobileInfo::new); |
|
|
return userService.findMobileSession(user.getTenantId(), user.getId(), mobileToken); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
@PostMapping("/user/mobile/info") |
|
|
@PostMapping("/user/mobile/session") |
|
|
public void saveMobileInfo(@RequestBody UserMobileInfo mobileInfo, |
|
|
public void saveMobileSession(@RequestBody MobileSessionInfo sessionInfo, |
|
|
@AuthenticationPrincipal SecurityUser securityUser) { |
|
|
@RequestHeader(MOBILE_TOKEN_HEADER) String mobileToken, |
|
|
userService.saveMobileInfo(securityUser.getTenantId(), securityUser.getId(), mobileInfo); |
|
|
@AuthenticationPrincipal SecurityUser user) { |
|
|
|
|
|
userService.saveMobileSession(user.getTenantId(), user.getId(), mobileToken, sessionInfo); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')") |
|
|
|
|
|
@DeleteMapping("/user/mobile/session") |
|
|
|
|
|
public void removeMobileSession(@RequestHeader(MOBILE_TOKEN_HEADER) String mobileToken, |
|
|
|
|
|
@AuthenticationPrincipal SecurityUser user) { |
|
|
|
|
|
userService.removeMobileSession(user.getTenantId(), mobileToken); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private void checkNotReserved(String strType, UserSettingsType type) throws ThingsboardException { |
|
|
private void checkNotReserved(String strType, UserSettingsType type) throws ThingsboardException { |
|
|
|