Browse Source

Merge pull request #333 from eykamp/is_public

Centralize checking for whether customer is public
pull/342/merge
Igor Kulikov 9 years ago
committed by GitHub
parent
commit
84b0a8e24d
  1. 6
      application/src/main/java/org/thingsboard/server/controller/CustomerController.java
  2. 8
      application/src/main/java/org/thingsboard/server/service/security/auth/jwt/RefreshTokenAuthenticationProvider.java
  3. 6
      application/src/main/java/org/thingsboard/server/service/security/auth/rest/RestAuthenticationProvider.java
  4. 11
      common/data/src/main/java/org/thingsboard/server/common/data/Customer.java

6
application/src/main/java/org/thingsboard/server/controller/CustomerController.java

@ -59,11 +59,7 @@ public class CustomerController extends BaseController {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
ObjectNode infoObject = objectMapper.createObjectNode(); ObjectNode infoObject = objectMapper.createObjectNode();
infoObject.put("title", customer.getTitle()); infoObject.put("title", customer.getTitle());
boolean isPublic = false; infoObject.put(IS_PUBLIC, customer.isPublic());
if (customer.getAdditionalInfo() != null && customer.getAdditionalInfo().has(IS_PUBLIC)) {
isPublic = customer.getAdditionalInfo().get(IS_PUBLIC).asBoolean();
}
infoObject.put(IS_PUBLIC, isPublic);
return infoObject; return infoObject;
} catch (Exception e) { } catch (Exception e) {
throw handleException(e); throw handleException(e);

8
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) { if (publicCustomer == null) {
throw new UsernameNotFoundException("Public entity not found by refresh token"); throw new UsernameNotFoundException("Public entity not found by refresh token");
} }
boolean isPublic = false;
if (publicCustomer.getAdditionalInfo() != null && publicCustomer.getAdditionalInfo().has("isPublic")) { if (!publicCustomer.isPublic()) {
isPublic = publicCustomer.getAdditionalInfo().get("isPublic").asBoolean();
}
if (!isPublic) {
throw new BadCredentialsException("Refresh token is not valid"); throw new BadCredentialsException("Refresh token is not valid");
} }
User user = new User(new UserId(UUIDBased.EMPTY)); User user = new User(new UserId(UUIDBased.EMPTY));
user.setTenantId(publicCustomer.getTenantId()); user.setTenantId(publicCustomer.getTenantId());
user.setCustomerId(publicCustomer.getId()); user.setCustomerId(publicCustomer.getId());

6
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) { if (publicCustomer == null) {
throw new UsernameNotFoundException("Public entity not found: " + publicId); throw new UsernameNotFoundException("Public entity not found: " + publicId);
} }
boolean isPublic = false; if (!publicCustomer.isPublic()) {
if (publicCustomer.getAdditionalInfo() != null && publicCustomer.getAdditionalInfo().has("isPublic")) {
isPublic = publicCustomer.getAdditionalInfo().get("isPublic").asBoolean();
}
if (!isPublic) {
throw new BadCredentialsException("Authentication Failed. Public Id is not valid."); throw new BadCredentialsException("Authentication Failed. Public Id is not valid.");
} }
User user = new User(new UserId(UUIDBased.EMPTY)); User user = new User(new UserId(UUIDBased.EMPTY));

11
common/data/src/main/java/org/thingsboard/server/common/data/Customer.java

@ -15,6 +15,7 @@
*/ */
package org.thingsboard.server.common.data; package org.thingsboard.server.common.data;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonProperty.Access; import com.fasterxml.jackson.annotation.JsonProperty.Access;
import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.CustomerId;
@ -61,6 +62,15 @@ public class Customer extends ContactBased<CustomerId> implements HasName {
this.title = title; this.title = title;
} }
@JsonIgnore
public boolean isPublic() {
if (getAdditionalInfo() != null && getAdditionalInfo().has("isPublic")) {
return additionalInfo.get("isPublic").asBoolean();
}
return false;
}
@Override @Override
@JsonProperty(access = Access.READ_ONLY) @JsonProperty(access = Access.READ_ONLY)
public String getName() { public String getName() {
@ -149,5 +159,4 @@ public class Customer extends ContactBased<CustomerId> implements HasName {
builder.append("]"); builder.append("]");
return builder.toString(); return builder.toString();
} }
} }

Loading…
Cancel
Save