433 changed files with 18241 additions and 6688 deletions
File diff suppressed because it is too large
@ -0,0 +1,24 @@ |
|||
{ |
|||
"providerId": "Apple", |
|||
"additionalInfo": null, |
|||
"accessTokenUri": "https://appleid.apple.com/auth/token", |
|||
"authorizationUri": "https://appleid.apple.com/auth/authorize?response_mode=form_post", |
|||
"scope": ["email","openid","name"], |
|||
"jwkSetUri": "https://appleid.apple.com/auth/keys", |
|||
"userInfoUri": null, |
|||
"clientAuthenticationMethod": "POST", |
|||
"userNameAttributeName": "email", |
|||
"mapperConfig": { |
|||
"type": "APPLE", |
|||
"basic": { |
|||
"emailAttributeKey": "email", |
|||
"firstNameAttributeKey": "firstName", |
|||
"lastNameAttributeKey": "lastName", |
|||
"tenantNameStrategy": "DOMAIN" |
|||
} |
|||
}, |
|||
"comment": null, |
|||
"loginButtonIcon": "apple-logo", |
|||
"loginButtonLabel": "Apple", |
|||
"helpLink": "https://developer.apple.com/sign-in-with-apple/get-started/" |
|||
} |
|||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,256 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.action; |
|||
|
|||
import com.fasterxml.jackson.databind.ObjectMapper; |
|||
import com.fasterxml.jackson.databind.node.ArrayNode; |
|||
import com.fasterxml.jackson.databind.node.ObjectNode; |
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.apache.commons.lang3.StringUtils; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.common.data.DataConstants; |
|||
import org.thingsboard.server.common.data.EntityType; |
|||
import org.thingsboard.server.common.data.HasName; |
|||
import org.thingsboard.server.common.data.HasTenantId; |
|||
import org.thingsboard.server.common.data.User; |
|||
import org.thingsboard.server.common.data.audit.ActionType; |
|||
import org.thingsboard.server.common.data.id.CustomerId; |
|||
import org.thingsboard.server.common.data.id.EntityId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.kv.AttributeKvEntry; |
|||
import org.thingsboard.server.common.data.kv.DataType; |
|||
import org.thingsboard.server.common.data.kv.KvEntry; |
|||
import org.thingsboard.server.common.data.kv.TsKvEntry; |
|||
import org.thingsboard.server.common.msg.TbMsg; |
|||
import org.thingsboard.server.common.msg.TbMsgDataType; |
|||
import org.thingsboard.server.common.msg.TbMsgMetaData; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.queue.TbClusterService; |
|||
|
|||
import java.util.List; |
|||
import java.util.Map; |
|||
import java.util.stream.Collectors; |
|||
|
|||
@TbCoreComponent |
|||
@Service |
|||
@RequiredArgsConstructor |
|||
@Slf4j |
|||
public class RuleEngineEntityActionService { |
|||
private final TbClusterService tbClusterService; |
|||
|
|||
private static final ObjectMapper json = new ObjectMapper(); |
|||
|
|||
public void pushEntityActionToRuleEngine(EntityId entityId, HasName entity, TenantId tenantId, CustomerId customerId, |
|||
ActionType actionType, User user, Object... additionalInfo) { |
|||
String msgType = null; |
|||
switch (actionType) { |
|||
case ADDED: |
|||
msgType = DataConstants.ENTITY_CREATED; |
|||
break; |
|||
case DELETED: |
|||
msgType = DataConstants.ENTITY_DELETED; |
|||
break; |
|||
case UPDATED: |
|||
msgType = DataConstants.ENTITY_UPDATED; |
|||
break; |
|||
case ASSIGNED_TO_CUSTOMER: |
|||
msgType = DataConstants.ENTITY_ASSIGNED; |
|||
break; |
|||
case UNASSIGNED_FROM_CUSTOMER: |
|||
msgType = DataConstants.ENTITY_UNASSIGNED; |
|||
break; |
|||
case ATTRIBUTES_UPDATED: |
|||
msgType = DataConstants.ATTRIBUTES_UPDATED; |
|||
break; |
|||
case ATTRIBUTES_DELETED: |
|||
msgType = DataConstants.ATTRIBUTES_DELETED; |
|||
break; |
|||
case ALARM_ACK: |
|||
msgType = DataConstants.ALARM_ACK; |
|||
break; |
|||
case ALARM_CLEAR: |
|||
msgType = DataConstants.ALARM_CLEAR; |
|||
break; |
|||
case ALARM_DELETE: |
|||
msgType = DataConstants.ALARM_DELETE; |
|||
break; |
|||
case ASSIGNED_FROM_TENANT: |
|||
msgType = DataConstants.ENTITY_ASSIGNED_FROM_TENANT; |
|||
break; |
|||
case ASSIGNED_TO_TENANT: |
|||
msgType = DataConstants.ENTITY_ASSIGNED_TO_TENANT; |
|||
break; |
|||
case PROVISION_SUCCESS: |
|||
msgType = DataConstants.PROVISION_SUCCESS; |
|||
break; |
|||
case PROVISION_FAILURE: |
|||
msgType = DataConstants.PROVISION_FAILURE; |
|||
break; |
|||
case TIMESERIES_UPDATED: |
|||
msgType = DataConstants.TIMESERIES_UPDATED; |
|||
break; |
|||
case TIMESERIES_DELETED: |
|||
msgType = DataConstants.TIMESERIES_DELETED; |
|||
break; |
|||
case ASSIGNED_TO_EDGE: |
|||
msgType = DataConstants.ENTITY_ASSIGNED_TO_EDGE; |
|||
break; |
|||
case UNASSIGNED_FROM_EDGE: |
|||
msgType = DataConstants.ENTITY_UNASSIGNED_FROM_EDGE; |
|||
break; |
|||
} |
|||
if (!StringUtils.isEmpty(msgType)) { |
|||
try { |
|||
TbMsgMetaData metaData = new TbMsgMetaData(); |
|||
if (user != null) { |
|||
metaData.putValue("userId", user.getId().toString()); |
|||
metaData.putValue("userName", user.getName()); |
|||
} |
|||
if (customerId != null && !customerId.isNullUid()) { |
|||
metaData.putValue("customerId", customerId.toString()); |
|||
} |
|||
if (actionType == ActionType.ASSIGNED_TO_CUSTOMER) { |
|||
String strCustomerId = extractParameter(String.class, 1, additionalInfo); |
|||
String strCustomerName = extractParameter(String.class, 2, additionalInfo); |
|||
metaData.putValue("assignedCustomerId", strCustomerId); |
|||
metaData.putValue("assignedCustomerName", strCustomerName); |
|||
} else if (actionType == ActionType.UNASSIGNED_FROM_CUSTOMER) { |
|||
String strCustomerId = extractParameter(String.class, 1, additionalInfo); |
|||
String strCustomerName = extractParameter(String.class, 2, additionalInfo); |
|||
metaData.putValue("unassignedCustomerId", strCustomerId); |
|||
metaData.putValue("unassignedCustomerName", strCustomerName); |
|||
} else if (actionType == ActionType.ASSIGNED_FROM_TENANT) { |
|||
String strTenantId = extractParameter(String.class, 0, additionalInfo); |
|||
String strTenantName = extractParameter(String.class, 1, additionalInfo); |
|||
metaData.putValue("assignedFromTenantId", strTenantId); |
|||
metaData.putValue("assignedFromTenantName", strTenantName); |
|||
} else if (actionType == ActionType.ASSIGNED_TO_TENANT) { |
|||
String strTenantId = extractParameter(String.class, 0, additionalInfo); |
|||
String strTenantName = extractParameter(String.class, 1, additionalInfo); |
|||
metaData.putValue("assignedToTenantId", strTenantId); |
|||
metaData.putValue("assignedToTenantName", strTenantName); |
|||
} else if (actionType == ActionType.ASSIGNED_TO_EDGE) { |
|||
String strEdgeId = extractParameter(String.class, 1, additionalInfo); |
|||
String strEdgeName = extractParameter(String.class, 2, additionalInfo); |
|||
metaData.putValue("assignedEdgeId", strEdgeId); |
|||
metaData.putValue("assignedEdgeName", strEdgeName); |
|||
} else if (actionType == ActionType.UNASSIGNED_FROM_EDGE) { |
|||
String strEdgeId = extractParameter(String.class, 1, additionalInfo); |
|||
String strEdgeName = extractParameter(String.class, 2, additionalInfo); |
|||
metaData.putValue("unassignedEdgeId", strEdgeId); |
|||
metaData.putValue("unassignedEdgeName", strEdgeName); |
|||
} |
|||
ObjectNode entityNode; |
|||
if (entity != null) { |
|||
entityNode = json.valueToTree(entity); |
|||
if (entityId.getEntityType() == EntityType.DASHBOARD) { |
|||
entityNode.put("configuration", ""); |
|||
} |
|||
} else { |
|||
entityNode = json.createObjectNode(); |
|||
if (actionType == ActionType.ATTRIBUTES_UPDATED) { |
|||
String scope = extractParameter(String.class, 0, additionalInfo); |
|||
@SuppressWarnings("unchecked") |
|||
List<AttributeKvEntry> attributes = extractParameter(List.class, 1, additionalInfo); |
|||
metaData.putValue(DataConstants.SCOPE, scope); |
|||
if (attributes != null) { |
|||
for (AttributeKvEntry attr : attributes) { |
|||
addKvEntry(entityNode, attr); |
|||
} |
|||
} |
|||
} else if (actionType == ActionType.ATTRIBUTES_DELETED) { |
|||
String scope = extractParameter(String.class, 0, additionalInfo); |
|||
@SuppressWarnings("unchecked") |
|||
List<String> keys = extractParameter(List.class, 1, additionalInfo); |
|||
metaData.putValue(DataConstants.SCOPE, scope); |
|||
ArrayNode attrsArrayNode = entityNode.putArray("attributes"); |
|||
if (keys != null) { |
|||
keys.forEach(attrsArrayNode::add); |
|||
} |
|||
} else if (actionType == ActionType.TIMESERIES_UPDATED) { |
|||
@SuppressWarnings("unchecked") |
|||
List<TsKvEntry> timeseries = extractParameter(List.class, 0, additionalInfo); |
|||
addTimeseries(entityNode, timeseries); |
|||
} else if (actionType == ActionType.TIMESERIES_DELETED) { |
|||
@SuppressWarnings("unchecked") |
|||
List<String> keys = extractParameter(List.class, 0, additionalInfo); |
|||
if (keys != null) { |
|||
ArrayNode timeseriesArrayNode = entityNode.putArray("timeseries"); |
|||
keys.forEach(timeseriesArrayNode::add); |
|||
} |
|||
entityNode.put("startTs", extractParameter(Long.class, 1, additionalInfo)); |
|||
entityNode.put("endTs", extractParameter(Long.class, 2, additionalInfo)); |
|||
} |
|||
} |
|||
TbMsg tbMsg = TbMsg.newMsg(msgType, entityId, customerId, metaData, TbMsgDataType.JSON, json.writeValueAsString(entityNode)); |
|||
if (tenantId.isNullUid()) { |
|||
if (entity instanceof HasTenantId) { |
|||
tenantId = ((HasTenantId) entity).getTenantId(); |
|||
} |
|||
} |
|||
tbClusterService.pushMsgToRuleEngine(tenantId, entityId, tbMsg, null); |
|||
} catch (Exception e) { |
|||
log.warn("[{}] Failed to push entity action to rule engine: {}", entityId, actionType, e); |
|||
} |
|||
} |
|||
} |
|||
|
|||
|
|||
private <T> T extractParameter(Class<T> clazz, int index, Object... additionalInfo) { |
|||
T result = null; |
|||
if (additionalInfo != null && additionalInfo.length > index) { |
|||
Object paramObject = additionalInfo[index]; |
|||
if (clazz.isInstance(paramObject)) { |
|||
result = clazz.cast(paramObject); |
|||
} |
|||
} |
|||
return result; |
|||
} |
|||
|
|||
private void addTimeseries(ObjectNode entityNode, List<TsKvEntry> timeseries) throws Exception { |
|||
if (timeseries != null && !timeseries.isEmpty()) { |
|||
ArrayNode result = entityNode.putArray("timeseries"); |
|||
Map<Long, List<TsKvEntry>> groupedTelemetry = timeseries.stream() |
|||
.collect(Collectors.groupingBy(TsKvEntry::getTs)); |
|||
for (Map.Entry<Long, List<TsKvEntry>> entry : groupedTelemetry.entrySet()) { |
|||
ObjectNode element = json.createObjectNode(); |
|||
element.put("ts", entry.getKey()); |
|||
ObjectNode values = element.putObject("values"); |
|||
for (TsKvEntry tsKvEntry : entry.getValue()) { |
|||
addKvEntry(values, tsKvEntry); |
|||
} |
|||
result.add(element); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void addKvEntry(ObjectNode entityNode, KvEntry kvEntry) throws Exception { |
|||
if (kvEntry.getDataType() == DataType.BOOLEAN) { |
|||
kvEntry.getBooleanValue().ifPresent(value -> entityNode.put(kvEntry.getKey(), value)); |
|||
} else if (kvEntry.getDataType() == DataType.DOUBLE) { |
|||
kvEntry.getDoubleValue().ifPresent(value -> entityNode.put(kvEntry.getKey(), value)); |
|||
} else if (kvEntry.getDataType() == DataType.LONG) { |
|||
kvEntry.getLongValue().ifPresent(value -> entityNode.put(kvEntry.getKey(), value)); |
|||
} else if (kvEntry.getDataType() == DataType.JSON) { |
|||
if (kvEntry.getJsonValue().isPresent()) { |
|||
entityNode.set(kvEntry.getKey(), json.readTree(kvEntry.getJsonValue().get())); |
|||
} |
|||
} else { |
|||
entityNode.put(kvEntry.getKey(), kvEntry.getValueAsString()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,101 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.security.auth.oauth2; |
|||
|
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken; |
|||
import org.springframework.stereotype.Service; |
|||
import org.springframework.util.LinkedMultiValueMap; |
|||
import org.springframework.util.MultiValueMap; |
|||
import org.springframework.util.StringUtils; |
|||
import org.thingsboard.common.util.JacksonUtil; |
|||
import org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig; |
|||
import org.thingsboard.server.common.data.oauth2.OAuth2Registration; |
|||
import org.thingsboard.server.dao.oauth2.OAuth2User; |
|||
import org.thingsboard.server.service.security.model.SecurityUser; |
|||
|
|||
import javax.servlet.http.HttpServletRequest; |
|||
import java.util.HashMap; |
|||
import java.util.Map; |
|||
|
|||
@Service(value = "appleOAuth2ClientMapper") |
|||
@Slf4j |
|||
public class AppleOAuth2ClientMapper extends AbstractOAuth2ClientMapper implements OAuth2ClientMapper { |
|||
|
|||
private static final String USER = "user"; |
|||
private static final String NAME = "name"; |
|||
private static final String FIRST_NAME = "firstName"; |
|||
private static final String LAST_NAME = "lastName"; |
|||
private static final String EMAIL = "email"; |
|||
|
|||
@Override |
|||
public SecurityUser getOrCreateUserByClientPrincipal(HttpServletRequest request, OAuth2AuthenticationToken token, String providerAccessToken, OAuth2Registration registration) { |
|||
OAuth2MapperConfig config = registration.getMapperConfig(); |
|||
Map<String, Object> attributes = updateAttributesFromRequestParams(request, token.getPrincipal().getAttributes()); |
|||
String email = BasicMapperUtils.getStringAttributeByKey(attributes, config.getBasic().getEmailAttributeKey()); |
|||
OAuth2User oauth2User = BasicMapperUtils.getOAuth2User(email, attributes, config); |
|||
|
|||
return getOrCreateSecurityUserFromOAuth2User(oauth2User, registration); |
|||
} |
|||
|
|||
private static Map<String, Object> updateAttributesFromRequestParams(HttpServletRequest request, Map<String, Object> attributes) { |
|||
Map<String, Object> updated = attributes; |
|||
MultiValueMap<String, String> params = toMultiMap(request.getParameterMap()); |
|||
String userValue = params.getFirst(USER); |
|||
if (StringUtils.hasText(userValue)) { |
|||
JsonNode user = null; |
|||
try { |
|||
user = JacksonUtil.toJsonNode(userValue); |
|||
} catch (Exception e) {} |
|||
if (user != null) { |
|||
updated = new HashMap<>(attributes); |
|||
if (user.has(NAME)) { |
|||
JsonNode name = user.get(NAME); |
|||
if (name.isObject()) { |
|||
JsonNode firstName = name.get(FIRST_NAME); |
|||
if (firstName != null && firstName.isTextual()) { |
|||
updated.put(FIRST_NAME, firstName.asText()); |
|||
} |
|||
JsonNode lastName = name.get(LAST_NAME); |
|||
if (lastName != null && lastName.isTextual()) { |
|||
updated.put(LAST_NAME, lastName.asText()); |
|||
} |
|||
} |
|||
} |
|||
if (user.has(EMAIL)) { |
|||
JsonNode email = user.get(EMAIL); |
|||
if (email != null && email.isTextual()) { |
|||
updated.put(EMAIL, email.asText()); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
return updated; |
|||
} |
|||
|
|||
private static MultiValueMap<String, String> toMultiMap(Map<String, String[]> map) { |
|||
MultiValueMap<String, String> params = new LinkedMultiValueMap<>(map.size()); |
|||
map.forEach((key, values) -> { |
|||
if (values.length > 0) { |
|||
for (String value : values) { |
|||
params.add(key, value); |
|||
} |
|||
} |
|||
}); |
|||
return params; |
|||
} |
|||
} |
|||
@ -0,0 +1,22 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.security.auth.oauth2; |
|||
|
|||
public interface TbOAuth2ParameterNames { |
|||
|
|||
String CALLBACK_URL_SCHEME = "callback_url_scheme"; |
|||
|
|||
} |
|||
@ -0,0 +1,69 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.security.model.token; |
|||
|
|||
import io.jsonwebtoken.Claims; |
|||
import io.jsonwebtoken.ExpiredJwtException; |
|||
import io.jsonwebtoken.Jws; |
|||
import io.jsonwebtoken.Jwts; |
|||
import io.jsonwebtoken.MalformedJwtException; |
|||
import io.jsonwebtoken.SignatureException; |
|||
import io.jsonwebtoken.UnsupportedJwtException; |
|||
import io.micrometer.core.instrument.util.StringUtils; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.stereotype.Component; |
|||
|
|||
import java.util.Date; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
@Component |
|||
@Slf4j |
|||
public class OAuth2AppTokenFactory { |
|||
|
|||
private static final String CALLBACK_URL_SCHEME = "callbackUrlScheme"; |
|||
|
|||
private static final long MAX_EXPIRATION_TIME_DIFF_MS = TimeUnit.MINUTES.toMillis(5); |
|||
|
|||
public String validateTokenAndGetCallbackUrlScheme(String appPackage, String appToken, String appSecret) { |
|||
Jws<Claims> jwsClaims; |
|||
try { |
|||
jwsClaims = Jwts.parser().setSigningKey(appSecret).parseClaimsJws(appToken); |
|||
} |
|||
catch (UnsupportedJwtException | MalformedJwtException | IllegalArgumentException | SignatureException ex) { |
|||
throw new IllegalArgumentException("Invalid Application token: ", ex); |
|||
} catch (ExpiredJwtException expiredEx) { |
|||
throw new IllegalArgumentException("Application token expired", expiredEx); |
|||
} |
|||
Claims claims = jwsClaims.getBody(); |
|||
Date expiration = claims.getExpiration(); |
|||
if (expiration == null) { |
|||
throw new IllegalArgumentException("Application token must have expiration date"); |
|||
} |
|||
long timeDiff = expiration.getTime() - System.currentTimeMillis(); |
|||
if (timeDiff > MAX_EXPIRATION_TIME_DIFF_MS) { |
|||
throw new IllegalArgumentException("Application token expiration time can't be longer than 5 minutes"); |
|||
} |
|||
if (!claims.getIssuer().equals(appPackage)) { |
|||
throw new IllegalArgumentException("Application token issuer doesn't match application package"); |
|||
} |
|||
String callbackUrlScheme = claims.get(CALLBACK_URL_SCHEME, String.class); |
|||
if (StringUtils.isEmpty(callbackUrlScheme)) { |
|||
throw new IllegalArgumentException("Application token doesn't have callbackUrlScheme"); |
|||
} |
|||
return callbackUrlScheme; |
|||
} |
|||
|
|||
} |
|||
@ -0,0 +1,110 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.service.ttl.alarms; |
|||
|
|||
import lombok.RequiredArgsConstructor; |
|||
import lombok.extern.slf4j.Slf4j; |
|||
import org.springframework.beans.factory.annotation.Value; |
|||
import org.springframework.scheduling.annotation.Scheduled; |
|||
import org.springframework.stereotype.Service; |
|||
import org.thingsboard.server.common.data.alarm.Alarm; |
|||
import org.thingsboard.server.common.data.audit.ActionType; |
|||
import org.thingsboard.server.common.data.id.AlarmId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
import org.thingsboard.server.common.data.page.PageData; |
|||
import org.thingsboard.server.common.data.page.PageLink; |
|||
import org.thingsboard.server.common.data.page.SortOrder; |
|||
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; |
|||
import org.thingsboard.server.common.msg.queue.ServiceType; |
|||
import org.thingsboard.server.dao.alarm.AlarmDao; |
|||
import org.thingsboard.server.dao.alarm.AlarmService; |
|||
import org.thingsboard.server.dao.relation.RelationService; |
|||
import org.thingsboard.server.dao.tenant.TbTenantProfileCache; |
|||
import org.thingsboard.server.dao.tenant.TenantDao; |
|||
import org.thingsboard.server.dao.util.PsqlDao; |
|||
import org.thingsboard.server.queue.discovery.PartitionService; |
|||
import org.thingsboard.server.queue.util.TbCoreComponent; |
|||
import org.thingsboard.server.service.action.RuleEngineEntityActionService; |
|||
import org.thingsboard.server.service.ttl.AbstractCleanUpService; |
|||
|
|||
import java.sql.Connection; |
|||
import java.sql.SQLException; |
|||
import java.util.Date; |
|||
import java.util.Optional; |
|||
import java.util.UUID; |
|||
import java.util.concurrent.TimeUnit; |
|||
|
|||
@TbCoreComponent |
|||
@Service |
|||
@Slf4j |
|||
@RequiredArgsConstructor |
|||
public class AlarmsCleanUpService { |
|||
@Value("${sql.ttl.alarms.removal_batch_size}") |
|||
private Integer removalBatchSize; |
|||
|
|||
private final TenantDao tenantDao; |
|||
private final AlarmDao alarmDao; |
|||
private final AlarmService alarmService; |
|||
private final RelationService relationService; |
|||
private final RuleEngineEntityActionService ruleEngineEntityActionService; |
|||
private final PartitionService partitionService; |
|||
private final TbTenantProfileCache tenantProfileCache; |
|||
|
|||
@Scheduled(initialDelayString = "#{T(org.apache.commons.lang3.RandomUtils).nextLong(0, ${sql.ttl.alarms.checking_interval})}", fixedDelayString = "${sql.ttl.alarms.checking_interval}") |
|||
public void cleanUp() { |
|||
PageLink tenantsBatchRequest = new PageLink(10_000, 0); |
|||
PageLink removalBatchRequest = new PageLink(removalBatchSize, 0 ); |
|||
PageData<TenantId> tenantsIds; |
|||
do { |
|||
tenantsIds = tenantDao.findTenantsIds(tenantsBatchRequest); |
|||
for (TenantId tenantId : tenantsIds.getData()) { |
|||
if (!partitionService.resolve(ServiceType.TB_CORE, tenantId, tenantId).isMyPartition()) { |
|||
continue; |
|||
} |
|||
|
|||
Optional<DefaultTenantProfileConfiguration> tenantProfileConfiguration = tenantProfileCache.get(tenantId).getProfileConfiguration(); |
|||
if (tenantProfileConfiguration.isEmpty() || tenantProfileConfiguration.get().getAlarmsTtlDays() == 0) { |
|||
continue; |
|||
} |
|||
|
|||
long ttl = TimeUnit.DAYS.toMillis(tenantProfileConfiguration.get().getAlarmsTtlDays()); |
|||
long expirationTime = System.currentTimeMillis() - ttl; |
|||
|
|||
long totalRemoved = 0; |
|||
while (true) { |
|||
PageData<AlarmId> toRemove = alarmDao.findAlarmsIdsByEndTsBeforeAndTenantId(expirationTime, tenantId, removalBatchRequest); |
|||
toRemove.getData().forEach(alarmId -> { |
|||
relationService.deleteEntityRelations(tenantId, alarmId); |
|||
Alarm alarm = alarmService.deleteAlarm(tenantId, alarmId).getAlarm(); |
|||
ruleEngineEntityActionService.pushEntityActionToRuleEngine(alarm.getOriginator(), alarm, tenantId, null, ActionType.ALARM_DELETE, null); |
|||
}); |
|||
|
|||
totalRemoved += toRemove.getTotalElements(); |
|||
if (!toRemove.hasNext()) { |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (totalRemoved > 0) { |
|||
log.info("Removed {} outdated alarm(s) for tenant {} older than {}", totalRemoved, tenantId, new Date(expirationTime)); |
|||
} |
|||
} |
|||
|
|||
tenantsBatchRequest = tenantsBatchRequest.nextPageLink(); |
|||
} while (tenantsIds.hasNext()); |
|||
} |
|||
|
|||
} |
|||
Binary file not shown.
Binary file not shown.
@ -0,0 +1,30 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.device.data.lwm2m; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.Map; |
|||
|
|||
@Data |
|||
public class BootstrapConfiguration { |
|||
|
|||
//TODO: define the objects;
|
|||
private Map<String, Object> servers; |
|||
private Map<String, Object> lwm2mServer; |
|||
private Map<String, Object> bootstrapServer; |
|||
|
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.device.data.lwm2m; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonInclude; |
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
@JsonInclude(JsonInclude.Include.NON_NULL) |
|||
public class ObjectAttributes { |
|||
|
|||
private Long dim; |
|||
private String ver; |
|||
private Long pmin; |
|||
private Long pmax; |
|||
private Double gt; |
|||
private Double lt; |
|||
private Double st; |
|||
|
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.device.data.lwm2m; |
|||
|
|||
import lombok.Data; |
|||
|
|||
@Data |
|||
public class OtherConfiguration { |
|||
|
|||
private Integer fwUpdateStrategy; |
|||
private Integer swUpdateStrategy; |
|||
private Integer clientOnlyObserveAfterConnect; |
|||
private String fwUpdateRecourse; |
|||
private String swUpdateRecourse; |
|||
|
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.device.data.lwm2m; |
|||
|
|||
import lombok.Data; |
|||
|
|||
import java.util.Map; |
|||
import java.util.Set; |
|||
|
|||
@Data |
|||
public class TelemetryMappingConfiguration { |
|||
|
|||
private Map<String, String> keyName; |
|||
private Set<String> observe; |
|||
private Set<String> attribute; |
|||
private Set<String> telemetry; |
|||
private Map<String, ObjectAttributes> attributeLwm2m; |
|||
|
|||
} |
|||
@ -0,0 +1,25 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.exception; |
|||
|
|||
public class ApiUsageLimitsExceededException extends RuntimeException { |
|||
public ApiUsageLimitsExceededException(String message) { |
|||
super(message); |
|||
} |
|||
|
|||
public ApiUsageLimitsExceededException() { |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.id; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public class OAuth2DomainId extends UUIDBased { |
|||
|
|||
@JsonCreator |
|||
public OAuth2DomainId(@JsonProperty("id") UUID id) { |
|||
super(id); |
|||
} |
|||
|
|||
public static OAuth2DomainId fromString(String oauth2DomainId) { |
|||
return new OAuth2DomainId(UUID.fromString(oauth2DomainId)); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.id; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public class OAuth2MobileId extends UUIDBased { |
|||
|
|||
@JsonCreator |
|||
public OAuth2MobileId(@JsonProperty("id") UUID id) { |
|||
super(id); |
|||
} |
|||
|
|||
public static OAuth2MobileId fromString(String oauth2MobileId) { |
|||
return new OAuth2MobileId(UUID.fromString(oauth2MobileId)); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.id; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public class OAuth2ParamsId extends UUIDBased { |
|||
|
|||
@JsonCreator |
|||
public OAuth2ParamsId(@JsonProperty("id") UUID id) { |
|||
super(id); |
|||
} |
|||
|
|||
public static OAuth2ParamsId fromString(String oauth2ParamsId) { |
|||
return new OAuth2ParamsId(UUID.fromString(oauth2ParamsId)); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.id; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonCreator; |
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
|
|||
import java.util.UUID; |
|||
|
|||
public class OAuth2RegistrationId extends UUIDBased { |
|||
|
|||
@JsonCreator |
|||
public OAuth2RegistrationId(@JsonProperty("id") UUID id) { |
|||
super(id); |
|||
} |
|||
|
|||
public static OAuth2RegistrationId fromString(String oauth2RegistrationId) { |
|||
return new OAuth2RegistrationId(UUID.fromString(oauth2RegistrationId)); |
|||
} |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.oauth2; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.BaseData; |
|||
import org.thingsboard.server.common.data.id.OAuth2DomainId; |
|||
import org.thingsboard.server.common.data.id.OAuth2ParamsId; |
|||
|
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
@ToString |
|||
@NoArgsConstructor |
|||
public class OAuth2Domain extends BaseData<OAuth2DomainId> { |
|||
|
|||
private OAuth2ParamsId oauth2ParamsId; |
|||
private String domainName; |
|||
private SchemeType domainScheme; |
|||
|
|||
public OAuth2Domain(OAuth2Domain domain) { |
|||
super(domain); |
|||
this.oauth2ParamsId = domain.oauth2ParamsId; |
|||
this.domainName = domain.domainName; |
|||
this.domainScheme = domain.domainScheme; |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.oauth2; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.ToString; |
|||
|
|||
@EqualsAndHashCode |
|||
@Data |
|||
@ToString |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
@Builder |
|||
public class OAuth2DomainInfo { |
|||
private SchemeType scheme; |
|||
private String name; |
|||
} |
|||
@ -0,0 +1,31 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.oauth2; |
|||
|
|||
import lombok.*; |
|||
|
|||
import java.util.List; |
|||
|
|||
@EqualsAndHashCode |
|||
@Data |
|||
@ToString |
|||
@Builder(toBuilder = true) |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class OAuth2Info { |
|||
private boolean enabled; |
|||
private List<OAuth2ParamsInfo> oauth2ParamsInfos; |
|||
} |
|||
@ -0,0 +1,42 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.oauth2; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.BaseData; |
|||
import org.thingsboard.server.common.data.id.OAuth2MobileId; |
|||
import org.thingsboard.server.common.data.id.OAuth2ParamsId; |
|||
|
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
@ToString |
|||
@NoArgsConstructor |
|||
public class OAuth2Mobile extends BaseData<OAuth2MobileId> { |
|||
|
|||
private OAuth2ParamsId oauth2ParamsId; |
|||
private String pkgName; |
|||
private String appSecret; |
|||
|
|||
public OAuth2Mobile(OAuth2Mobile mobile) { |
|||
super(mobile); |
|||
this.oauth2ParamsId = mobile.oauth2ParamsId; |
|||
this.pkgName = mobile.pkgName; |
|||
this.appSecret = mobile.appSecret; |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.oauth2; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.ToString; |
|||
|
|||
@EqualsAndHashCode |
|||
@Data |
|||
@ToString |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
@Builder |
|||
public class OAuth2MobileInfo { |
|||
private String pkgName; |
|||
private String appSecret; |
|||
} |
|||
@ -0,0 +1,40 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.oauth2; |
|||
|
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.BaseData; |
|||
import org.thingsboard.server.common.data.id.OAuth2ParamsId; |
|||
import org.thingsboard.server.common.data.id.TenantId; |
|||
|
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
@ToString |
|||
@NoArgsConstructor |
|||
public class OAuth2Params extends BaseData<OAuth2ParamsId> { |
|||
|
|||
private boolean enabled; |
|||
private TenantId tenantId; |
|||
|
|||
public OAuth2Params(OAuth2Params oauth2Params) { |
|||
super(oauth2Params); |
|||
this.enabled = oauth2Params.enabled; |
|||
this.tenantId = oauth2Params.tenantId; |
|||
} |
|||
} |
|||
@ -0,0 +1,39 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.oauth2; |
|||
|
|||
import lombok.AllArgsConstructor; |
|||
import lombok.Builder; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.ToString; |
|||
|
|||
import java.util.List; |
|||
|
|||
@EqualsAndHashCode |
|||
@Data |
|||
@ToString |
|||
@Builder(toBuilder = true) |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
public class OAuth2ParamsInfo { |
|||
|
|||
private List<OAuth2DomainInfo> domainInfos; |
|||
private List<OAuth2MobileInfo> mobileInfos; |
|||
private List<OAuth2RegistrationInfo> clientRegistrations; |
|||
|
|||
} |
|||
@ -0,0 +1,79 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.oauth2; |
|||
|
|||
import com.fasterxml.jackson.annotation.JsonProperty; |
|||
import lombok.Data; |
|||
import lombok.EqualsAndHashCode; |
|||
import lombok.NoArgsConstructor; |
|||
import lombok.ToString; |
|||
import org.thingsboard.server.common.data.HasName; |
|||
import org.thingsboard.server.common.data.SearchTextBasedWithAdditionalInfo; |
|||
import org.thingsboard.server.common.data.id.OAuth2ParamsId; |
|||
import org.thingsboard.server.common.data.id.OAuth2RegistrationId; |
|||
|
|||
import java.util.List; |
|||
|
|||
@EqualsAndHashCode(callSuper = true) |
|||
@Data |
|||
@ToString(exclude = {"clientSecret"}) |
|||
@NoArgsConstructor |
|||
public class OAuth2Registration extends SearchTextBasedWithAdditionalInfo<OAuth2RegistrationId> implements HasName { |
|||
|
|||
private OAuth2ParamsId oauth2ParamsId; |
|||
private OAuth2MapperConfig mapperConfig; |
|||
private String clientId; |
|||
private String clientSecret; |
|||
private String authorizationUri; |
|||
private String accessTokenUri; |
|||
private List<String> scope; |
|||
private String userInfoUri; |
|||
private String userNameAttributeName; |
|||
private String jwkSetUri; |
|||
private String clientAuthenticationMethod; |
|||
private String loginButtonLabel; |
|||
private String loginButtonIcon; |
|||
private List<PlatformType> platforms; |
|||
|
|||
public OAuth2Registration(OAuth2Registration registration) { |
|||
super(registration); |
|||
this.oauth2ParamsId = registration.oauth2ParamsId; |
|||
this.mapperConfig = registration.mapperConfig; |
|||
this.clientId = registration.clientId; |
|||
this.clientSecret = registration.clientSecret; |
|||
this.authorizationUri = registration.authorizationUri; |
|||
this.accessTokenUri = registration.accessTokenUri; |
|||
this.scope = registration.scope; |
|||
this.userInfoUri = registration.userInfoUri; |
|||
this.userNameAttributeName = registration.userNameAttributeName; |
|||
this.jwkSetUri = registration.jwkSetUri; |
|||
this.clientAuthenticationMethod = registration.clientAuthenticationMethod; |
|||
this.loginButtonLabel = registration.loginButtonLabel; |
|||
this.loginButtonIcon = registration.loginButtonIcon; |
|||
this.platforms = registration.platforms; |
|||
} |
|||
|
|||
@Override |
|||
@JsonProperty(access = JsonProperty.Access.READ_ONLY) |
|||
public String getName() { |
|||
return loginButtonLabel; |
|||
} |
|||
|
|||
@Override |
|||
public String getSearchText() { |
|||
return getName(); |
|||
} |
|||
} |
|||
@ -0,0 +1,45 @@ |
|||
/** |
|||
* Copyright © 2016-2021 The Thingsboard Authors |
|||
* |
|||
* Licensed under the Apache License, Version 2.0 (the "License"); |
|||
* you may not use this file except in compliance with the License. |
|||
* You may obtain a copy of the License at |
|||
* |
|||
* http://www.apache.org/licenses/LICENSE-2.0
|
|||
* |
|||
* Unless required by applicable law or agreed to in writing, software |
|||
* distributed under the License is distributed on an "AS IS" BASIS, |
|||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
* See the License for the specific language governing permissions and |
|||
* limitations under the License. |
|||
*/ |
|||
package org.thingsboard.server.common.data.oauth2.deprecated; |
|||
|
|||
import com.fasterxml.jackson.databind.JsonNode; |
|||
import lombok.*; |
|||
import org.thingsboard.server.common.data.oauth2.OAuth2MapperConfig; |
|||
|
|||
import java.util.List; |
|||
|
|||
@Deprecated |
|||
@EqualsAndHashCode |
|||
@Data |
|||
@ToString(exclude = {"clientSecret"}) |
|||
@NoArgsConstructor |
|||
@AllArgsConstructor |
|||
@Builder |
|||
public class ClientRegistrationDto { |
|||
private OAuth2MapperConfig mapperConfig; |
|||
private String clientId; |
|||
private String clientSecret; |
|||
private String authorizationUri; |
|||
private String accessTokenUri; |
|||
private List<String> scope; |
|||
private String userInfoUri; |
|||
private String userNameAttributeName; |
|||
private String jwkSetUri; |
|||
private String clientAuthenticationMethod; |
|||
private String loginButtonLabel; |
|||
private String loginButtonIcon; |
|||
private JsonNode additionalInfo; |
|||
} |
|||
Some files were not shown because too many files changed in this diff
Loading…
Reference in new issue