Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Bohdan Khablenko
committed
Mar 30, 2016
1 parent
3c0d7c6
commit 46d90f8
Showing
30 changed files
with
614 additions
and
168 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
...ao/src/main/java/org/kaaproject/kaa/server/common/dao/service/CredentialsServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/** | ||
* 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.common.dao.service; | ||
|
||
import java.text.MessageFormat; | ||
import java.util.Optional; | ||
|
||
import org.apache.commons.lang3.Validate; | ||
import org.kaaproject.kaa.common.dto.credentials.CredentialsDto; | ||
import org.kaaproject.kaa.common.dto.credentials.CredentialsStatus; | ||
import org.kaaproject.kaa.server.common.dao.CredentialsService; | ||
import org.kaaproject.kaa.server.common.dao.exception.CredentialsServiceException; | ||
import org.kaaproject.kaa.server.common.dao.impl.CredentialsDao; | ||
import org.kaaproject.kaa.server.common.dao.model.Credentials; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
/** | ||
* The default implementation of the {@link CredentialsService} interface. | ||
* | ||
* @author Bohdan Khablenko | ||
* | ||
* @since v0.9.0 | ||
*/ | ||
@Transactional | ||
public class CredentialsServiceImpl implements CredentialsService { | ||
|
||
private static final Logger LOG = LoggerFactory.getLogger(EndpointRegistrationServiceImpl.class); | ||
|
||
private final CredentialsDao<Credentials> credentialsDao; | ||
|
||
public CredentialsServiceImpl(CredentialsDao<Credentials> credentialsDao) { | ||
this.credentialsDao = credentialsDao; | ||
} | ||
|
||
@Override | ||
public CredentialsDto provideCredentials(String applicationId, CredentialsDto credentials) throws CredentialsServiceException { | ||
Validate.notBlank(applicationId, "Invalid application ID provided!"); | ||
Validate.notNull(credentials, "Invalid credentials provided!"); | ||
try { | ||
return this.credentialsDao.save(applicationId, credentials).toDto(); | ||
} catch (Exception cause) { | ||
String message = MessageFormat.format("[{0}] An unexpected exception occured while saving credentials!", applicationId); | ||
LOG.error(message, cause); | ||
throw new CredentialsServiceException(cause); | ||
} | ||
} | ||
|
||
@Override | ||
public Optional<CredentialsDto> lookupCredentials(String applicationId, String credentialsId) throws CredentialsServiceException { | ||
Validate.notBlank(applicationId, "Invalid application ID provided!"); | ||
Validate.notBlank(credentialsId, "Invalid credentials ID provided!"); | ||
try { | ||
return this.credentialsDao.find(applicationId, credentialsId).map(Credentials::toDto); | ||
} catch (Exception cause) { | ||
String message = MessageFormat.format("[{0}] An unexpected exception occured while searching for credentials [{1}]", applicationId, credentialsId); | ||
LOG.error(message, cause); | ||
throw new CredentialsServiceException(cause); | ||
} | ||
} | ||
|
||
@Override | ||
public void markCredentialsInUse(String applicationId, String credentialsId) throws CredentialsServiceException { | ||
this.updateStatus(applicationId, credentialsId, CredentialsStatus.IN_USE); | ||
} | ||
|
||
@Override | ||
public void markCredentialsRevoked(String applicationId, String credentialsId) throws CredentialsServiceException { | ||
this.updateStatus(applicationId, credentialsId, CredentialsStatus.REVOKED); | ||
} | ||
|
||
private void updateStatus(String applicationId, String credentialsId, CredentialsStatus status) throws CredentialsServiceException { | ||
Validate.notBlank(applicationId, "Invalid application ID provided!"); | ||
Validate.notBlank(credentialsId, "Invalid credentials ID provided!"); | ||
try { | ||
this.credentialsDao.updateStatus(applicationId, credentialsId, status); | ||
} catch (Exception cause) { | ||
String message = MessageFormat.format("[{0}] An unexpected exception occured while updating credentials [{1}]", applicationId, credentialsId); | ||
LOG.error(message, cause); | ||
throw new CredentialsServiceException(cause); | ||
} | ||
} | ||
} |
Oops, something went wrong.