Skip to content

Commit

Permalink
Merge pull request #4 from jazz-community/use-exposed-log
Browse files Browse the repository at this point in the history
Use parent logging object exposed to service
  • Loading branch information
SBI- authored Jul 25, 2018
2 parents 717b6ff + 471fe57 commit d5b5d5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.google.gson.JsonObject;
import com.ibm.team.repository.common.IContributor;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.common.util.JazzLog;
import com.ibm.team.repository.service.TeamRawService;
import com.siemens.bt.jazz.services.PersonalTokenService.internal.BuildSecretsHelper;
import com.siemens.bt.jazz.services.PersonalTokenService.internal.BuildSecretsReader;
Expand All @@ -23,8 +22,6 @@
import java.security.GeneralSecurityException;

public class TokenReaderService extends AbstractRestService {
private static final JazzLog logger = JazzLog.getLog(TokenReaderService.class);

public TokenReaderService(Log log, HttpServletRequest request, HttpServletResponse response, RestRequest restRequest, TeamRawService parentService) {
super(log, request, response, restRequest, parentService);
}
Expand All @@ -44,13 +41,13 @@ public void execute() throws IOException, URISyntaxException, AuthenticationExce
securedValue = BuildSecretsReader.getSecretByContributor(parentService, user, hashedKey);
userToken = Crypto.decrypt(securedValue, privateKey);
} catch (GeneralSecurityException ex) {
logger.error("[PTS] Token Service decryption failed for user '" + user.getUserId() + "'. Error message: " + ex.getMessage());
log.error("[PTS] Token Service decryption failed for user '" + user.getUserId() + "'. Error message: " + ex.getMessage());
response.setStatus(500);
} catch (UnsupportedEncodingException ex) {
logger.error("[PTS] Token Service decryption failed due to encoding issues for user '" + user.getUserId() + "'. Error message: " + ex.getMessage());
log.error("[PTS] Token Service decryption failed due to encoding issues for user '" + user.getUserId() + "'. Error message: " + ex.getMessage());
response.setStatus(500);
} catch (TeamRepositoryException ex) {
logger.error("[PTS] Problem reading Build Secrets Store for user '" + user.getUserId() + "'. Error message: " + ex.getMessage());
log.error("[PTS] Problem reading Build Secrets Store for user '" + user.getUserId() + "'. Error message: " + ex.getMessage());
response.setStatus(500);
}

Expand All @@ -59,7 +56,7 @@ public void execute() throws IOException, URISyntaxException, AuthenticationExce
formattedResponse.addProperty("token", userToken);
response.getWriter().write(formattedResponse.toString());
response.setStatus(200);
logger.info("[PTS] Token read for '" + user.getUserId() + "'");
log.info("[PTS] Token read for '" + user.getUserId() + "'");
} else {
response.setStatus(404);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.security.GeneralSecurityException;

public final class TokenWriterService extends AbstractRestService {
private static final JazzLog logger = JazzLog.getLog(TokenWriterService.class);

public TokenWriterService(Log log, HttpServletRequest request, HttpServletResponse response, RestRequest restRequest, TeamRawService parentService) {
super(log, request, response, restRequest, parentService);
Expand All @@ -48,16 +47,16 @@ public void execute() throws IOException, URISyntaxException, AuthenticationExce
try {
String encryptedToken = Crypto.encrypt(token, privateKey);
BuildSecretsWriter.storeSecret(parentService, user, hashedKey, encryptedToken);
logger.info("[PTS] Token created by '" + user.getUserId() + "'");
log.info("[PTS] Token created by '" + user.getUserId() + "'");
response.setStatus(201);
} catch (GeneralSecurityException ex) {
logger.error("[PTS] Token Service encryption failed for user '" + user.getUserId() + "'. Error message: " + ex.getMessage());
log.error("[PTS] Token Service encryption failed for user '" + user.getUserId() + "'. Error message: " + ex.getMessage());
response.setStatus(500);
} catch (UnsupportedEncodingException ex) {
logger.error("[PTS] Token Service encryption failed due to encoding issues for user '" + user.getUserId() + "'. Error message: " + ex.getMessage());
log.error("[PTS] Token Service encryption failed due to encoding issues for user '" + user.getUserId() + "'. Error message: " + ex.getMessage());
response.setStatus(500);
} catch (TeamRepositoryException ex) {
logger.error("[PTS] Problem writing to Build Secrets Store for user '" + user.getUserId() + "'. Error message: " + ex.getMessage());
log.error("[PTS] Problem writing to Build Secrets Store for user '" + user.getUserId() + "'. Error message: " + ex.getMessage());
response.setStatus(500);
}
} else {
Expand Down

0 comments on commit d5b5d5e

Please sign in to comment.