diff --git a/application/src/main/java/org/thingsboard/server/controller/CustomerController.java b/application/src/main/java/org/thingsboard/server/controller/CustomerController.java index 091eb0edce..ec1149656b 100644 --- a/application/src/main/java/org/thingsboard/server/controller/CustomerController.java +++ b/application/src/main/java/org/thingsboard/server/controller/CustomerController.java @@ -56,11 +56,7 @@ public class CustomerController extends BaseController { ObjectMapper objectMapper = new ObjectMapper(); ObjectNode infoObject = objectMapper.createObjectNode(); infoObject.put("title", customer.getTitle()); - boolean isPublic = false; - if (customer.getAdditionalInfo() != null && customer.getAdditionalInfo().has("isPublic")) { - isPublic = customer.getAdditionalInfo().get("isPublic").asBoolean(); - } - infoObject.put("isPublic", isPublic); + infoObject.put("isPublic", customer.isPublic()); return infoObject; } catch (Exception e) { throw handleException(e); diff --git a/application/src/main/java/org/thingsboard/server/service/security/auth/jwt/RefreshTokenAuthenticationProvider.java b/application/src/main/java/org/thingsboard/server/service/security/auth/jwt/RefreshTokenAuthenticationProvider.java index 811f39f5d1..be5e546aaf 100644 --- a/application/src/main/java/org/thingsboard/server/service/security/auth/jwt/RefreshTokenAuthenticationProvider.java +++ b/application/src/main/java/org/thingsboard/server/service/security/auth/jwt/RefreshTokenAuthenticationProvider.java @@ -103,13 +103,11 @@ public class RefreshTokenAuthenticationProvider implements AuthenticationProvide if (publicCustomer == null) { throw new UsernameNotFoundException("Public entity not found by refresh token"); } - boolean isPublic = false; - if (publicCustomer.getAdditionalInfo() != null && publicCustomer.getAdditionalInfo().has("isPublic")) { - isPublic = publicCustomer.getAdditionalInfo().get("isPublic").asBoolean(); - } - if (!isPublic) { + + if (!publicCustomer.isPublic()) { throw new BadCredentialsException("Refresh token is not valid"); } + User user = new User(new UserId(UUIDBased.EMPTY)); user.setTenantId(publicCustomer.getTenantId()); user.setCustomerId(publicCustomer.getId()); diff --git a/application/src/main/java/org/thingsboard/server/service/security/auth/rest/RestAuthenticationProvider.java b/application/src/main/java/org/thingsboard/server/service/security/auth/rest/RestAuthenticationProvider.java index af10674294..661502319b 100644 --- a/application/src/main/java/org/thingsboard/server/service/security/auth/rest/RestAuthenticationProvider.java +++ b/application/src/main/java/org/thingsboard/server/service/security/auth/rest/RestAuthenticationProvider.java @@ -108,11 +108,7 @@ public class RestAuthenticationProvider implements AuthenticationProvider { if (publicCustomer == null) { throw new UsernameNotFoundException("Public entity not found: " + publicId); } - boolean isPublic = false; - if (publicCustomer.getAdditionalInfo() != null && publicCustomer.getAdditionalInfo().has("isPublic")) { - isPublic = publicCustomer.getAdditionalInfo().get("isPublic").asBoolean(); - } - if (!isPublic) { + if (!publicCustomer.isPublic()) { throw new BadCredentialsException("Authentication Failed. Public Id is not valid."); } User user = new User(new UserId(UUIDBased.EMPTY)); diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/Customer.java b/common/data/src/main/java/org/thingsboard/server/common/data/Customer.java index ec535bf44c..bdf38bd9dc 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/Customer.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/Customer.java @@ -60,6 +60,14 @@ public class Customer extends ContactBased implements HasName { public void setTitle(String title) { this.title = title; } + + public boolean isPublic() { + if (getAdditionalInfo() != null && getAdditionalInfo().has("isPublic")) { + return getAdditionalInfo().get("isPublic").asBoolean(); + } + + return false; + } @Override @JsonProperty(access = Access.READ_ONLY)