Commit 864a98fd8b1f95e7b22d765ff357504357aedb6e

Authored by Andrii Shvaika
2 parents 71f94358 d9bfd829

Merge branch 'master' of github.com:thingsboard/thingsboard

Showing 23 changed files with 240 additions and 127 deletions
... ... @@ -5,7 +5,7 @@
5 5 "94715984-ae74-76e4-20b7-2f956b01ed80": {
6 6 "isSystemType": true,
7 7 "bundleAlias": "entity_admin_widgets",
8   - "typeAlias": "device_admin_table2",
  8 + "typeAlias": "device_admin_table",
9 9 "type": "latest",
10 10 "title": "New widget",
11 11 "sizeX": 24,
... ... @@ -1271,4 +1271,4 @@
1271 1271 }
1272 1272 },
1273 1273 "name": "Gateways"
1274   -}
\ No newline at end of file
  1274 +}
... ...
... ... @@ -6,7 +6,7 @@
6 6 },
7 7 "widgetTypes": [
8 8 {
9   - "alias": "device_admin_table2",
  9 + "alias": "device_admin_table",
10 10 "name": "Device admin table",
11 11 "descriptor": {
12 12 "type": "latest",
... ... @@ -22,7 +22,7 @@
22 22 }
23 23 },
24 24 {
25   - "alias": "device_admin_table",
  25 + "alias": "asset_admin_table",
26 26 "name": "Asset admin table",
27 27 "descriptor": {
28 28 "type": "latest",
... ...
... ... @@ -79,11 +79,18 @@ public class ThingsboardSecurityConfiguration extends WebSecurityConfigurerAdapt
79 79 @Qualifier("oauth2AuthenticationSuccessHandler")
80 80 private AuthenticationSuccessHandler oauth2AuthenticationSuccessHandler;
81 81
  82 + @Autowired(required = false)
  83 + @Qualifier("oauth2AuthenticationFailureHandler")
  84 + private AuthenticationFailureHandler oauth2AuthenticationFailureHandler;
  85 +
82 86 @Autowired
83 87 @Qualifier("defaultAuthenticationSuccessHandler")
84 88 private AuthenticationSuccessHandler successHandler;
85 89
86   - @Autowired private AuthenticationFailureHandler failureHandler;
  90 + @Autowired
  91 + @Qualifier("defaultAuthenticationFailureHandler")
  92 + private AuthenticationFailureHandler failureHandler;
  93 +
87 94 @Autowired private RestAuthenticationProvider restAuthenticationProvider;
88 95 @Autowired private JwtAuthenticationProvider jwtAuthenticationProvider;
89 96 @Autowired private RefreshTokenAuthenticationProvider refreshTokenAuthenticationProvider;
... ... @@ -204,11 +211,11 @@ public class ThingsboardSecurityConfiguration extends WebSecurityConfigurerAdapt
204 211 http.oauth2Login()
205 212 .loginPage("/oauth2Login")
206 213 .loginProcessingUrl(oauth2Configuration.getLoginProcessingUrl())
207   - .successHandler(oauth2AuthenticationSuccessHandler);
  214 + .successHandler(oauth2AuthenticationSuccessHandler)
  215 + .failureHandler(oauth2AuthenticationFailureHandler);
208 216 }
209 217 }
210 218
211   -
212 219 @Bean
213 220 @ConditionalOnMissingBean(CorsFilter.class)
214 221 public CorsFilter corsFilter(@Autowired MvcCorsProperties mvcCorsProperties) {
... ...
... ... @@ -52,6 +52,7 @@ import org.thingsboard.server.service.security.model.UserPrincipal;
52 52 import org.thingsboard.server.service.security.model.token.JwtToken;
53 53 import org.thingsboard.server.service.security.model.token.JwtTokenFactory;
54 54 import org.thingsboard.server.service.security.system.SystemSecurityService;
  55 +import org.thingsboard.server.utils.MiscUtils;
55 56 import ua_parser.Client;
56 57
57 58 import javax.servlet.http.HttpServletRequest;
... ... @@ -170,7 +171,7 @@ public class AuthController extends BaseController {
170 171 try {
171 172 String email = resetPasswordByEmailRequest.get("email").asText();
172 173 UserCredentials userCredentials = userService.requestPasswordReset(TenantId.SYS_TENANT_ID, email);
173   - String baseUrl = constructBaseUrl(request);
  174 + String baseUrl = MiscUtils.constructBaseUrl(request);
174 175 String resetUrl = String.format("%s/api/noauth/resetPassword?resetToken=%s", baseUrl,
175 176 userCredentials.getResetToken());
176 177
... ... @@ -218,7 +219,7 @@ public class AuthController extends BaseController {
218 219 User user = userService.findUserById(TenantId.SYS_TENANT_ID, credentials.getUserId());
219 220 UserPrincipal principal = new UserPrincipal(UserPrincipal.Type.USER_NAME, user.getEmail());
220 221 SecurityUser securityUser = new SecurityUser(user, credentials.isEnabled(), principal);
221   - String baseUrl = constructBaseUrl(request);
  222 + String baseUrl = MiscUtils.constructBaseUrl(request);
222 223 String loginUrl = String.format("%s/login", baseUrl);
223 224 String email = user.getEmail();
224 225
... ... @@ -265,7 +266,7 @@ public class AuthController extends BaseController {
265 266 User user = userService.findUserById(TenantId.SYS_TENANT_ID, userCredentials.getUserId());
266 267 UserPrincipal principal = new UserPrincipal(UserPrincipal.Type.USER_NAME, user.getEmail());
267 268 SecurityUser securityUser = new SecurityUser(user, userCredentials.isEnabled(), principal);
268   - String baseUrl = constructBaseUrl(request);
  269 + String baseUrl = MiscUtils.constructBaseUrl(request);
269 270 String loginUrl = String.format("%s/login", baseUrl);
270 271 String email = user.getEmail();
271 272 mailService.sendPasswordWasResetEmail(loginUrl, email);
... ...
... ... @@ -521,39 +521,6 @@ public abstract class BaseController {
521 521 return ruleNode;
522 522 }
523 523
524   -
525   - protected String constructBaseUrl(HttpServletRequest request) {
526   - String scheme = request.getScheme();
527   -
528   - String forwardedProto = request.getHeader("x-forwarded-proto");
529   - if (forwardedProto != null) {
530   - scheme = forwardedProto;
531   - }
532   -
533   - int serverPort = request.getServerPort();
534   - if (request.getHeader("x-forwarded-port") != null) {
535   - try {
536   - serverPort = request.getIntHeader("x-forwarded-port");
537   - } catch (NumberFormatException e) {
538   - }
539   - } else if (forwardedProto != null) {
540   - switch (forwardedProto) {
541   - case "http":
542   - serverPort = 80;
543   - break;
544   - case "https":
545   - serverPort = 443;
546   - break;
547   - }
548   - }
549   -
550   - String baseUrl = String.format("%s://%s:%d",
551   - scheme,
552   - request.getServerName(),
553   - serverPort);
554   - return baseUrl;
555   - }
556   -
557 524 protected <I extends EntityId> I emptyId(EntityType entityType) {
558 525 return (I) EntityIdFactory.getByTypeAndUuid(entityType, ModelConstants.NULL_UUID);
559 526 }
... ...
... ... @@ -52,6 +52,7 @@ import org.thingsboard.server.service.security.model.token.JwtToken;
52 52 import org.thingsboard.server.service.security.model.token.JwtTokenFactory;
53 53 import org.thingsboard.server.service.security.permission.Operation;
54 54 import org.thingsboard.server.service.security.permission.Resource;
  55 +import org.thingsboard.server.utils.MiscUtils;
55 56
56 57 import javax.servlet.http.HttpServletRequest;
57 58
... ... @@ -148,7 +149,7 @@ public class UserController extends BaseController {
148 149 if (sendEmail) {
149 150 SecurityUser authUser = getCurrentUser();
150 151 UserCredentials userCredentials = userService.findUserCredentialsByUserId(authUser.getTenantId(), savedUser.getId());
151   - String baseUrl = constructBaseUrl(request);
  152 + String baseUrl = MiscUtils.constructBaseUrl(request);
152 153 String activateUrl = String.format(ACTIVATE_URL_PATTERN, baseUrl,
153 154 userCredentials.getActivateToken());
154 155 String email = savedUser.getEmail();
... ... @@ -188,7 +189,7 @@ public class UserController extends BaseController {
188 189
189 190 UserCredentials userCredentials = userService.findUserCredentialsByUserId(getCurrentUser().getTenantId(), user.getId());
190 191 if (!userCredentials.isEnabled()) {
191   - String baseUrl = constructBaseUrl(request);
  192 + String baseUrl = MiscUtils.constructBaseUrl(request);
192 193 String activateUrl = String.format(ACTIVATE_URL_PATTERN, baseUrl,
193 194 userCredentials.getActivateToken());
194 195 mailService.sendActivationEmail(activateUrl, email);
... ... @@ -213,7 +214,7 @@ public class UserController extends BaseController {
213 214 SecurityUser authUser = getCurrentUser();
214 215 UserCredentials userCredentials = userService.findUserCredentialsByUserId(authUser.getTenantId(), user.getId());
215 216 if (!userCredentials.isEnabled()) {
216   - String baseUrl = constructBaseUrl(request);
  217 + String baseUrl = MiscUtils.constructBaseUrl(request);
217 218 String activateUrl = String.format(ACTIVATE_URL_PATTERN, baseUrl,
218 219 userCredentials.getActivateToken());
219 220 return activateUrl;
... ...
... ... @@ -19,6 +19,7 @@ import lombok.extern.slf4j.Slf4j;
19 19 import org.springframework.beans.factory.annotation.Autowired;
20 20 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
21 21 import org.springframework.security.core.userdetails.UsernameNotFoundException;
  22 +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
22 23 import org.springframework.util.StringUtils;
23 24 import org.thingsboard.server.common.data.Customer;
24 25 import org.thingsboard.server.common.data.Tenant;
... ... @@ -27,13 +28,16 @@ import org.thingsboard.server.common.data.id.CustomerId;
27 28 import org.thingsboard.server.common.data.id.TenantId;
28 29 import org.thingsboard.server.common.data.page.TextPageLink;
29 30 import org.thingsboard.server.common.data.security.Authority;
  31 +import org.thingsboard.server.common.data.security.UserCredentials;
30 32 import org.thingsboard.server.dao.customer.CustomerService;
31 33 import org.thingsboard.server.dao.oauth2.OAuth2User;
32 34 import org.thingsboard.server.dao.tenant.TenantService;
33 35 import org.thingsboard.server.dao.user.UserService;
  36 +import org.thingsboard.server.service.install.InstallScripts;
34 37 import org.thingsboard.server.service.security.model.SecurityUser;
35 38 import org.thingsboard.server.service.security.model.UserPrincipal;
36 39
  40 +import java.io.IOException;
37 41 import java.util.List;
38 42 import java.util.Optional;
39 43 import java.util.concurrent.locks.Lock;
... ... @@ -46,14 +50,20 @@ public abstract class AbstractOAuth2ClientMapper {
46 50 private UserService userService;
47 51
48 52 @Autowired
  53 + private BCryptPasswordEncoder passwordEncoder;
  54 +
  55 + @Autowired
49 56 private TenantService tenantService;
50 57
51 58 @Autowired
52 59 private CustomerService customerService;
53 60
  61 + @Autowired
  62 + private InstallScripts installScripts;
  63 +
54 64 private final Lock userCreationLock = new ReentrantLock();
55 65
56   - protected SecurityUser getOrCreateSecurityUserFromOAuth2User(OAuth2User oauth2User, boolean allowUserCreation) {
  66 + protected SecurityUser getOrCreateSecurityUserFromOAuth2User(OAuth2User oauth2User, boolean allowUserCreation, boolean activateUser) {
57 67 UserPrincipal principal = new UserPrincipal(UserPrincipal.Type.USER_NAME, oauth2User.getEmail());
58 68
59 69 User user = userService.findUserByEmail(TenantId.SYS_TENANT_ID, oauth2User.getEmail());
... ... @@ -83,7 +93,14 @@ public abstract class AbstractOAuth2ClientMapper {
83 93 user.setFirstName(oauth2User.getFirstName());
84 94 user.setLastName(oauth2User.getLastName());
85 95 user = userService.saveUser(user);
  96 + if (activateUser) {
  97 + UserCredentials userCredentials = userService.findUserCredentialsByUserId(user.getTenantId(), user.getId());
  98 + userService.activateUserCredentials(user.getTenantId(), userCredentials.getActivateToken(), passwordEncoder.encode(""));
  99 + }
86 100 }
  101 + } catch (Exception e) {
  102 + log.error("Can't get or create security user from oauth2 user", e);
  103 + throw new RuntimeException("Can't get or create security user from oauth2 user", e);
87 104 } finally {
88 105 userCreationLock.unlock();
89 106 }
... ... @@ -98,13 +115,14 @@ public abstract class AbstractOAuth2ClientMapper {
98 115 }
99 116 }
100 117
101   - private TenantId getTenantId(String tenantName) {
  118 + private TenantId getTenantId(String tenantName) throws IOException {
102 119 List<Tenant> tenants = tenantService.findTenants(new TextPageLink(1, tenantName)).getData();
103 120 Tenant tenant;
104 121 if (tenants == null || tenants.isEmpty()) {
105 122 tenant = new Tenant();
106 123 tenant.setTitle(tenantName);
107 124 tenant = tenantService.saveTenant(tenant);
  125 + installScripts.createDefaultRuleChains(tenant.getId());
108 126 } else {
109 127 tenant = tenants.get(0);
110 128 }
... ...
... ... @@ -56,7 +56,8 @@ public class BasicOAuth2ClientMapper extends AbstractOAuth2ClientMapper implemen
56 56 String customerName = sub.replace(config.getBasic().getCustomerNamePattern());
57 57 oauth2User.setCustomerName(customerName);
58 58 }
59   - return getOrCreateSecurityUserFromOAuth2User(oauth2User, config.getBasic().isAllowUserCreation());
  59 +
  60 + return getOrCreateSecurityUserFromOAuth2User(oauth2User, config.isAllowUserCreation(), config.isActivateUser());
60 61 }
61 62
62 63 private String getTenantName(Map<String, Object> attributes, OAuth2ClientMapperConfig config) {
... ...
... ... @@ -38,7 +38,7 @@ public class CustomOAuth2ClientMapper extends AbstractOAuth2ClientMapper impleme
38 38 @Override
39 39 public SecurityUser getOrCreateUserByClientPrincipal(OAuth2AuthenticationToken token, OAuth2ClientMapperConfig config) {
40 40 OAuth2User oauth2User = getOAuth2User(token, config.getCustom());
41   - return getOrCreateSecurityUserFromOAuth2User(oauth2User, config.getBasic().isAllowUserCreation());
  41 + return getOrCreateSecurityUserFromOAuth2User(oauth2User, config.isAllowUserCreation(), config.isActivateUser());
42 42 }
43 43
44 44 private synchronized OAuth2User getOAuth2User(OAuth2AuthenticationToken token, OAuth2ClientMapperConfig.CustomOAuth2ClientMapperConfig custom) {
... ...
  1 +/**
  2 + * Copyright © 2016-2020 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.service.security.auth.oauth2;
  17 +
  18 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  19 +import org.springframework.security.core.AuthenticationException;
  20 +import org.springframework.security.web.authentication.SimpleUrlAuthenticationFailureHandler;
  21 +import org.springframework.stereotype.Component;
  22 +import org.thingsboard.server.utils.MiscUtils;
  23 +
  24 +import javax.servlet.ServletException;
  25 +import javax.servlet.http.HttpServletRequest;
  26 +import javax.servlet.http.HttpServletResponse;
  27 +import java.io.IOException;
  28 +import java.net.URLEncoder;
  29 +import java.nio.charset.StandardCharsets;
  30 +
  31 +@Component(value = "oauth2AuthenticationFailureHandler")
  32 +@ConditionalOnProperty(prefix = "security.oauth2", value = "enabled", havingValue = "true")
  33 +public class Oauth2AuthenticationFailureHandler extends SimpleUrlAuthenticationFailureHandler {
  34 +
  35 + @Override
  36 + public void onAuthenticationFailure(HttpServletRequest request,
  37 + HttpServletResponse response, AuthenticationException exception)
  38 + throws IOException, ServletException {
  39 + String baseUrl = MiscUtils.constructBaseUrl(request);
  40 + getRedirectStrategy().sendRedirect(request, response, baseUrl + "/login?loginError=" +
  41 + URLEncoder.encode(exception.getMessage(), StandardCharsets.UTF_8.toString()));
  42 + }
  43 +}
... ...
... ... @@ -27,6 +27,7 @@ import org.thingsboard.server.service.security.auth.jwt.RefreshTokenRepository;
27 27 import org.thingsboard.server.service.security.model.SecurityUser;
28 28 import org.thingsboard.server.service.security.model.token.JwtToken;
29 29 import org.thingsboard.server.service.security.model.token.JwtTokenFactory;
  30 +import org.thingsboard.server.utils.MiscUtils;
30 31
31 32 import javax.servlet.http.HttpServletRequest;
32 33 import javax.servlet.http.HttpServletResponse;
... ... @@ -65,6 +66,7 @@ public class Oauth2AuthenticationSuccessHandler extends SimpleUrlAuthenticationS
65 66 JwtToken accessToken = tokenFactory.createAccessJwtToken(securityUser);
66 67 JwtToken refreshToken = refreshTokenRepository.requestRefreshToken(securityUser);
67 68
68   - getRedirectStrategy().sendRedirect(request, response, "/?accessToken=" + accessToken.getToken() + "&refreshToken=" + refreshToken.getToken());
  69 + String baseUrl = MiscUtils.constructBaseUrl(request);
  70 + getRedirectStrategy().sendRedirect(request, response, baseUrl + "/?accessToken=" + accessToken.getToken() + "&refreshToken=" + refreshToken.getToken());
69 71 }
70 72 }
\ No newline at end of file
... ...
... ... @@ -26,7 +26,7 @@ import javax.servlet.http.HttpServletRequest;
26 26 import javax.servlet.http.HttpServletResponse;
27 27 import java.io.IOException;
28 28
29   -@Component
  29 +@Component(value = "defaultAuthenticationFailureHandler")
30 30 public class RestAwareAuthenticationFailureHandler implements AuthenticationFailureHandler {
31 31
32 32 private final ThingsboardErrorResponseHandler errorResponseHandler;
... ...
... ... @@ -18,8 +18,8 @@ package org.thingsboard.server.utils;
18 18 import com.google.common.hash.HashFunction;
19 19 import com.google.common.hash.Hashing;
20 20
  21 +import javax.servlet.http.HttpServletRequest;
21 22 import java.nio.charset.Charset;
22   -import java.util.Random;
23 23
24 24
25 25 /**
... ... @@ -47,4 +47,36 @@ public class MiscUtils {
47 47 throw new IllegalArgumentException("Can't find hash function with name " + name);
48 48 }
49 49 }
  50 +
  51 + public static String constructBaseUrl(HttpServletRequest request) {
  52 + String scheme = request.getScheme();
  53 +
  54 + String forwardedProto = request.getHeader("x-forwarded-proto");
  55 + if (forwardedProto != null) {
  56 + scheme = forwardedProto;
  57 + }
  58 +
  59 + int serverPort = request.getServerPort();
  60 + if (request.getHeader("x-forwarded-port") != null) {
  61 + try {
  62 + serverPort = request.getIntHeader("x-forwarded-port");
  63 + } catch (NumberFormatException e) {
  64 + }
  65 + } else if (forwardedProto != null) {
  66 + switch (forwardedProto) {
  67 + case "http":
  68 + serverPort = 80;
  69 + break;
  70 + case "https":
  71 + serverPort = 443;
  72 + break;
  73 + }
  74 + }
  75 +
  76 + String baseUrl = String.format("%s://%s:%d",
  77 + scheme,
  78 + request.getServerName(),
  79 + serverPort);
  80 + return baseUrl;
  81 + }
50 82 }
... ...
... ... @@ -100,34 +100,54 @@ security:
100 100 basic:
101 101 enabled: "${SECURITY_BASIC_ENABLED:false}"
102 102 oauth2:
  103 + # Enable/disable OAuth 2 login functionality
  104 + # For details please refer to https://thingsboard.io/docs/user-guide/oauth-2-support/
103 105 enabled: "${SECURITY_OAUTH2_ENABLED:false}"
  106 + # Redirect URL where access code from external user management system will be processed
104 107 loginProcessingUrl: "${SECURITY_OAUTH2_LOGIN_PROCESSING_URL:/login/oauth2/code/}"
  108 + # List of SSO clients
105 109 clients:
106 110 default:
107   - loginButtonLabel: "${SECURITY_OAUTH2_DEFAULT_LOGIN_BUTTON_LABEL:Default}" # Label that going to be show on login screen
108   - loginButtonIcon: "${SECURITY_OAUTH2_DEFAULT_LOGIN_BUTTON_ICON:}" # Icon that going to be show on login screen. Material design icon ID (https://material.angularjs.org/latest/api/directive/mdIcon)
  111 + # Label that going to be show on login button - 'Login with {loginButtonLabel}'
  112 + loginButtonLabel: "${SECURITY_OAUTH2_DEFAULT_LOGIN_BUTTON_LABEL:Default}"
  113 + # Icon that going to be show on login button. Material design icon ID (https://material.angularjs.org/latest/api/directive/mdIcon)
  114 + loginButtonIcon: "${SECURITY_OAUTH2_DEFAULT_LOGIN_BUTTON_ICON:}"
109 115 clientName: "${SECURITY_OAUTH2_DEFAULT_CLIENT_NAME:ClientName}"
110 116 clientId: "${SECURITY_OAUTH2_DEFAULT_CLIENT_ID:}"
111 117 clientSecret: "${SECURITY_OAUTH2_DEFAULT_CLIENT_SECRET:}"
112 118 accessTokenUri: "${SECURITY_OAUTH2_DEFAULT_ACCESS_TOKEN_URI:}"
113 119 authorizationUri: "${SECURITY_OAUTH2_DEFAULT_AUTHORIZATION_URI:}"
114 120 scope: "${SECURITY_OAUTH2_DEFAULT_SCOPE:}"
115   - redirectUriTemplate: "${SECURITY_OAUTH2_DEFAULT_REDIRECT_URI_TEMPLATE:http://localhost:8080/login/oauth2/code/}" # Must be in sync with security.oauth2.loginProcessingUrl
  121 + # Redirect URL that must be in sync with 'security.oauth2.loginProcessingUrl', but domain name added
  122 + redirectUriTemplate: "${SECURITY_OAUTH2_DEFAULT_REDIRECT_URI_TEMPLATE:http://localhost:8080/login/oauth2/code/}"
116 123 jwkSetUri: "${SECURITY_OAUTH2_DEFAULT_JWK_SET_URI:}"
117   - authorizationGrantType: "${SECURITY_OAUTH2_DEFAULT_AUTHORIZATION_GRANT_TYPE:authorization_code}" # authorization_code, implicit, refresh_token or client_credentials
  124 + # 'authorization_code', 'implicit', 'refresh_token' or 'client_credentials'
  125 + authorizationGrantType: "${SECURITY_OAUTH2_DEFAULT_AUTHORIZATION_GRANT_TYPE:authorization_code}"
118 126 clientAuthenticationMethod: "${SECURITY_OAUTH2_DEFAULT_CLIENT_AUTHENTICATION_METHOD:post}" # basic or post
119 127 userInfoUri: "${SECURITY_OAUTH2_DEFAULT_USER_INFO_URI:}"
120 128 userNameAttributeName: "${SECURITY_OAUTH2_DEFAULT_USER_NAME_ATTRIBUTE_NAME:email}"
121 129 mapperConfig:
122   - type: "${SECURITY_OAUTH2_DEFAULT_MAPPER_TYPE:basic}" # basic or custom
  130 + # Allows to create user if it not exists
  131 + allowUserCreation: "${SECURITY_OAUTH2_DEFAULT_MAPPER_ALLOW_USER_CREATION:true}"
  132 + # Allows user to setup ThingsBoard internal password and login over default Login window
  133 + activateUser: "${SECURITY_OAUTH2_DEFAULT_MAPPER_ACTIVATE_USER:false}"
  134 + # Mapper type of converter from external user into internal - 'basic' or 'custom'
  135 + type: "${SECURITY_OAUTH2_DEFAULT_MAPPER_TYPE:basic}"
123 136 basic:
124   - allowUserCreation: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_ALLOW_USER_CREATION:true}" # Allows to create user if it not exists
125   - emailAttributeKey: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_EMAIL_ATTRIBUTE_KEY:email}" # Attribute key to use as email for the user
  137 + # Key from attributes of external user object to use as email
  138 + emailAttributeKey: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_EMAIL_ATTRIBUTE_KEY:email}"
126 139 firstNameAttributeKey: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_FIRST_NAME_ATTRIBUTE_KEY:}"
127 140 lastNameAttributeKey: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_LAST_NAME_ATTRIBUTE_KEY:}"
128   - tenantNameStrategy: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_TENANT_NAME_STRATEGY:domain}" # domain, email or custom
129   - tenantNamePattern: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_TENANT_NAME_PATTERN:}" # %{attribute_key} as placeholder for attributes value by key
130   - customerNamePattern: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_CUSTOMER_NAME_PATTERN:}" # %{attribute_key} as placeholder for attributes value by key
  141 + # Strategy for generating Tenant from external user object - 'domain', 'email' or 'custom'
  142 + # 'domain' - name of the Tenant will be extracted as domain from the email of the user
  143 + # 'email' - name of the Tenant will email of the user
  144 + # 'custom' - please configure 'tenantNamePattern' for custom mapping
  145 + tenantNameStrategy: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_TENANT_NAME_STRATEGY:domain}"
  146 + # %{attribute_key} as placeholder for attribute value of attributes of external user object
  147 + tenantNamePattern: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_TENANT_NAME_PATTERN:}"
  148 + # If this field is not empty, user will be created as a user under defined Customer
  149 + # %{attribute_key} as placeholder for attribute value of attributes of external user object
  150 + customerNamePattern: "${SECURITY_OAUTH2_DEFAULT_MAPPER_BASIC_CUSTOMER_NAME_PATTERN:}"
131 151 custom:
132 152 url: "${SECURITY_OAUTH2_DEFAULT_MAPPER_CUSTOM_URL:}"
133 153 username: "${SECURITY_OAUTH2_DEFAULT_MAPPER_CUSTOM_USERNAME:}"
... ...
... ... @@ -20,13 +20,14 @@ import lombok.Data;
20 20 @Data
21 21 public class OAuth2ClientMapperConfig {
22 22
  23 + private boolean allowUserCreation;
  24 + private boolean activateUser;
23 25 private String type;
24 26 private BasicOAuth2ClientMapperConfig basic;
25 27 private CustomOAuth2ClientMapperConfig custom;
26 28
27 29 @Data
28 30 public static class BasicOAuth2ClientMapperConfig {
29   - private boolean allowUserCreation;
30 31 private String emailAttributeKey;
31 32 private String firstNameAttributeKey;
32 33 private String lastNameAttributeKey;
... ...
... ... @@ -468,11 +468,23 @@
468 468 <groupId>org.springframework.security</groupId>
469 469 <artifactId>spring-security-oauth2-client</artifactId>
470 470 <version>${spring-security.version}</version>
  471 + <exclusions>
  472 + <exclusion>
  473 + <groupId>org.springframework</groupId>
  474 + <artifactId>spring-core</artifactId>
  475 + </exclusion>
  476 + </exclusions>
471 477 </dependency>
472 478 <dependency>
473 479 <groupId>org.springframework.security</groupId>
474 480 <artifactId>spring-security-oauth2-jose</artifactId>
475 481 <version>${spring-security.version}</version>
  482 + <exclusions>
  483 + <exclusion>
  484 + <groupId>org.springframework</groupId>
  485 + <artifactId>spring-core</artifactId>
  486 + </exclusion>
  487 + </exclusions>
476 488 </dependency>
477 489 <dependency>
478 490 <groupId>org.springframework.boot</groupId>
... ...
... ... @@ -20,7 +20,6 @@ import com.google.common.cache.CacheLoader;
20 20 import com.google.common.cache.LoadingCache;
21 21 import com.google.common.util.concurrent.Futures;
22 22 import com.google.common.util.concurrent.ListenableFuture;
23   -import com.google.common.util.concurrent.MoreExecutors;
24 23 import lombok.AllArgsConstructor;
25 24 import lombok.Data;
26 25 import lombok.NoArgsConstructor;
... ... @@ -78,7 +77,8 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA
78 77
79 78 @Override
80 79 public void onMsg(TbContext ctx, TbMsg msg) {
81   - withCallback(processEntityRelationAction(ctx, msg),
  80 + String relationType = processPattern(msg, config.getRelationType());
  81 + withCallback(processEntityRelationAction(ctx, msg, relationType),
82 82 filterResult -> ctx.tellNext(filterResult.getMsg(), filterResult.isResult() ? SUCCESS : FAILURE), t -> ctx.tellFailure(msg, t), ctx.getDbCallbackExecutor());
83 83 }
84 84
... ... @@ -86,13 +86,13 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA
86 86 public void destroy() {
87 87 }
88 88
89   - protected ListenableFuture<RelationContainer> processEntityRelationAction(TbContext ctx, TbMsg msg) {
90   - return Futures.transformAsync(getEntity(ctx, msg), entityContainer -> doProcessEntityRelationAction(ctx, msg, entityContainer), MoreExecutors.directExecutor());
  89 + protected ListenableFuture<RelationContainer> processEntityRelationAction(TbContext ctx, TbMsg msg, String relationType) {
  90 + return Futures.transformAsync(getEntity(ctx, msg), entityContainer -> doProcessEntityRelationAction(ctx, msg, entityContainer, relationType), ctx.getDbCallbackExecutor());
91 91 }
92 92
93 93 protected abstract boolean createEntityIfNotExists();
94 94
95   - protected abstract ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entityContainer);
  95 + protected abstract ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entityContainer, String relationType);
96 96
97 97 protected abstract C loadEntityNodeActionConfig(TbNodeConfiguration configuration) throws TbNodeException;
98 98
... ... @@ -120,11 +120,11 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA
120 120 if (EntitySearchDirection.FROM.name().equals(this.config.getDirection())) {
121 121 searchDirectionIds.setFromId(EntityIdFactory.getByTypeAndId(entityContainer.getEntityType().name(), entityContainer.getEntityId().toString()));
122 122 searchDirectionIds.setToId(msg.getOriginator());
123   - searchDirectionIds.setOrignatorDirectionFrom(false);
  123 + searchDirectionIds.setOriginatorDirectionFrom(false);
124 124 } else {
125 125 searchDirectionIds.setToId(EntityIdFactory.getByTypeAndId(entityContainer.getEntityType().name(), entityContainer.getEntityId().toString()));
126 126 searchDirectionIds.setFromId(msg.getOriginator());
127   - searchDirectionIds.setOrignatorDirectionFrom(true);
  127 + searchDirectionIds.setOriginatorDirectionFrom(true);
128 128 }
129 129 return searchDirectionIds;
130 130 }
... ... @@ -153,7 +153,7 @@ public abstract class TbAbstractRelationActionNode<C extends TbAbstractRelationA
153 153 protected static class SearchDirectionIds {
154 154 private EntityId fromId;
155 155 private EntityId toId;
156   - private boolean orignatorDirectionFrom;
  156 + private boolean originatorDirectionFrom;
157 157 }
158 158
159 159 private static class EntityCacheLoader extends CacheLoader<EntityKey, EntityContainer> {
... ...
... ... @@ -17,7 +17,6 @@ package org.thingsboard.rule.engine.action;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
20   -import com.google.common.util.concurrent.MoreExecutors;
21 20 import lombok.extern.slf4j.Slf4j;
22 21 import org.thingsboard.rule.engine.api.RuleNode;
23 22 import org.thingsboard.rule.engine.api.TbContext;
... ... @@ -57,8 +56,6 @@ import java.util.List;
57 56 )
58 57 public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateRelationNodeConfiguration> {
59 58
60   - private String relationType;
61   -
62 59 @Override
63 60 protected TbCreateRelationNodeConfiguration loadEntityNodeActionConfig(TbNodeConfiguration configuration) throws TbNodeException {
64 61 return TbNodeUtils.convert(configuration, TbCreateRelationNodeConfiguration.class);
... ... @@ -70,8 +67,8 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
70 67 }
71 68
72 69 @Override
73   - protected ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entity) {
74   - ListenableFuture<Boolean> future = createIfAbsent(ctx, msg, entity);
  70 + protected ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entity, String relationType) {
  71 + ListenableFuture<Boolean> future = createIfAbsent(ctx, msg, entity, relationType);
75 72 return Futures.transform(future, result -> {
76 73 RelationContainer container = new RelationContainer();
77 74 if (result && config.isChangeOriginatorToRelatedEntity()) {
... ... @@ -82,16 +79,15 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
82 79 }
83 80 container.setResult(result);
84 81 return container;
85   - }, MoreExecutors.directExecutor());
  82 + }, ctx.getDbCallbackExecutor());
86 83 }
87 84
88   - private ListenableFuture<Boolean> createIfAbsent(TbContext ctx, TbMsg msg, EntityContainer entityContainer) {
89   - relationType = processPattern(msg, config.getRelationType());
  85 + private ListenableFuture<Boolean> createIfAbsent(TbContext ctx, TbMsg msg, EntityContainer entityContainer, String relationType) {
90 86 SearchDirectionIds sdId = processSingleSearchDirection(msg, entityContainer);
91 87 ListenableFuture<Boolean> checkRelationFuture = Futures.transformAsync(ctx.getRelationService().checkRelation(ctx.getTenantId(), sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON), result -> {
92 88 if (!result) {
93 89 if (config.isRemoveCurrentRelations()) {
94   - return processDeleteRelations(ctx, processFindRelations(ctx, msg, sdId));
  90 + return processDeleteRelations(ctx, processFindRelations(ctx, msg, sdId, relationType));
95 91 }
96 92 return Futures.immediateFuture(false);
97 93 }
... ... @@ -100,14 +96,14 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
100 96
101 97 return Futures.transformAsync(checkRelationFuture, result -> {
102 98 if (!result) {
103   - return processCreateRelation(ctx, entityContainer, sdId);
  99 + return processCreateRelation(ctx, entityContainer, sdId, relationType);
104 100 }
105 101 return Futures.immediateFuture(true);
106 102 }, ctx.getDbCallbackExecutor());
107 103 }
108 104
109   - private ListenableFuture<List<EntityRelation>> processFindRelations(TbContext ctx, TbMsg msg, SearchDirectionIds sdId) {
110   - if (sdId.isOrignatorDirectionFrom()) {
  105 + private ListenableFuture<List<EntityRelation>> processFindRelations(TbContext ctx, TbMsg msg, SearchDirectionIds sdId, String relationType) {
  106 + if (sdId.isOriginatorDirectionFrom()) {
111 107 return ctx.getRelationService().findByFromAndTypeAsync(ctx.getTenantId(), msg.getOriginator(), relationType, RelationTypeGroup.COMMON);
112 108 } else {
113 109 return ctx.getRelationService().findByToAndTypeAsync(ctx.getTenantId(), msg.getOriginator(), relationType, RelationTypeGroup.COMMON);
... ... @@ -121,91 +117,91 @@ public class TbCreateRelationNode extends TbAbstractRelationActionNode<TbCreateR
121 117 for (EntityRelation relation : entityRelations) {
122 118 list.add(ctx.getRelationService().deleteRelationAsync(ctx.getTenantId(), relation));
123 119 }
124   - return Futures.transform(Futures.allAsList(list), result -> false, MoreExecutors.directExecutor());
  120 + return Futures.transform(Futures.allAsList(list), result -> false, ctx.getDbCallbackExecutor());
125 121 }
126 122 return Futures.immediateFuture(false);
127 123 }, ctx.getDbCallbackExecutor());
128 124 }
129 125
130   - private ListenableFuture<Boolean> processCreateRelation(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
  126 + private ListenableFuture<Boolean> processCreateRelation(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
131 127 switch (entityContainer.getEntityType()) {
132 128 case ASSET:
133   - return processAsset(ctx, entityContainer, sdId);
  129 + return processAsset(ctx, entityContainer, sdId, relationType);
134 130 case DEVICE:
135   - return processDevice(ctx, entityContainer, sdId);
  131 + return processDevice(ctx, entityContainer, sdId, relationType);
136 132 case CUSTOMER:
137   - return processCustomer(ctx, entityContainer, sdId);
  133 + return processCustomer(ctx, entityContainer, sdId, relationType);
138 134 case DASHBOARD:
139   - return processDashboard(ctx, entityContainer, sdId);
  135 + return processDashboard(ctx, entityContainer, sdId, relationType);
140 136 case ENTITY_VIEW:
141   - return processView(ctx, entityContainer, sdId);
  137 + return processView(ctx, entityContainer, sdId, relationType);
142 138 case TENANT:
143   - return processTenant(ctx, entityContainer, sdId);
  139 + return processTenant(ctx, entityContainer, sdId, relationType);
144 140 }
145 141 return Futures.immediateFuture(true);
146 142 }
147 143
148   - private ListenableFuture<Boolean> processView(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
  144 + private ListenableFuture<Boolean> processView(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
149 145 return Futures.transformAsync(ctx.getEntityViewService().findEntityViewByIdAsync(ctx.getTenantId(), new EntityViewId(entityContainer.getEntityId().getId())), entityView -> {
150 146 if (entityView != null) {
151   - return processSave(ctx, sdId);
  147 + return processSave(ctx, sdId, relationType);
152 148 } else {
153 149 return Futures.immediateFuture(true);
154 150 }
155 151 }, ctx.getDbCallbackExecutor());
156 152 }
157 153
158   - private ListenableFuture<Boolean> processDevice(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
  154 + private ListenableFuture<Boolean> processDevice(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
159 155 return Futures.transformAsync(ctx.getDeviceService().findDeviceByIdAsync(ctx.getTenantId(), new DeviceId(entityContainer.getEntityId().getId())), device -> {
160 156 if (device != null) {
161   - return processSave(ctx, sdId);
  157 + return processSave(ctx, sdId, relationType);
162 158 } else {
163 159 return Futures.immediateFuture(true);
164 160 }
165   - }, MoreExecutors.directExecutor());
  161 + }, ctx.getDbCallbackExecutor());
166 162 }
167 163
168   - private ListenableFuture<Boolean> processAsset(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
  164 + private ListenableFuture<Boolean> processAsset(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
169 165 return Futures.transformAsync(ctx.getAssetService().findAssetByIdAsync(ctx.getTenantId(), new AssetId(entityContainer.getEntityId().getId())), asset -> {
170 166 if (asset != null) {
171   - return processSave(ctx, sdId);
  167 + return processSave(ctx, sdId, relationType);
172 168 } else {
173 169 return Futures.immediateFuture(true);
174 170 }
175 171 }, ctx.getDbCallbackExecutor());
176 172 }
177 173
178   - private ListenableFuture<Boolean> processCustomer(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
  174 + private ListenableFuture<Boolean> processCustomer(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
179 175 return Futures.transformAsync(ctx.getCustomerService().findCustomerByIdAsync(ctx.getTenantId(), new CustomerId(entityContainer.getEntityId().getId())), customer -> {
180 176 if (customer != null) {
181   - return processSave(ctx, sdId);
  177 + return processSave(ctx, sdId, relationType);
182 178 } else {
183 179 return Futures.immediateFuture(true);
184 180 }
185 181 }, ctx.getDbCallbackExecutor());
186 182 }
187 183
188   - private ListenableFuture<Boolean> processDashboard(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
  184 + private ListenableFuture<Boolean> processDashboard(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
189 185 return Futures.transformAsync(ctx.getDashboardService().findDashboardByIdAsync(ctx.getTenantId(), new DashboardId(entityContainer.getEntityId().getId())), dashboard -> {
190 186 if (dashboard != null) {
191   - return processSave(ctx, sdId);
  187 + return processSave(ctx, sdId, relationType);
192 188 } else {
193 189 return Futures.immediateFuture(true);
194 190 }
195 191 }, ctx.getDbCallbackExecutor());
196 192 }
197 193
198   - private ListenableFuture<Boolean> processTenant(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId) {
  194 + private ListenableFuture<Boolean> processTenant(TbContext ctx, EntityContainer entityContainer, SearchDirectionIds sdId, String relationType) {
199 195 return Futures.transformAsync(ctx.getTenantService().findTenantByIdAsync(ctx.getTenantId(), new TenantId(entityContainer.getEntityId().getId())), tenant -> {
200 196 if (tenant != null) {
201   - return processSave(ctx, sdId);
  197 + return processSave(ctx, sdId, relationType);
202 198 } else {
203 199 return Futures.immediateFuture(true);
204 200 }
205 201 }, ctx.getDbCallbackExecutor());
206 202 }
207 203
208   - private ListenableFuture<Boolean> processSave(TbContext ctx, SearchDirectionIds sdId) {
  204 + private ListenableFuture<Boolean> processSave(TbContext ctx, SearchDirectionIds sdId, String relationType) {
209 205 return ctx.getRelationService().saveRelationAsync(ctx.getTenantId(), new EntityRelation(sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON));
210 206 }
211 207
... ...
... ... @@ -17,7 +17,6 @@ package org.thingsboard.rule.engine.action;
17 17
18 18 import com.google.common.util.concurrent.Futures;
19 19 import com.google.common.util.concurrent.ListenableFuture;
20   -import com.google.common.util.concurrent.MoreExecutors;
21 20 import lombok.extern.slf4j.Slf4j;
22 21 import org.thingsboard.rule.engine.api.RuleNode;
23 22 import org.thingsboard.rule.engine.api.TbContext;
... ... @@ -48,8 +47,6 @@ import java.util.List;
48 47 )
49 48 public class TbDeleteRelationNode extends TbAbstractRelationActionNode<TbDeleteRelationNodeConfiguration> {
50 49
51   - private String relationType;
52   -
53 50 @Override
54 51 protected TbDeleteRelationNodeConfiguration loadEntityNodeActionConfig(TbNodeConfiguration configuration) throws TbNodeException {
55 52 return TbNodeUtils.convert(configuration, TbDeleteRelationNodeConfiguration.class);
... ... @@ -61,21 +58,20 @@ public class TbDeleteRelationNode extends TbAbstractRelationActionNode<TbDeleteR
61 58 }
62 59
63 60 @Override
64   - protected ListenableFuture<RelationContainer> processEntityRelationAction(TbContext ctx, TbMsg msg) {
65   - return getRelationContainerListenableFuture(ctx, msg);
  61 + protected ListenableFuture<RelationContainer> processEntityRelationAction(TbContext ctx, TbMsg msg, String relationType) {
  62 + return getRelationContainerListenableFuture(ctx, msg, relationType);
66 63 }
67 64
68 65 @Override
69   - protected ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entityContainer) {
70   - return Futures.transform(processSingle(ctx, msg, entityContainer), result -> new RelationContainer(msg, result), MoreExecutors.directExecutor());
  66 + protected ListenableFuture<RelationContainer> doProcessEntityRelationAction(TbContext ctx, TbMsg msg, EntityContainer entityContainer, String relationType) {
  67 + return Futures.transform(processSingle(ctx, msg, entityContainer, relationType), result -> new RelationContainer(msg, result), ctx.getDbCallbackExecutor());
71 68 }
72 69
73   - private ListenableFuture<RelationContainer> getRelationContainerListenableFuture(TbContext ctx, TbMsg msg) {
74   - relationType = processPattern(msg, config.getRelationType());
  70 + private ListenableFuture<RelationContainer> getRelationContainerListenableFuture(TbContext ctx, TbMsg msg, String relationType) {
75 71 if (config.isDeleteForSingleEntity()) {
76   - return Futures.transformAsync(getEntity(ctx, msg), entityContainer -> doProcessEntityRelationAction(ctx, msg, entityContainer), MoreExecutors.directExecutor());
  72 + return Futures.transformAsync(getEntity(ctx, msg), entityContainer -> doProcessEntityRelationAction(ctx, msg, entityContainer, relationType), ctx.getDbCallbackExecutor());
77 73 } else {
78   - return Futures.transform(processList(ctx, msg), result -> new RelationContainer(msg, result), MoreExecutors.directExecutor());
  74 + return Futures.transform(processList(ctx, msg), result -> new RelationContainer(msg, result), ctx.getDbCallbackExecutor());
79 75 }
80 76 }
81 77
... ... @@ -95,23 +91,23 @@ public class TbDeleteRelationNode extends TbAbstractRelationActionNode<TbDeleteR
95 91 }
96 92 }
97 93 return Futures.immediateFuture(true);
98   - }, MoreExecutors.directExecutor());
  94 + }, ctx.getDbCallbackExecutor());
99 95 }
100   - }, MoreExecutors.directExecutor());
  96 + }, ctx.getDbCallbackExecutor());
101 97 }
102 98
103   - private ListenableFuture<Boolean> processSingle(TbContext ctx, TbMsg msg, EntityContainer entityContainer) {
  99 + private ListenableFuture<Boolean> processSingle(TbContext ctx, TbMsg msg, EntityContainer entityContainer, String relationType) {
104 100 SearchDirectionIds sdId = processSingleSearchDirection(msg, entityContainer);
105 101 return Futures.transformAsync(ctx.getRelationService().checkRelation(ctx.getTenantId(), sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON),
106 102 result -> {
107 103 if (result) {
108   - return processSingleDeleteRelation(ctx, sdId);
  104 + return processSingleDeleteRelation(ctx, sdId, relationType);
109 105 }
110 106 return Futures.immediateFuture(true);
111   - }, MoreExecutors.directExecutor());
  107 + }, ctx.getDbCallbackExecutor());
112 108 }
113 109
114   - private ListenableFuture<Boolean> processSingleDeleteRelation(TbContext ctx, SearchDirectionIds sdId) {
  110 + private ListenableFuture<Boolean> processSingleDeleteRelation(TbContext ctx, SearchDirectionIds sdId, String relationType) {
115 111 return ctx.getRelationService().deleteRelationAsync(ctx.getTenantId(), sdId.getFromId(), sdId.getToId(), relationType, RelationTypeGroup.COMMON);
116 112 }
117 113
... ...
... ... @@ -22,7 +22,7 @@ export default angular.module('thingsboard.api.user', [thingsboardApiLogin,
22 22 .name;
23 23
24 24 /*@ngInject*/
25   -function UserService($http, $q, $rootScope, adminService, dashboardService, timeService, loginService, toast, store, jwtHelper, $translate, $state, $location) {
  25 +function UserService($http, $q, $rootScope, adminService, dashboardService, timeService, loginService, toast, store, jwtHelper, $translate, $state, $location, $mdDialog) {
26 26 var currentUser = null,
27 27 currentUserDetails = null,
28 28 lastPublicDashboardId = null,
... ... @@ -406,6 +406,10 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, time
406 406 }, function fail() {
407 407 deferred.reject();
408 408 });
  409 + } else if (locationSearch.loginError) {
  410 + showLoginErrorDialog(locationSearch.loginError);
  411 + $location.search('loginError', null);
  412 + deferred.reject();
409 413 } else {
410 414 procceedJwtTokenValidate();
411 415 }
... ... @@ -415,6 +419,17 @@ function UserService($http, $q, $rootScope, adminService, dashboardService, time
415 419 return deferred.promise;
416 420 }
417 421
  422 + function showLoginErrorDialog(loginError) {
  423 + $translate(['login.error',
  424 + 'action.close']).then(function (translations) {
  425 + var alert = $mdDialog.alert()
  426 + .title(translations['login.error'])
  427 + .htmlContent(loginError)
  428 + .ok(translations['action.close']);
  429 + $mdDialog.show(alert);
  430 + });
  431 + }
  432 +
418 433 function loadIsUserTokenAccessEnabled() {
419 434 var deferred = $q.defer();
420 435 if (currentUser.authority === 'SYS_ADMIN' || currentUser.authority === 'TENANT_ADMIN') {
... ...
... ... @@ -1334,7 +1334,8 @@
1334 1334 "password-link-sent-message": "Password reset link was successfully sent!",
1335 1335 "email": "Email",
1336 1336 "login-with": "Login with {{name}}",
1337   - "or": "or"
  1337 + "or": "or",
  1338 + "error": "Login error"
1338 1339 },
1339 1340 "position": {
1340 1341 "top": "Top",
... ...
... ... @@ -51,7 +51,7 @@
51 51 <div class="text mat-typography">{{ "login.or" | translate | uppercase }}</div>
52 52 <div class="line"><md-divider></md-divider></div>
53 53 </div>
54   - <md-button ng-repeat="oauth2Client in oauth2Clients" class="md-raised"
  54 + <md-button ng-repeat="oauth2Client in oauth2Clients" class="md-raised md-accent md-hue-2"
55 55 layout="row" layout-align="center center" ng-href="{{ oauth2Client.url }}" target="_self">
56 56 <md-icon class="material-icons md-18" md-svg-icon="{{ oauth2Client.icon }}"></md-icon>
57 57 {{ 'login.login-with' | translate: {name: oauth2Client.name} }}
... ...
... ... @@ -94,7 +94,7 @@ export default class TbGoogleMap {
94 94 window[this.initMapFunctionName] = function() { // eslint-disable-line no-undef, angular/window-service
95 95 lazyLoad.load([ // eslint-disable-line no-undef
96 96 { type: 'js', path: 'https://unpkg.com/@google/markerwithlabel@1.2.3/src/markerwithlabel.js' },
97   - { type: 'js', path: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/markerclusterer.js' }
  97 + { type: 'js', path: 'https://unpkg.com/@google/markerclustererplus@4.0.1/dist/markerclustererplus.min.js' }
98 98 ]).then(
99 99 function success() {
100 100 gmGlobals.gmApiKeys[tbMap.apiKey].loaded = true;
... ...