diff --git a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/credentials/CredentialsDto.java b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/credentials/CredentialsDto.java index ddc6a06a66..7609d8b7ac 100644 --- a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/credentials/CredentialsDto.java +++ b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/credentials/CredentialsDto.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.common.dto.credentials; import java.io.Serializable; @@ -20,54 +21,39 @@ import org.kaaproject.kaa.common.dto.HasId; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.annotation.JsonInclude.Include; -import com.fasterxml.jackson.annotation.JsonProperty; - /** * @author Bohdan Khablenko * @author Andrew Shvayka * * @since v0.9.0 */ -@JsonInclude(Include.NON_NULL) public final class CredentialsDto implements HasId, Serializable { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1000L; - @JsonProperty("credentialsId") private String id; - - @JsonProperty("credentials") - private byte[] credentials; - - @JsonProperty("status") + private byte[] credentialsBody; private CredentialsStatus status; - - public CredentialsDto() { - super(); - } @Override public String getId() { - return id; + return this.id; } - @Override public void setId(String id) { this.id = id; } - public byte[] getCredentials() { - return credentials; + public byte[] getCredentialsBody() { + return this.credentialsBody; } - public void setCredentials(byte[] credentials) { - this.credentials = credentials; + public void setCredentialsBody(byte[] credentialsBody) { + this.credentialsBody = credentialsBody; } public CredentialsStatus getStatus() { - return status; + return this.status; } public void setStatus(CredentialsStatus status) { @@ -78,36 +64,50 @@ public void setStatus(CredentialsStatus status) { public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + Arrays.hashCode(credentials); - result = prime * result + ((id == null) ? 0 : id.hashCode()); - result = prime * result + ((status == null) ? 0 : status.hashCode()); + result = prime * result + Arrays.hashCode(this.credentialsBody); + result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); + result = prime * result + ((this.status == null) ? 0 : this.status.hashCode()); return result; } @Override public boolean equals(Object obj) { - if (this == obj) + if (this == obj) { return true; - if (obj == null) + } + if (obj == null) { return false; - if (getClass() != obj.getClass()) + } + if (getClass() != obj.getClass()) { return false; + } CredentialsDto other = (CredentialsDto) obj; - if (!Arrays.equals(credentials, other.credentials)) + if (!Arrays.equals(this.credentialsBody, other.credentialsBody)) { return false; - if (id == null) { - if (other.id != null) + } + if (this.id == null) { + if (other.id != null) { return false; - } else if (!id.equals(other.id)) + } + } else if (!this.id.equals(other.id)) { return false; - if (status != other.status) + } + if (this.status != other.status) { return false; + } return true; } @Override public String toString() { - return "CredentialsDto [id=" + id + ", credentials=" + Arrays.toString(credentials) + ", status=" + status + "]"; + StringBuilder builder = new StringBuilder(); + builder.append("CredentialsDto [id="); + builder.append(this.id); + builder.append(", credentialsBody="); + builder.append(Arrays.toString(this.credentialsBody)); + builder.append(", status="); + builder.append(this.status); + builder.append("]"); + return builder.toString(); } - } diff --git a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/credentials/CredentialsStatus.java b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/credentials/CredentialsStatus.java index 4f3fc3f799..980591081e 100644 --- a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/credentials/CredentialsStatus.java +++ b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/credentials/CredentialsStatus.java @@ -13,14 +13,14 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.common.dto.credentials; /** - * @author Bohdan Khablenko * @author Andrew Shvayka * * @since v0.9.0 */ public enum CredentialsStatus { - AVAILABLE, IN_USE, REVOKED; + AVAILABLE, IN_USE, REVOKED; } diff --git a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/credentials/EndpointRegistrationInfoDto.java b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/credentials/EndpointRegistrationInfoDto.java index 3e4fdb8e27..cea33d4618 100644 --- a/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/credentials/EndpointRegistrationInfoDto.java +++ b/server/common/dto/src/main/java/org/kaaproject/kaa/common/dto/credentials/EndpointRegistrationInfoDto.java @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.common.dto.credentials; import java.io.Serializable; @@ -21,32 +22,25 @@ import org.kaaproject.kaa.common.dto.HasId; /** - * @author Bohdan Khablenko * @author Andrew Shvayka + * @author Bohdan Khablenko * * @since v0.9.0 */ -public class EndpointRegistrationInfoDto implements HasId, Serializable { +public final class EndpointRegistrationInfoDto implements HasId, Serializable { + + private static final long serialVersionUID = 1000L; - private static final long serialVersionUID = 1L; - private String id; - private String applicationId; - - /** - * This is optional - */ - private String credentialsId; - private String endpointId; - + private String credentialsId; private Integer serverProfileVersion; - private String serverProfileBody; + @Override public String getId() { - return id; + return this.id; } public void setId(String id) { @@ -54,31 +48,31 @@ public void setId(String id) { } public String getApplicationId() { - return applicationId; + return this.applicationId; } public void setApplicationId(String applicationId) { this.applicationId = applicationId; } - public String getCredentialsId() { - return credentialsId; + public String getEndpointId() { + return this.endpointId; } - public void setCredentialsId(String credentialsId) { - this.credentialsId = credentialsId; + public void setEndpointId(String endpointId) { + this.endpointId = endpointId; } - public String getEndpointId() { - return endpointId; + public Optional getCredentialsId() { + return Optional.ofNullable(this.credentialsId); } - public void setEndpointId(String endpointId) { - this.endpointId = endpointId; + public void setCredentialsId(String credentialsId) { + this.credentialsId = credentialsId; } public Optional getServerProfileVersion() { - return Optional.ofNullable(serverProfileVersion); + return Optional.ofNullable(this.serverProfileVersion); } public void setServerProfileVersion(Integer serverProfileVersion) { @@ -86,10 +80,99 @@ public void setServerProfileVersion(Integer serverProfileVersion) { } public Optional getServerProfileBody() { - return Optional.ofNullable(serverProfileBody); + return Optional.ofNullable(this.serverProfileBody); } public void setServerProfileBody(String serverProfileBody) { this.serverProfileBody = serverProfileBody; } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((this.applicationId == null) ? 0 : this.applicationId.hashCode()); + result = prime * result + ((this.credentialsId == null) ? 0 : this.credentialsId.hashCode()); + result = prime * result + ((this.endpointId == null) ? 0 : this.endpointId.hashCode()); + result = prime * result + ((this.id == null) ? 0 : this.id.hashCode()); + result = prime * result + ((this.serverProfileBody == null) ? 0 : this.serverProfileBody.hashCode()); + result = prime * result + ((this.serverProfileVersion == null) ? 0 : this.serverProfileVersion.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } + EndpointRegistrationInfoDto other = (EndpointRegistrationInfoDto) obj; + if (this.applicationId == null) { + if (other.applicationId != null) { + return false; + } + } else if (!this.applicationId.equals(other.applicationId)) { + return false; + } + if (this.credentialsId == null) { + if (other.credentialsId != null) { + return false; + } + } else if (!this.credentialsId.equals(other.credentialsId)) { + return false; + } + if (this.endpointId == null) { + if (other.endpointId != null) { + return false; + } + } else if (!this.endpointId.equals(other.endpointId)) { + return false; + } + if (this.id == null) { + if (other.id != null) { + return false; + } + } else if (!this.id.equals(other.id)) { + return false; + } + if (this.serverProfileBody == null) { + if (other.serverProfileBody != null) { + return false; + } + } else if (!this.serverProfileBody.equals(other.serverProfileBody)) { + return false; + } + if (this.serverProfileVersion == null) { + if (other.serverProfileVersion != null) { + return false; + } + } else if (!this.serverProfileVersion.equals(other.serverProfileVersion)) { + return false; + } + return true; + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("EndpointRegistrationInfoDto [id="); + builder.append(this.id); + builder.append(", applicationId="); + builder.append(this.applicationId); + builder.append(", endpointId="); + builder.append(this.endpointId); + builder.append(", credentialsId="); + builder.append(this.credentialsId); + builder.append(", serverProfileVersion="); + builder.append(this.serverProfileVersion); + builder.append(", serverProfileBody="); + builder.append(this.serverProfileBody); + builder.append("]"); + return builder.toString(); + } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/CredentialsService.java b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/CredentialsService.java index a741f00bf4..2c511d9451 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/CredentialsService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/CredentialsService.java @@ -13,13 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.server.node.service.credentials; +import java.util.Optional; + import org.kaaproject.kaa.common.dto.credentials.CredentialsDto; import org.kaaproject.kaa.common.dto.credentials.CredentialsStatus; /** - * This interface is used to communicate with external systems in order to manage credentials information + * A service that communicates with an external system to manage credentials + * information. * * @author Bohdan Khablenko * @author Andrew Shvayka @@ -27,34 +31,49 @@ * @since v0.9.0 */ public interface CredentialsService { - + /** - * Provision credentials entry. - * @param credentials - credentials to provision - * @throws UnsupportedOperationException - in case service implementation is read-only - * @return provisioned credentials + * Provisions credentials information to the external system. + * + * @param credentials The credentials to provision + * + * @return The credentials provisioned + * + * @throws UnsupportedOperationException - if the underlying implementation + * forbids credentials provisioning. + * @throws CredentialsServiceException - if an unexpected exception occures. */ CredentialsDto provisionCredentials(CredentialsDto credentials) throws CredentialsServiceException; /** - * Lookup credentials entry by id. - * @param credentialsId - credentials to provision - * @return credentials or null if credentials are not found + * Returns the credentials by ID. + * + * @param credentialsId The credentials ID + * + * @return The credentials with the given ID */ - CredentialsDto lookupCredentials(String credentialsId); - + Optional lookupCredentials(String credentialsId); + /** - * Update credentials status to {@link CredentialsStatus#IN_USE} - * @param credentialsId - * @throws CredentialsServiceException in case credentials are not in {@link CredentialsStatus#AVAILABLE} + * Sets the status of the given credentials to + * {@link CredentialsStatus#IN_USE}. + * + * @param credentialsId The credentials ID + * + * @throws CredentialsServiceException - if the credentials are not + * {@link CredentialsStatus#AVAILABLE available}. */ void markCredentialsInUse(String credentialsId) throws CredentialsServiceException; - + /** - * Update credentials status to {@link CredentialsStatus#REVOKED} - * @param credentialsId - * @throws UnsupportedOperationException - in case the service implementation does not allow revocation of credentials + * Revokes the given credentials by setting their status to + * {@link CredentialsStatus#REVOKED}. + * + * @param credentialsId The credentials ID + * + * @throws UnsupportedOperationException - if the underlying implementation + * forbids credentials revokation. + * @throws CredentialsServiceException - if an unexpected exception occures. */ void markCredentialsRevoked(String credentialsId) throws CredentialsServiceException; - } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/CredentialsServiceException.java b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/CredentialsServiceException.java index c8bb280328..151fa39409 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/CredentialsServiceException.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/CredentialsServiceException.java @@ -1,8 +1,49 @@ +/** + * Copyright 2014-2016 CyberVision, Inc. + * + * 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.kaaproject.kaa.server.node.service.credentials; -public class CredentialsServiceException extends Exception{ +/** + * A checked exception to be thrown by {@link CredentialsService}. + * + * @author Andrew Shvayka + * @author Bohdan Khablenko + * + * @since v0.9.0 + */ +public final class CredentialsServiceException extends Exception { + + private static final long serialVersionUID = 1000L; - private static final long serialVersionUID = 1L; + /** + * Constructs a new exception with the specified cause. + * + * @param cause The exception cause + */ + public CredentialsServiceException(Throwable cause) { + super(cause); + } - //TODO: define the structure, fields, etc. + /** + * Constructs a new exception with the specified cause and detail message. + * + * @param message The detail message + * @param cause The exception cause + */ + public CredentialsServiceException(String message, Throwable cause) { + super(message, cause); + } } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/CredentialsServiceFactory.java b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/CredentialsServiceFactory.java index 93e8acb6b0..c225ed6bbb 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/CredentialsServiceFactory.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/CredentialsServiceFactory.java @@ -13,22 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.server.node.service.credentials; /** - * This interface is used to communicate with external systems in order to manage credentials information + * Allows each application to have a credentials service of its own. * * @author Andrew Shvayka + * @author Bohdan Khablenko * * @since v0.9.0 */ public interface CredentialsServiceFactory { /** - * Lookup implementation of credentials service based on application id - * @param applicationId - * @return + * Returns the service that is responsible for managing credentials for the + * specified application. + * + * @param applicationId The application ID + * + * @return The servise that is responsible for managing credentials for the + * specified application. */ CredentialsService getCredentialsService(String applicationId); - } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/DefaultInternalCredentialsService.java b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/DefaultInternalCredentialsService.java index e07c846121..aa32ea7e33 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/DefaultInternalCredentialsService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/DefaultInternalCredentialsService.java @@ -1,8 +1,34 @@ +/** + * Copyright 2014-2016 CyberVision, Inc. + * + * 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.kaaproject.kaa.server.node.service.credentials; +import java.util.Optional; + import org.kaaproject.kaa.common.dto.credentials.CredentialsDto; import org.springframework.stereotype.Service; +/** + * The default implementation of the {@link InternalCredentialsService} + * interface. + * + * @author Bohdan Khablenko + * + * @since v0.9.0 + */ @Service public class DefaultInternalCredentialsService implements InternalCredentialsService { @@ -13,7 +39,7 @@ public CredentialsDto provisionCredentials(String applicationId, CredentialsDto } @Override - public CredentialsDto lookupCredentials(String applicationId, String credentialsId) { + public Optional lookupCredentials(String applicationId, String credentialsId) { // TODO Auto-generated method stub return null; } @@ -21,13 +47,10 @@ public CredentialsDto lookupCredentials(String applicationId, String credentials @Override public void markCredentialsInUse(String applicationId, String credentialsId) throws CredentialsServiceException { // TODO Auto-generated method stub - } @Override public void markCredentialsRevoked(String applicationId, String credentialsId) throws CredentialsServiceException { // TODO Auto-generated method stub - } - } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/InternalCredentialsService.java b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/InternalCredentialsService.java index 343abfda13..14896a2c3d 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/InternalCredentialsService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/InternalCredentialsService.java @@ -13,57 +13,77 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.server.node.service.credentials; +import java.util.Optional; + import org.kaaproject.kaa.common.dto.credentials.CredentialsDto; +import org.kaaproject.kaa.common.dto.credentials.CredentialsStatus; /** - * Internal sibling of {@link CredentialsService} that works in scope of application id + * The interface {@link InternalCredentialsService} is an internal sibling of + * {@link CredentialsService}. + * + * In general, each application has its own independent credentials service used + * as a bridge to some external system. Since Kaa acts as such a system by + * default, a single credentials service is enough to be used across all + * applications. Its methods require an additonal parameter, though, namely an + * application ID. + * * @author Andrew Shvayka + * @author Bohdan Khablenko * + * @since v0.9.0 */ public interface InternalCredentialsService { - + /** - * Provision credentials entry. + * Provisions credentials information to the internal system. * + * @param credentials The credentials to provision + * + * @return The credentials provisioned + * + * @throws CredentialsServiceException - if an unexpected exception occures. + * * @see CredentialsService#provisionCredentials(CredentialsDto) - * - * @param applicationId - application id - * @param credentials - credentials to provision - * @throws UnsupportedOperationException - in case service implementation is read-only - * @return provisioned credentials */ CredentialsDto provisionCredentials(String applicationId, CredentialsDto credentials) throws CredentialsServiceException; /** - * Lookup credentials entry by id. - * + * Returns the credentials by ID. + * + * @param credentialsId The credentials ID + * + * @return The credentials with the given ID + * * @see CredentialsService#lookupCredentials(String) - * - * @param applicationId - application id - * @param credentialsId - credentials to provision - * @return credentials or null if credentials are not found */ - CredentialsDto lookupCredentials(String applicationId, String credentialsId); - - /** - * Mark credentials in use - * + Optional lookupCredentials(String applicationId, String credentialsId); + + /** + * Sets the status of the given credentials to + * {@link CredentialsStatus#IN_USE}. + * + * @param credentialsId The credentials ID + * + * @throws CredentialsServiceException - if the credentials are not + * {@link CredentialsStatus#AVAILABLE available}. + * * @see CredentialsService#markCredentialsInUse(String) - * - * @param applicationId - application id - * @param credentialsId - credentials id */ void markCredentialsInUse(String applicationId, String credentialsId) throws CredentialsServiceException; - - /** - * Mark credentials revoked - * + + /** + * Revokes the given credentials by setting their status to + * {@link CredentialsStatus#REVOKED}. + * + * @param credentialsId The credentials ID + * + * @throws CredentialsServiceException - if an unexpected exception occures. + * * @see CredentialsService#markCredentialsRevoked(String) - * - * @param applicationId - application id - * @param credentialsId - credentials id */ void markCredentialsRevoked(String applicationId, String credentialsId) throws CredentialsServiceException; } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/InternalCredentialsServiceAdapter.java b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/InternalCredentialsServiceAdapter.java index af49092e37..cca9f27cd0 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/InternalCredentialsServiceAdapter.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/InternalCredentialsServiceAdapter.java @@ -13,45 +13,55 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.server.node.service.credentials; +import java.util.Optional; + import org.kaaproject.kaa.common.dto.credentials.CredentialsDto; /** - * Bridge between {@link CredentialsService} and {@link InternalCredentialsService} interfaces - * @author ashvayka + * A bridge between the {@link CredentialsService} and + * {@link InternalCredentialsService} interfaces. + * + * @author Andrew Shvayka + * @author Bohdan Khablenko * + * @since v0.9.0 */ -public class InternalCredentialsServiceAdapter implements CredentialsService { +public final class InternalCredentialsServiceAdapter implements CredentialsService { private final String applicationId; - private final InternalCredentialsService service; + private final InternalCredentialsService credentialsService; - public InternalCredentialsServiceAdapter(String applicationId, InternalCredentialsService service) { - super(); + /** + * Constructs an adapter for the given application. + * + * @param applicationId The application ID + * @param credentialsService The internal credentials service used by Kaa + */ + public InternalCredentialsServiceAdapter(String applicationId, InternalCredentialsService credentialsService) { this.applicationId = applicationId; - this.service = service; + this.credentialsService = credentialsService; } @Override public CredentialsDto provisionCredentials(CredentialsDto credentials) throws CredentialsServiceException { - return service.provisionCredentials(applicationId, credentials); + return credentialsService.provisionCredentials(applicationId, credentials); } @Override - public CredentialsDto lookupCredentials(String credentialsId) { - return service.lookupCredentials(applicationId, credentialsId); + public Optional lookupCredentials(String credentialsId) { + return credentialsService.lookupCredentials(applicationId, credentialsId); } @Override public void markCredentialsInUse(String credentialsId) throws CredentialsServiceException { - service.markCredentialsInUse(applicationId, credentialsId); + credentialsService.markCredentialsInUse(applicationId, credentialsId); } @Override public void markCredentialsRevoked(String credentialsId) throws CredentialsServiceException { - service.markCredentialsRevoked(applicationId, credentialsId); + credentialsService.markCredentialsRevoked(applicationId, credentialsId); } - - } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/InternalCredentialsServiceFactory.java b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/InternalCredentialsServiceFactory.java index 88dfccf4b9..968c0a90e5 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/InternalCredentialsServiceFactory.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/credentials/InternalCredentialsServiceFactory.java @@ -13,23 +13,27 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.server.node.service.credentials; import org.springframework.beans.factory.annotation.Autowired; /** - * Provides default implementation of {@link CredentialsServiceFactory} - * that always return {@link InternalCredentialsService} based on provided applicationId - * + * The default implementation of the {@link CredentialsServiceFactory} used by + * Kaa in order to utilize {@link InternalCredentialsService}. + * + * @author Andrew Shvayka + * @author Bohdan Khablenko + * + * @since v0.9.0 */ -public class InternalCredentialsServiceFactory implements CredentialsServiceFactory { +public final class InternalCredentialsServiceFactory implements CredentialsServiceFactory { @Autowired - private InternalCredentialsService service; - + private InternalCredentialsService credentialsService; + @Override public CredentialsService getCredentialsService(String applicationId) { - return new InternalCredentialsServiceAdapter(applicationId, service); + return new InternalCredentialsServiceAdapter(applicationId, this.credentialsService); } - } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/registration/RegistrationService.java b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/registration/RegistrationService.java index 60938da519..4670fb595b 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/registration/RegistrationService.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/registration/RegistrationService.java @@ -13,19 +13,22 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.kaaproject.kaa.server.node.service.registration; import org.kaaproject.kaa.common.dto.credentials.EndpointRegistrationInfoDto; /** - * This service represent Kaa platform capabilities to provision, lookup and - * revoke registration information. Information that is managed using this - * service should be stored in Kaa NoSQL database. Registration information is - * represented using {@link EndpointRegistrationInfoDto} and contains server side - * profile body and version. + * This service represent the Kaa platform capabilities to provision, lookup and + * revoke registration information. The information that is managed using this + * service should be stored in an NoSQL database. Registration information is + * represented with instances of the {@link EndpointRegistrationInfoDto} class + * and contains server-side endpoint profile version and body. * * @author Andrew Shvayka + * @author Bohdan Khablenko * + * @since v0.9.0 */ public interface RegistrationService { @@ -33,9 +36,8 @@ EndpointRegistrationInfoDto provisonEndpointRegistrationInfo(EndpointRegistratio throws RegistrationServiceException; EndpointRegistrationInfoDto lookupEndpointRegistrationInfoByEndpointId(String endpointId) throws RegistrationServiceException; - + EndpointRegistrationInfoDto lookupEndpointRegistrationInfoByCredentialsId(String credentialsId) throws RegistrationServiceException; EndpointRegistrationInfoDto revokeEndpointRegistrationInfo(String endpointId) throws RegistrationServiceException; - } diff --git a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/registration/RegistrationServiceException.java b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/registration/RegistrationServiceException.java index cb209853d6..1929bdde28 100644 --- a/server/node/src/main/java/org/kaaproject/kaa/server/node/service/registration/RegistrationServiceException.java +++ b/server/node/src/main/java/org/kaaproject/kaa/server/node/service/registration/RegistrationServiceException.java @@ -1,7 +1,49 @@ +/** + * Copyright 2014-2016 CyberVision, Inc. + * + * 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.kaaproject.kaa.server.node.service.registration; +/** + * A checked exception to be thrown by {@link RegistrationService}. + * + * @author Andrew Shvayka + * @author Bohdan Khablenko + * + * @since v0.9.0 + */ public class RegistrationServiceException extends Exception { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1000L; + + /** + * Constructs a new exception with the specified cause. + * + * @param cause The exception cause + */ + public RegistrationServiceException(Throwable cause) { + super(cause); + } + /** + * Constructs a new exception with the specified cause and detail message. + * + * @param message The detail message + * @param cause The exception cause + */ + public RegistrationServiceException(String message, Throwable cause) { + super(message, cause); + } }