Browse Source
Merge pull request #11175 from AndriiLandiak/fix/edge-oauth
Fix Edge Oauth2 validation
pull/11045/head
Viacheslav Klimov
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with
8 additions and
2 deletions
-
application/src/main/java/org/thingsboard/server/service/edge/EdgeEventSourcingListener.java
-
application/src/main/java/org/thingsboard/server/service/edge/rpc/fetch/OAuth2EdgeEventFetcher.java
-
application/src/main/java/org/thingsboard/server/service/edge/rpc/processor/oauth2/OAuth2EdgeProcessor.java
|
|
|
@ -204,6 +204,9 @@ public class EdgeEventSourcingListener { |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
if (entity instanceof OAuth2Info oAuth2Info) { |
|
|
|
return oAuth2Info.isEdgeEnabled(); |
|
|
|
} |
|
|
|
// Default: If the entity doesn't match any of the conditions, consider it as valid.
|
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
@ -45,8 +45,11 @@ public class OAuth2EdgeEventFetcher implements EdgeEventFetcher { |
|
|
|
|
|
|
|
@Override |
|
|
|
public PageData<EdgeEvent> fetchEdgeEvents(TenantId tenantId, Edge edge, PageLink pageLink) { |
|
|
|
List<EdgeEvent> result = new ArrayList<>(); |
|
|
|
OAuth2Info oAuth2Info = oAuth2Service.findOAuth2Info(); |
|
|
|
if (!oAuth2Info.isEdgeEnabled()) { |
|
|
|
return new PageData<>(); |
|
|
|
} |
|
|
|
List<EdgeEvent> result = new ArrayList<>(); |
|
|
|
result.add(EdgeUtils.constructEdgeEvent(tenantId, edge.getId(), EdgeEventType.OAUTH2, |
|
|
|
EdgeEventActionType.ADDED, null, JacksonUtil.valueToTree(oAuth2Info))); |
|
|
|
// returns PageData object to be in sync with other fetchers
|
|
|
|
|
|
|
|
@ -40,7 +40,7 @@ public class OAuth2EdgeProcessor extends BaseEdgeProcessor { |
|
|
|
public DownlinkMsg convertOAuth2EventToDownlink(EdgeEvent edgeEvent) { |
|
|
|
DownlinkMsg downlinkMsg = null; |
|
|
|
OAuth2Info oAuth2Info = JacksonUtil.convertValue(edgeEvent.getBody(), OAuth2Info.class); |
|
|
|
if (oAuth2Info != null) { |
|
|
|
if (oAuth2Info != null && oAuth2Info.isEdgeEnabled()) { |
|
|
|
OAuth2UpdateMsg oAuth2UpdateMsg = oAuth2MsgConstructor.constructOAuth2UpdateMsg(oAuth2Info); |
|
|
|
downlinkMsg = DownlinkMsg.newBuilder() |
|
|
|
.setDownlinkMsgId(EdgeUtils.nextPositiveInt()) |
|
|
|
|