Skip to content

Commit

Permalink
Merge pull request #148 from /issues/146-refactor-structure
Browse files Browse the repository at this point in the history
Fix #146: Refactor package and class structure
  • Loading branch information
romanstrobl authored Apr 16, 2024
2 parents e1b85ae + 2f72153 commit 6905625
Show file tree
Hide file tree
Showing 17 changed files with 51 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore;
package com.wultra.security.userdatastore.config;

import com.wultra.core.audit.base.Audit;
import com.wultra.core.audit.base.AuditFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore;
package com.wultra.security.userdatastore.config;

import io.swagger.v3.oas.annotations.OpenAPIDefinition;
import io.swagger.v3.oas.annotations.info.Contact;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore;
package com.wultra.security.userdatastore.config;

import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore;
package com.wultra.security.userdatastore.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore;
package com.wultra.security.userdatastore.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.info.BuildProperties;
Expand All @@ -32,7 +32,7 @@
@Controller
class HomeController {

private BuildProperties buildProperties;
private final BuildProperties buildProperties;

public HomeController(@Autowired(required = false) final BuildProperties buildProperties) {
this.buildProperties = buildProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore.userclaims;
package com.wultra.security.userdatastore.controller;

import com.wultra.security.userdatastore.model.error.ClaimNotFoundException;
import com.wultra.security.userdatastore.model.error.EncryptionException;
import com.wultra.security.userdatastore.model.error.InvalidRequestException;
import com.wultra.security.userdatastore.service.UserClaimsService;
import io.getlime.core.rest.model.base.response.ErrorResponse;
import io.getlime.core.rest.model.base.response.ObjectResponse;
import io.getlime.core.rest.model.base.response.Response;
Expand Down Expand Up @@ -59,14 +63,14 @@ public ErrorResponse handleInvalidRequestException(final RuntimeException e) {
}

/**
* Exception handler for {@link NotFoundException}.
* Exception handler for {@link ClaimNotFoundException}.
*
* @param e Exception.
* @return Response with error details.
*/
@ExceptionHandler(NotFoundException.class)
@ExceptionHandler(ClaimNotFoundException.class)
@ResponseStatus(HttpStatus.BAD_REQUEST)
public ErrorResponse handleNotFoundException(final NotFoundException e) {
public ErrorResponse handleNotFoundException(final ClaimNotFoundException e) {
logger.warn("Error occurred when processing request object.", e);
return new ErrorResponse("NOT_FOUND", e.getMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore;
package com.wultra.security.userdatastore.errorhandling;

import io.getlime.core.rest.model.base.response.ErrorResponse;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -33,7 +33,7 @@
*/
@ControllerAdvice
@Slf4j
public class DefaultExceptionHandler {
class DefaultExceptionHandler {

/**
* Exception handler for no resource found.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore.userclaims;
package com.wultra.security.userdatastore.model.entity;

/**
* Encryption mode.
*
* @author Lubos Racansky, [email protected]
*/
enum EncryptionMode {
public enum EncryptionMode {

/**
* No encryption.
Expand All @@ -32,5 +32,5 @@ enum EncryptionMode {
/**
* AES encryption with HMAC-based index.
*/
AES_HMAC;
AES_HMAC
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore.userclaims;
package com.wultra.security.userdatastore.model.entity;

import jakarta.persistence.*;
import lombok.Getter;
Expand All @@ -33,7 +33,7 @@
@Table(name = "uds_user_claims")
@Getter
@Setter
class UserClaimsEntity {
public class UserClaimsEntity {

@Id
private String userId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore.userclaims;
package com.wultra.security.userdatastore.model.error;

/**
* Exception to be thrown when the requested entity is not found.
* Exception to be thrown when the requested claim is not found.
*
* @author Lubos Racansky, [email protected]
*/
class NotFoundException extends RuntimeException {
public class ClaimNotFoundException extends RuntimeException {

/**
* No-arg constructor.
*/
public NotFoundException() {
public ClaimNotFoundException() {
}

/**
* Constructs a new exception with the specified message.
*
* @param message message
*/
public NotFoundException(String message) {
public ClaimNotFoundException(String message) {
super(message);
}

Expand All @@ -44,7 +44,7 @@ public NotFoundException(String message) {
*
* @param cause cause
*/
public NotFoundException(Throwable cause) {
public ClaimNotFoundException(Throwable cause) {
super(cause);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore.userclaims;
package com.wultra.security.userdatastore.model.error;

/**
* Exception to be thrown when there is a problem at encryption layer.
*
* @author Lubos Racansky, [email protected]
*/
class EncryptionException extends RuntimeException {
public class EncryptionException extends RuntimeException {

/**
* No-arg constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore.userclaims;
package com.wultra.security.userdatastore.model.error;

/**
* Exception to be thrown when the user's request is invalid.
*
* @author Lubos Racansky, [email protected]
*/
class InvalidRequestException extends RuntimeException {
public class InvalidRequestException extends RuntimeException {

/**
* No-arg constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore.userclaims;
package com.wultra.security.userdatastore.model.repository;

import com.wultra.security.userdatastore.model.entity.UserClaimsEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand All @@ -26,6 +27,6 @@
* @author Lubos Racansky [email protected]
*/
@Repository
interface UserClaimsRepository extends JpaRepository<UserClaimsEntity, String> {
public interface UserClaimsRepository extends JpaRepository<UserClaimsEntity, String> {

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore.userclaims;
package com.wultra.security.userdatastore.service;

import com.wultra.security.userdatastore.model.entity.EncryptionMode;
import com.wultra.security.userdatastore.model.entity.UserClaimsEntity;
import com.wultra.security.userdatastore.model.error.EncryptionException;
import io.getlime.security.powerauth.crypto.lib.generator.KeyGenerator;
import io.getlime.security.powerauth.crypto.lib.model.exception.CryptoProviderException;
import io.getlime.security.powerauth.crypto.lib.model.exception.GenericCryptoException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore.userclaims;
package com.wultra.security.userdatastore.service;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.wultra.core.audit.base.Audit;
import com.wultra.core.audit.base.model.AuditDetail;
import com.wultra.security.userdatastore.model.entity.UserClaimsEntity;
import com.wultra.security.userdatastore.model.error.ClaimNotFoundException;
import com.wultra.security.userdatastore.model.error.InvalidRequestException;
import com.wultra.security.userdatastore.model.repository.UserClaimsRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
Expand All @@ -38,7 +42,7 @@
@Service
@Transactional
@Slf4j
class UserClaimsService {
public class UserClaimsService {

private final UserClaimsRepository userClaimsRepository;

Expand All @@ -60,7 +64,7 @@ public Object fetchUserClaims(final String userId) {
final String claims = userClaimsRepository.findById(userId)
.map(encryptionService::decryptClaims)
.orElseThrow(() ->
new NotFoundException("Claims for user ID: '%s' not found".formatted(userId)));
new ClaimNotFoundException("Claims for user ID: '%s' not found".formatted(userId)));
audit("Retrieved claims of user ID: {}", userId);
try {
return objectMapper.readValue(claims, new TypeReference<>() {});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore.userclaims;
package com.wultra.security.userdatastore.controller;

import com.wultra.security.userdatastore.WebSecurityConfiguration;
import com.wultra.security.userdatastore.config.WebSecurityConfiguration;
import com.wultra.security.userdatastore.service.UserClaimsService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.wultra.security.userdatastore.userclaims;
package com.wultra.security.userdatastore.service;

import com.wultra.security.userdatastore.model.entity.EncryptionMode;
import com.wultra.security.userdatastore.model.entity.UserClaimsEntity;
import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
Expand Down

0 comments on commit 6905625

Please sign in to comment.