From 3100ee93d5b7a8b35d54d7ff0e9529bae792f074 Mon Sep 17 00:00:00 2001 From: Justin Field Date: Mon, 3 Apr 2017 17:23:33 -0700 Subject: [PATCH] Feature/add principal event logging (#30) Added logging to endpoints to log what principal is attempting to invoke them --- .../nike/cerberus/dao/SafeDepositBoxDao.java | 4 ++++ .../endpoints/AdminStandardEndpoint.java | 13 +++++++++++++ .../endpoints/admin/PutSDBMetadata.java | 11 ++++++++++- .../authentication/AuthenticateIamRoleV1.java | 17 ++++++++++++++--- .../authentication/AuthenticateIamRoleV2.java | 16 +++++++++++++--- .../authentication/AuthenticateUser.java | 7 +++++++ .../authentication/RefreshUserToken.java | 8 ++++++++ .../endpoints/authentication/RevokeToken.java | 7 +++++++ .../endpoints/sdb/CreateSafeDepositBox.java | 8 ++++++++ .../endpoints/sdb/DeleteSafeDepositBox.java | 14 +++++++++++++- .../endpoints/sdb/GetSafeDepositBox.java | 14 +++++++++++++- .../endpoints/sdb/GetSafeDepositBoxes.java | 7 +++++++ .../endpoints/sdb/UpdateSafeDepositBox.java | 14 +++++++++++++- .../cerberus/mapper/SafeDepositBoxMapper.java | 2 ++ .../cerberus/service/SafeDepositBoxService.java | 9 +++++++++ .../cerberus/mapper/SafeDepositBoxMapper.xml | 4 ++++ 16 files changed, 145 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/nike/cerberus/dao/SafeDepositBoxDao.java b/src/main/java/com/nike/cerberus/dao/SafeDepositBoxDao.java index de18cb28c..23305d8e8 100644 --- a/src/main/java/com/nike/cerberus/dao/SafeDepositBoxDao.java +++ b/src/main/java/com/nike/cerberus/dao/SafeDepositBoxDao.java @@ -85,4 +85,8 @@ public String getSafeDepositBoxIdByName(String name) { return safeDepositBoxMapper.getSafeDepositBoxIdByName(name); } + public String getSafeDepositBoxNameById(String id) { + return safeDepositBoxMapper.getSafeDepositBoxNameById(id); + } + } diff --git a/src/main/java/com/nike/cerberus/endpoints/AdminStandardEndpoint.java b/src/main/java/com/nike/cerberus/endpoints/AdminStandardEndpoint.java index f045a54da..e2757bd6d 100644 --- a/src/main/java/com/nike/cerberus/endpoints/AdminStandardEndpoint.java +++ b/src/main/java/com/nike/cerberus/endpoints/AdminStandardEndpoint.java @@ -24,6 +24,8 @@ import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; import io.netty.channel.ChannelHandlerContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.ws.rs.core.SecurityContext; import java.util.Optional; @@ -35,13 +37,24 @@ */ public abstract class AdminStandardEndpoint extends StandardEndpoint { + private final Logger log = LoggerFactory.getLogger(getClass()); + public final CompletableFuture> execute(final RequestInfo request, final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx) { + final Optional securityContext = CmsRequestSecurityValidator.getSecurityContextForRequest(request); + String principal = securityContext.isPresent() ? + securityContext.get().getUserPrincipal() instanceof VaultAuthPrincipal ? + securityContext.get().getUserPrincipal().getName() : + "( Principal is not a Vault auth principal. )" : "( Principal name is empty. )"; + + log.info("Admin Endpoint Event: the principal {} is attempting to access admin endpoint: {}", principal, this.getClass().getName()); if (!securityContext.isPresent() || !securityContext.get().isUserInRole(VaultAuthPrincipal.ROLE_ADMIN)) { + log.error("Admin Endpoint Event: the principal {} is attempted to access {}, an admin endpoint but was not an admin", principal, + this.getClass().getName()); throw new ApiException(DefaultApiError.ACCESS_DENIED); } diff --git a/src/main/java/com/nike/cerberus/endpoints/admin/PutSDBMetadata.java b/src/main/java/com/nike/cerberus/endpoints/admin/PutSDBMetadata.java index 4c5946dd3..479583640 100644 --- a/src/main/java/com/nike/cerberus/endpoints/admin/PutSDBMetadata.java +++ b/src/main/java/com/nike/cerberus/endpoints/admin/PutSDBMetadata.java @@ -27,6 +27,8 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpResponseStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.ws.rs.core.SecurityContext; import java.util.concurrent.CompletableFuture; @@ -37,6 +39,8 @@ */ public class PutSDBMetadata extends AdminStandardEndpoint { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final MetadataService metadataService; @Inject @@ -52,7 +56,12 @@ public CompletableFuture> doExecute(RequestInfo return CompletableFuture.supplyAsync(() -> { VaultAuthPrincipal vaultAuthPrincipal = (VaultAuthPrincipal) securityContext.getUserPrincipal(); - metadataService.restoreMetadata(request.getContent(), vaultAuthPrincipal.getName()); + + String principal = vaultAuthPrincipal.getName(); + + log.info("Metadata Restore Event: the principal {} is attempting to restore sdb name: '{}'", principal, request.getContent().getName()); + + metadataService.restoreMetadata(request.getContent(), principal); return ResponseInfo.newBuilder() .withHttpStatusCode(HttpResponseStatus.NO_CONTENT.code()) diff --git a/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamRoleV1.java b/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamRoleV1.java index a3fdc89c8..26c24125c 100644 --- a/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamRoleV1.java +++ b/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamRoleV1.java @@ -19,12 +19,15 @@ import com.nike.cerberus.domain.IamRoleAuthResponse; import com.nike.cerberus.domain.IamRoleCredentialsV1; import com.nike.cerberus.service.AuthenticationService; +import com.nike.cerberus.util.AwsIamRoleArnParser; import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import java.util.concurrent.CompletableFuture; @@ -37,6 +40,8 @@ @Deprecated public class AuthenticateIamRoleV1 extends StandardEndpoint { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final AuthenticationService authenticationService; @Inject @@ -48,9 +53,15 @@ public AuthenticateIamRoleV1(final AuthenticationService authenticationService) public CompletableFuture> execute(final RequestInfo request, final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> - ResponseInfo.newBuilder(authenticationService.authenticate(request.getContent())).build(), - longRunningTaskExecutor); + return CompletableFuture.supplyAsync(() -> { + IamRoleCredentialsV1 credentials = request.getContent(); + log.info("IAM Auth Event: the IAM principal {} in attempting to authenticate in region {}", + String.format(AwsIamRoleArnParser.AWS_IAM_ROLE_ARN_TEMPLATE, + credentials.getAccountId(), credentials.getRoleName()), credentials.getRegion()); + + return ResponseInfo.newBuilder(authenticationService.authenticate(request.getContent())).build(); + }, longRunningTaskExecutor); + } @Override diff --git a/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamRoleV2.java b/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamRoleV2.java index f08221c0f..7086a8892 100644 --- a/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamRoleV2.java +++ b/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateIamRoleV2.java @@ -18,14 +18,18 @@ package com.nike.cerberus.endpoints.authentication; import com.nike.cerberus.domain.IamRoleAuthResponse; +import com.nike.cerberus.domain.IamRoleCredentialsV1; import com.nike.cerberus.domain.IamRoleCredentialsV2; import com.nike.cerberus.service.AuthenticationService; +import com.nike.cerberus.util.AwsIamRoleArnParser; import com.nike.riposte.server.http.RequestInfo; import com.nike.riposte.server.http.ResponseInfo; import com.nike.riposte.server.http.StandardEndpoint; import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import java.util.concurrent.CompletableFuture; @@ -37,6 +41,8 @@ */ public class AuthenticateIamRoleV2 extends StandardEndpoint { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final AuthenticationService authenticationService; @Inject @@ -48,9 +54,13 @@ public AuthenticateIamRoleV2(final AuthenticationService authenticationService) public CompletableFuture> execute(final RequestInfo request, final Executor longRunningTaskExecutor, final ChannelHandlerContext ctx) { - return CompletableFuture.supplyAsync(() -> - ResponseInfo.newBuilder(authenticationService.authenticate(request.getContent())).build(), - longRunningTaskExecutor); + return CompletableFuture.supplyAsync(() -> { + IamRoleCredentialsV2 credentials = request.getContent(); + log.info("IAM Auth Event: the IAM principal {} in attempting to authenticate in region {}", + credentials.getRoleArn(), credentials.getRegion()); + + return ResponseInfo.newBuilder(authenticationService.authenticate(request.getContent())).build(); + }, longRunningTaskExecutor); } @Override diff --git a/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateUser.java b/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateUser.java index fef26db0f..d456ab72f 100644 --- a/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateUser.java +++ b/src/main/java/com/nike/cerberus/endpoints/authentication/AuthenticateUser.java @@ -29,6 +29,8 @@ import io.netty.handler.codec.http.HttpMethod; import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.ArrayUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.ws.rs.core.HttpHeaders; @@ -41,6 +43,8 @@ */ public class AuthenticateUser extends StandardEndpoint { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final AuthenticationService authenticationService; @Inject @@ -56,6 +60,9 @@ public CompletableFuture> execute(final RequestInfo { final UserCredentials credentials = extractCredentials(request.getHeaders().get(HttpHeaders.AUTHORIZATION)); + + log.info("User Auth Event: the principal: {} is attempting to authenticate", credentials.getUsername()); + return ResponseInfo.newBuilder(authenticationService.authenticate(credentials)).build(); }, longRunningTaskExecutor diff --git a/src/main/java/com/nike/cerberus/endpoints/authentication/RefreshUserToken.java b/src/main/java/com/nike/cerberus/endpoints/authentication/RefreshUserToken.java index a5a473d38..e3411c67a 100644 --- a/src/main/java/com/nike/cerberus/endpoints/authentication/RefreshUserToken.java +++ b/src/main/java/com/nike/cerberus/endpoints/authentication/RefreshUserToken.java @@ -28,6 +28,8 @@ import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.ws.rs.core.SecurityContext; @@ -40,6 +42,8 @@ */ public class RefreshUserToken extends StandardEndpoint { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final AuthenticationService authenticationService; @Inject @@ -62,6 +66,10 @@ public ResponseInfo getRefreshedUserToken(final RequestInfo CmsRequestSecurityValidator.getSecurityContextForRequest(request); if (securityContext.isPresent()) { + final VaultAuthPrincipal vaultAuthPrincipal = + (VaultAuthPrincipal) securityContext.get().getUserPrincipal(); + log.info("Refresh User Token Auth Event: the principal: {} is attempting to refresh its token", vaultAuthPrincipal.getName()); + return ResponseInfo.newBuilder( authenticationService.refreshUserToken( (VaultAuthPrincipal) securityContext.get().getUserPrincipal())).build(); diff --git a/src/main/java/com/nike/cerberus/endpoints/authentication/RevokeToken.java b/src/main/java/com/nike/cerberus/endpoints/authentication/RevokeToken.java index 893e7302b..ccef04de2 100644 --- a/src/main/java/com/nike/cerberus/endpoints/authentication/RevokeToken.java +++ b/src/main/java/com/nike/cerberus/endpoints/authentication/RevokeToken.java @@ -28,6 +28,8 @@ import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpResponseStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.ws.rs.core.SecurityContext; @@ -40,6 +42,8 @@ */ public class RevokeToken extends StandardEndpoint { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final AuthenticationService authenticationService; @Inject @@ -61,6 +65,9 @@ public ResponseInfo revokeToken(RequestInfo request) { if (securityContext.isPresent()) { final VaultAuthPrincipal vaultAuthPrincipal = (VaultAuthPrincipal) securityContext.get().getUserPrincipal(); + + log.info("Delete Token Auth Event: the principal: {} is attempting to delete a token", vaultAuthPrincipal.getName()); + authenticationService.revoke(vaultAuthPrincipal.getClientToken().getId()); return ResponseInfo.newBuilder().withHttpStatusCode(HttpResponseStatus.NO_CONTENT.code()).build(); } diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/CreateSafeDepositBox.java b/src/main/java/com/nike/cerberus/endpoints/sdb/CreateSafeDepositBox.java index 5ccebcf04..298820c47 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/CreateSafeDepositBox.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/CreateSafeDepositBox.java @@ -31,6 +31,8 @@ import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpResponseStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.ws.rs.core.SecurityContext; @@ -46,6 +48,8 @@ */ public class CreateSafeDepositBox extends StandardEndpoint> { + private final Logger log = LoggerFactory.getLogger(getClass()); + public static final String BASE_PATH = "/v1/safe-deposit-box"; public static final String HEADER_X_REFRESH_TOKEN = "X-Refresh-Token"; @@ -71,6 +75,10 @@ private ResponseInfo> createSafeDepositBox(final RequestInfo if (securityContext.isPresent()) { final VaultAuthPrincipal vaultAuthPrincipal = (VaultAuthPrincipal) securityContext.get().getUserPrincipal(); + + log.info("Create SDB Event: the principal: {} is attempting to create sdb name: '{}'", + vaultAuthPrincipal.getName(), request.getContent().getName()); + final String id = safeDepositBoxService.createSafeDepositBox(request.getContent(), vaultAuthPrincipal.getName()); diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/DeleteSafeDepositBox.java b/src/main/java/com/nike/cerberus/endpoints/sdb/DeleteSafeDepositBox.java index 70feca9dd..8334880b0 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/DeleteSafeDepositBox.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/DeleteSafeDepositBox.java @@ -29,6 +29,8 @@ import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpResponseStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.ws.rs.core.SecurityContext; @@ -41,6 +43,8 @@ */ public class DeleteSafeDepositBox extends StandardEndpoint { + private final Logger log = LoggerFactory.getLogger(getClass()); + public static final String HEADER_X_REFRESH_TOKEN = "X-Refresh-Token"; private final SafeDepositBoxService safeDepositBoxService; @@ -61,7 +65,15 @@ private ResponseInfo deleteSafeDepositBox(final RequestInfo request) if (securityContext.isPresent()) { final VaultAuthPrincipal vaultAuthPrincipal = (VaultAuthPrincipal) securityContext.get().getUserPrincipal(); - safeDepositBoxService.deleteSafeDepositBox(vaultAuthPrincipal.getUserGroups(), request.getPathParam("id")); + + String sdbId = request.getPathParam("id"); + Optional sdbNameOptional = safeDepositBoxService.getSafeDepositBoxNameById(sdbId); + String sdbName = sdbNameOptional.isPresent() ? sdbNameOptional.get() : + String.format("(Failed to lookup name from id: %s)", sdbId); + log.info("Delete SDB Event: the principal: {} is attempting to delete sdb name: '{}' and id: '{}'", + vaultAuthPrincipal.getName(), sdbName, sdbId); + + safeDepositBoxService.deleteSafeDepositBox(vaultAuthPrincipal.getUserGroups(), sdbId); return ResponseInfo.newBuilder().withHttpStatusCode(HttpResponseStatus.OK.code()) .withHeaders(new DefaultHttpHeaders().set(HEADER_X_REFRESH_TOKEN, Boolean.TRUE.toString())) .build(); diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBox.java b/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBox.java index 084294c9b..df9e8ab99 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBox.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBox.java @@ -29,6 +29,8 @@ import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.ws.rs.core.SecurityContext; @@ -42,6 +44,8 @@ */ public class GetSafeDepositBox extends StandardEndpoint { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final SafeDepositBoxService safeDepositBoxService; @Inject @@ -62,10 +66,18 @@ public ResponseInfo getSafeDepositBox(final RequestInfo re if (securityContext.isPresent()) { final VaultAuthPrincipal vaultAuthPrincipal = (VaultAuthPrincipal) securityContext.get().getUserPrincipal(); + + String sdbId = request.getPathParam("id"); + Optional sdbNameOptional = safeDepositBoxService.getSafeDepositBoxNameById(sdbId); + String sdbName = sdbNameOptional.isPresent() ? sdbNameOptional.get() : + String.format("(Failed to lookup name from id: %s)", sdbId); + log.info("Read SDB Event: the principal: {} is attempting to read sdb name: '{}' and id: '{}'", + vaultAuthPrincipal.getName(), sdbName, sdbId); + final Optional safeDepositBox = safeDepositBoxService.getAssociatedSafeDepositBox( vaultAuthPrincipal.getUserGroups(), - request.getPathParam("id")); + sdbId); if (safeDepositBox.isPresent()) { return ResponseInfo.newBuilder(safeDepositBox.get()).build(); diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxes.java b/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxes.java index d890fffdb..e0da81f6f 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxes.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/GetSafeDepositBoxes.java @@ -28,6 +28,8 @@ import com.nike.riposte.util.Matcher; import io.netty.channel.ChannelHandlerContext; import io.netty.handler.codec.http.HttpMethod; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.ws.rs.core.SecurityContext; @@ -42,6 +44,8 @@ */ public class GetSafeDepositBoxes extends StandardEndpoint> { + private final Logger log = LoggerFactory.getLogger(getClass()); + private final SafeDepositBoxService safeDepositBoxService; @Inject @@ -63,6 +67,9 @@ public ResponseInfo> getSafeDepositBoxes(final Reque if (securityContext.isPresent()) { final VaultAuthPrincipal vaultAuthPrincipal = (VaultAuthPrincipal) securityContext.get().getUserPrincipal(); + log.info("List SDB Event: the principal: {} is attempting to list the SDBs that it has access to", + vaultAuthPrincipal.getName()); + return ResponseInfo.newBuilder( safeDepositBoxService.getAssociatedSafeDepositBoxes(vaultAuthPrincipal.getUserGroups())).build(); } diff --git a/src/main/java/com/nike/cerberus/endpoints/sdb/UpdateSafeDepositBox.java b/src/main/java/com/nike/cerberus/endpoints/sdb/UpdateSafeDepositBox.java index 069c3f5b1..b12ce06aa 100644 --- a/src/main/java/com/nike/cerberus/endpoints/sdb/UpdateSafeDepositBox.java +++ b/src/main/java/com/nike/cerberus/endpoints/sdb/UpdateSafeDepositBox.java @@ -31,6 +31,8 @@ import io.netty.handler.codec.http.DefaultHttpHeaders; import io.netty.handler.codec.http.HttpMethod; import io.netty.handler.codec.http.HttpResponseStatus; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import javax.inject.Inject; import javax.ws.rs.core.SecurityContext; @@ -43,6 +45,8 @@ */ public class UpdateSafeDepositBox extends StandardEndpoint { + private final Logger log = LoggerFactory.getLogger(getClass()); + public static final String HEADER_X_REFRESH_TOKEN = "X-Refresh-Token"; private final SafeDepositBoxService safeDepositBoxService; @@ -63,10 +67,18 @@ private ResponseInfo updateSafeDepositBox(final RequestInfo sdbNameOptional = safeDepositBoxService.getSafeDepositBoxNameById(sdbId); + String sdbName = sdbNameOptional.isPresent() ? sdbNameOptional.get() : + String.format("(Failed to lookup name from id: %s)", sdbId); + log.info("Update SDB Event: the principal: {} is attempting to update sdb name: '{}' and id: '{}'", + vaultAuthPrincipal.getName(), sdbName, sdbId); + safeDepositBoxService.updateSafeDepositBox(request.getContent(), vaultAuthPrincipal.getUserGroups(), vaultAuthPrincipal.getName(), - request.getPathParam("id")); + sdbId); return ResponseInfo.newBuilder().withHttpStatusCode(HttpResponseStatus.NO_CONTENT.code()) .withHeaders(new DefaultHttpHeaders().set(HEADER_X_REFRESH_TOKEN, Boolean.TRUE.toString())) .build(); diff --git a/src/main/java/com/nike/cerberus/mapper/SafeDepositBoxMapper.java b/src/main/java/com/nike/cerberus/mapper/SafeDepositBoxMapper.java index 550a494ed..4814106be 100644 --- a/src/main/java/com/nike/cerberus/mapper/SafeDepositBoxMapper.java +++ b/src/main/java/com/nike/cerberus/mapper/SafeDepositBoxMapper.java @@ -51,4 +51,6 @@ public interface SafeDepositBoxMapper { int count(); String getSafeDepositBoxIdByName(@Param("name") String name); + + String getSafeDepositBoxNameById(@Param("id") String id); } diff --git a/src/main/java/com/nike/cerberus/service/SafeDepositBoxService.java b/src/main/java/com/nike/cerberus/service/SafeDepositBoxService.java index 4d935439b..c01036199 100644 --- a/src/main/java/com/nike/cerberus/service/SafeDepositBoxService.java +++ b/src/main/java/com/nike/cerberus/service/SafeDepositBoxService.java @@ -603,6 +603,15 @@ public Optional getSafeDepositBoxIdByName(String name) { return Optional.ofNullable(safeDepositBoxDao.getSafeDepositBoxIdByName(name)); } + /** + * @param id Safe Deposit Box id + * @return The name for the box + */ + public Optional getSafeDepositBoxNameById(String id) { + return Optional.ofNullable(safeDepositBoxDao.getSafeDepositBoxNameById(id)); + } + + /** * Admin method for restoring sdb * @param safeDepositBox Safe Deposit Box to restore diff --git a/src/main/resources/com/nike/cerberus/mapper/SafeDepositBoxMapper.xml b/src/main/resources/com/nike/cerberus/mapper/SafeDepositBoxMapper.xml index 217d97649..a8ec2ffd1 100644 --- a/src/main/resources/com/nike/cerberus/mapper/SafeDepositBoxMapper.xml +++ b/src/main/resources/com/nike/cerberus/mapper/SafeDepositBoxMapper.xml @@ -193,4 +193,8 @@ SELECT id FROM SAFE_DEPOSIT_BOX WHERE NAME = #{name} + + \ No newline at end of file