Skip to content

Commit

Permalink
Added useConfigurationRawSchema field to support client that use Kaa …
Browse files Browse the repository at this point in the history
…SDK 0.9.0
  • Loading branch information
Kirill380 committed Jul 13, 2016
1 parent 6064e31 commit 8b61c73
Show file tree
Hide file tree
Showing 25 changed files with 375 additions and 512 deletions.
Expand Up @@ -317,7 +317,7 @@ private void sendConnect() throws Exception {
byte[] requestBodyEncoded = encDec.encodeData(body);
byte[] sessionKey = encDec.getEncodedSessionKey();
byte[] signature = encDec.sign(sessionKey);
sendFrame(new Connect(CHANNEL_TIMEOUT, Constants.KAA_PLATFORM_PROTOCOL_AVRO_ID, sessionKey, requestBodyEncoded, signature));
sendFrame(new Connect(CHANNEL_TIMEOUT, Constants.KAA_PLATFORM_PROTOCOL_AVRO_ID_V2, sessionKey, requestBodyEncoded, signature));
}

private synchronized void closeConnection() {
Expand Down
Expand Up @@ -16,9 +16,11 @@

package org.kaaproject.kaa.client.channel.impl.channels;

import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.util.LinkedHashMap;

import org.kaaproject.kaa.common.Constants;
import org.kaaproject.kaa.common.endpoint.CommonEPConstans;
import org.kaaproject.kaa.common.endpoint.security.MessageEncoderDecoder;
import org.slf4j.Logger;
Expand All @@ -44,6 +46,7 @@ static LinkedHashMap<String, byte[]> createHttpRequest(byte [] body, MessageEnco
if (body != null && messageEncDec != null) {
byte[] requestKeyEncoded = messageEncDec.getEncodedSessionKey();
byte[] requestBodyEncoded = messageEncDec.encodeData(body);
byte[] nextProtocol = ByteBuffer.allocate(4).putInt(Constants.KAA_PLATFORM_PROTOCOL_AVRO_ID_V2).array();
byte[] signature = null;
if(sign){
signature = messageEncDec.sign(requestKeyEncoded);
Expand All @@ -61,13 +64,12 @@ static LinkedHashMap<String, byte[]> createHttpRequest(byte [] body, MessageEnco
}
LinkedHashMap<String, byte[]> requestEntity = new LinkedHashMap<String, byte[]>(); //NOSONAR
if(sign){
requestEntity.put(CommonEPConstans.REQUEST_SIGNATURE_ATTR_NAME,
signature);
requestEntity.put(CommonEPConstans.REQUEST_SIGNATURE_ATTR_NAME, signature);
}
requestEntity.put(CommonEPConstans.REQUEST_KEY_ATTR_NAME,
requestKeyEncoded);
requestEntity.put(CommonEPConstans.REQUEST_DATA_ATTR_NAME,
requestBodyEncoded);
requestEntity.put(CommonEPConstans.REQUEST_KEY_ATTR_NAME, requestKeyEncoded);
requestEntity.put(CommonEPConstans.REQUEST_DATA_ATTR_NAME, requestBodyEncoded);
requestEntity.put(CommonEPConstans.NEXT_PROTOCOL_ATTR_NAME, nextProtocol);

return requestEntity;
}
return null;
Expand Down
Expand Up @@ -20,44 +20,38 @@
* Common Kaa project Constants.
*/
public interface Constants { //NOSONAR
/**
* Used URI delimiter.
*/
public static final String URI_DELIM = "/"; //NOSONAR

String URI_DELIM = "/"; //NOSONAR

/**
* HTTP response content-type.
*/
public static final String RESPONSE_CONTENT_TYPE = "\"application/x-kaa\""; //NOSONAR
String RESPONSE_CONTENT_TYPE = "\"application/x-kaa\""; //NOSONAR

/**
* HTTP response custom header for set RSA Signature encoded in base64
*/
public static final String SIGNATURE_HEADER_NAME = "X-SIGNATURE"; //NOSONAR
String SIGNATURE_HEADER_NAME = "X-SIGNATURE"; //NOSONAR

/**
* The identifier for the Avro platform protocol
*/
public static final int KAA_PLATFORM_PROTOCOL_AVRO_ID = 0xf291f2d4;

/**
* The identifier for the Binary platform protocol
*/
public static final int KAA_PLATFORM_PROTOCOL_BINARY_ID = 0x3553c66f;
//The identifier for the Avro platform protocol
int KAA_PLATFORM_PROTOCOL_AVRO_ID = 0xf291f2d4;

/**
* The size of sdk token
*/
public static final int SDK_TOKEN_SIZE = 27;
//cvc32 of AvroEncDecUseRawChema
int KAA_PLATFORM_PROTOCOL_AVRO_ID_V2 = 0xe0c0c178;

/**
* The size of application token
*/
public static final int APP_TOKEN_SIZE = 20;

/**
* The size of user verifier token
*/
public static final int USER_VERIFIER_TOKEN_SIZE = 20;
//The identifier for the Binary platform protocol
int KAA_PLATFORM_PROTOCOL_BINARY_ID = 0x3553c66f;

//cvc32 of BinaryEncDecUseRawSchema
int KAA_PLATFORM_PROTOCOL_BINARY_ID_V2 = 0x0231ad61;


int SDK_TOKEN_SIZE = 27;

int APP_TOKEN_SIZE = 20;

int USER_VERIFIER_TOKEN_SIZE = 20;

}
Expand Up @@ -85,12 +85,16 @@ public class EndpointServiceImpl implements EndpointService {

@Autowired
private EndpointGroupDao<EndpointGroup> endpointGroupDao;

@Autowired
private HistoryService historyService;

@Autowired
private ServerProfileService serverProfileService;

@Autowired
private CTLService ctlService;

@Autowired
private TopicDao<Topic> topicDao;

Expand Down
Expand Up @@ -58,6 +58,7 @@ public class EndpointProfileDto implements HasId, HasVersion, Serializable {
private String serverHash;
private String sdkToken;
private Long version;
private boolean useConfigurationRawSchema;

@Override
public String getId() {
Expand Down Expand Up @@ -283,6 +284,15 @@ public void setVersion(Long version) {
this.version = version;
}


public boolean isUseConfigurationRawSchema() {
return useConfigurationRawSchema;
}

public void setUseConfigurationRawSchema(boolean useConfigurationRawSchema) {
this.useConfigurationRawSchema = useConfigurationRawSchema;
}

@Override
public boolean equals(Object o) {
if (this == o) {
Expand Down Expand Up @@ -349,6 +359,10 @@ public boolean equals(Object o) {
return false;
}

if (useConfigurationRawSchema != that.useConfigurationRawSchema) {
return false;
}

return true;
}

Expand All @@ -371,9 +385,11 @@ public int hashCode() {
result = 31 * result + systemNfVersion;
result = 31 * result + userNfVersion;
result = 31 * result + (sdkToken != null ? sdkToken.hashCode() : 0);
result = 31 * result + (useConfigurationRawSchema ? 1 : 0);
return result;
}


@Override
public String toString() {
StringBuilder builder = new StringBuilder();
Expand Down Expand Up @@ -423,6 +439,8 @@ public String toString() {
builder.append(serverHash);
builder.append(", sdkToken=");
builder.append(sdkToken);
builder.append(", useRawSchema=");
builder.append(useConfigurationRawSchema);
builder.append("]");
return builder.toString();
}
Expand Down
Expand Up @@ -21,33 +21,7 @@
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.convertECFVersionDtoToModelList;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.getByteBuffer;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.CassandraDaoUtil.getBytes;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_ACCESS_TOKEN_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_APP_ID_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_COLUMN_FAMILY_NAME;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_CONFIGURATION_VERSION_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_CONFIG_HASH_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_ECF_VERSION_STATE_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_ENDPOINT_ID_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_EP_KEY_HASH_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_EP_KEY_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_GROUP_STATE_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_LOG_SCHEMA_VERSION_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_NOTIFICATION_VERSION_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_PROFILE_HASH_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_PROFILE_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_PROFILE_VERSION_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SDK_TOKEN_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SEQUENCE_NUMBER_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SERVER_HASH_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SERVER_PROFILE_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SERVER_PROFILE_VERSION_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SIMPLE_TOPIC_HASH_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SUBSCRIPTIONS_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_SYSTEM_NOTIFICATION_VERSION_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_TOPIC_HASH_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_USER_CONFIG_HASH_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_USER_ID_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.EP_USER_NOTIFICATION_VERSION_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.cassandra.dao.model.CassandraModelConstants.*;

import java.io.Serializable;
import java.nio.ByteBuffer;
Expand Down Expand Up @@ -126,7 +100,11 @@ public final class CassandraEndpointProfile implements EndpointProfile, Serializ
@Column(name = EP_SDK_TOKEN_PROPERTY)
private String sdkToken;
@Column(name = EP_SERVER_PROFILE_PROPERTY)
private String serverProfile;
private String serverProfile;

@Column(name = EP_USE_RAW_SCHEMA)
private Boolean useConfigurationRawSchema;

@Column(name = OPT_LOCK)
private Long version;

Expand Down Expand Up @@ -160,6 +138,7 @@ public CassandraEndpointProfile(EndpointProfileDto dto) {
this.serverHash = dto.getServerHash();
this.sdkToken = dto.getSdkToken();
this.serverProfile = dto.getServerProfileBody();
this.useConfigurationRawSchema = dto.isUseConfigurationRawSchema();
this.version = dto.getVersion();
}

Expand Down Expand Up @@ -376,7 +355,15 @@ public void setSdkToken(String sdkToken) {
public void setApplicationId(String applicationId) {
this.applicationId = applicationId;
}


public Boolean getUseConfigurationRawSchema() {
return useConfigurationRawSchema;
}

public void setUseConfigurationRawSchema(Boolean useConfigurationRawSchema) {
this.useConfigurationRawSchema = useConfigurationRawSchema;
}

@Override
public Long getVersion() {
return version;
Expand Down Expand Up @@ -420,6 +407,9 @@ public boolean equals(Object o) {
if (ecfVersionStates != null ? !ecfVersionStates.equals(that.ecfVersionStates) : that.ecfVersionStates != null) return false;
if (serverHash != null ? !serverHash.equals(that.serverHash) : that.serverHash != null) return false;
if (sdkToken != null ? !sdkToken.equals(that.sdkToken) : that.sdkToken != null) return false;
if (useConfigurationRawSchema != null ? !useConfigurationRawSchema.equals(that.useConfigurationRawSchema) : that.useConfigurationRawSchema != null) {
return false;
}
return serverProfile != null ? serverProfile.equals(that.serverProfile) : that.serverProfile == null;

}
Expand Down Expand Up @@ -450,6 +440,7 @@ public int hashCode() {
result = 31 * result + (ecfVersionStates != null ? ecfVersionStates.hashCode() : 0);
result = 31 * result + (serverHash != null ? serverHash.hashCode() : 0);
result = 31 * result + (sdkToken != null ? sdkToken.hashCode() : 0);
result = 31 * result + (useConfigurationRawSchema != null ? useConfigurationRawSchema.hashCode() : 0);
result = 31 * result + (serverProfile != null ? serverProfile.hashCode() : 0);
return result;
}
Expand Down Expand Up @@ -482,6 +473,7 @@ public String toString() {
", ecfVersionStates=" + ecfVersionStates +
", serverHash='" + serverHash + '\'' +
", sdkToken='" + sdkToken + '\'' +
", useRawSchema=" + useConfigurationRawSchema +
", serverProfile='" + serverProfile + '\'' +
'}';
}
Expand Down Expand Up @@ -515,6 +507,7 @@ public EndpointProfileDto toDto() {
dto.setServerHash(serverHash);
dto.setSdkToken(sdkToken);
dto.setServerProfileBody(serverProfile);
dto.setUseConfigurationRawSchema(useConfigurationRawSchema);
dto.setVersion(version);
return dto;
}
Expand Down
Expand Up @@ -109,6 +109,7 @@ private CassandraModelConstants() {
public static final String EP_ECF_VERSION_STATE_PROPERTY = "ecf_ver_state";
public static final String EP_SERVER_HASH_PROPERTY = "server_hash";
public static final String EP_SDK_TOKEN_PROPERTY = SDK_TOKEN_PROPERTY;
public static final String EP_USE_RAW_SCHEMA = "use_raw_schema";
public static final String EP_SERVER_PROFILE_PROPERTY = "srv_pf";

/**
Expand Down
Expand Up @@ -88,6 +88,7 @@ CREATE TABLE IF NOT EXISTS kaa.ep_profile (
server_hash text,
sdk_token text,
srv_pf text,
use_raw_schema boolean,
opt_lock bigint
);

Expand Down
Expand Up @@ -39,18 +39,7 @@

import static org.kaaproject.kaa.server.common.dao.DaoConstants.OPT_LOCK;
import static org.kaaproject.kaa.server.common.dao.impl.DaoUtil.convertDtoList;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.ENDPOINT_GROUP_ID;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.ENDPOINT_PROFILE;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_ACCESS_TOKEN;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_APPLICATION_ID;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_ENDPOINT_KEY_HASH;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_GROUP_STATE;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_PROFILE_VERSION;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SDK_TOKEN;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SERVER_PROFILE_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_SERVER_PROFILE_VERSION_PROPERTY;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.EP_USER_ID;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.ID;
import static org.kaaproject.kaa.server.common.nosql.mongo.dao.model.MongoModelConstants.*;
import static org.springframework.data.mongodb.core.query.Criteria.where;
import static org.springframework.data.mongodb.core.query.Query.query;
import static org.springframework.data.mongodb.core.query.Update.update;
Expand Down Expand Up @@ -103,7 +92,7 @@ public EndpointProfilesBodyDto findBodyByEndpointGroupId(PageLinkDto pageLink) {
where(EP_GROUP_STATE + "." + ENDPOINT_GROUP_ID).is(pageLink.getEndpointGroupId())));
query.skip(offs).limit(lim + 1);
query.fields().include(DaoConstants.PROFILE).include(EP_SERVER_PROFILE_PROPERTY).include(EP_ENDPOINT_KEY_HASH).include(EP_APPLICATION_ID)
.include(EP_PROFILE_VERSION).include(EP_SERVER_PROFILE_VERSION_PROPERTY);
.include(EP_PROFILE_VERSION).include(EP_SERVER_PROFILE_VERSION_PROPERTY).include(EP_USE_RAW_SCHEMA);
List<EndpointProfileDto> endpointProfileDtoList = convertDtoList(mongoTemplate.find(query, getDocumentClass()));
if (endpointProfileDtoList.size() == (lim + 1)) {
String offset = Integer.toString(lim + offs);
Expand Down Expand Up @@ -149,7 +138,7 @@ public EndpointProfileBodyDto findBodyByKeyHash(byte[] endpointKeyHash) {
EndpointProfileBodyDto endpointProfileBodyDto = null;
Query query = Query.query(where(EP_ENDPOINT_KEY_HASH).is(endpointKeyHash));
query.fields().include(DaoConstants.PROFILE).include(EP_SERVER_PROFILE_PROPERTY).include(EP_APPLICATION_ID)
.include(EP_PROFILE_VERSION).include(EP_SERVER_PROFILE_VERSION_PROPERTY);
.include(EP_PROFILE_VERSION).include(EP_SERVER_PROFILE_VERSION_PROPERTY).include(EP_USE_RAW_SCHEMA);
EndpointProfileDto pf = mongoTemplate.findOne(query, getDocumentClass()).toDto();
if (pf != null) {
endpointProfileBodyDto = new EndpointProfileBodyDto(endpointKeyHash, pf.getClientProfileBody(), pf.getServerProfileBody(),
Expand Down

0 comments on commit 8b61c73

Please sign in to comment.