This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository pollen. See https://gitlab.nuiton.org/chorem/pollen.git commit aaa8e2b8f706fb10855cfccabb9f0c8688da68d4 Author: dcosse <cosse@codelutin.com> Date: Thu Oct 10 13:41:23 2019 +0200 fix some Sonar Issus --- .../pollen/services/service/CryptoService.java | 74 +++++++++++++++------- .../pollen/services/service/SocialAuthService.java | 43 +++++++------ 2 files changed, 72 insertions(+), 45 deletions(-) diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/CryptoService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/CryptoService.java index 6dd1d90d..9d605c58 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/CryptoService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/CryptoService.java @@ -126,24 +126,35 @@ public class CryptoService extends PollenServiceSupport { protected byte[] compressMessage(byte[] message) throws IOException { ByteArrayOutputStream bOut = new ByteArrayOutputStream(); - PGPCompressedDataGenerator comData = new PGPCompressedDataGenerator(CompressionAlgorithmTags.ZIP); - OutputStream cos = comData.open(bOut); // open it with the final destination - - PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator(); + OutputStream pOut = null; + PGPCompressedDataGenerator comData = null; // we want to generate compressed data. This might be a user option later, // in which case we would pass in bOut. - OutputStream pOut = lData.open(cos, // the compressed output stream - PGPLiteralData.BINARY, - PGPLiteralDataGenerator.CONSOLE, // "filename" to store - message.length, // length of clear data - new Date() // current time - ); - - pOut.write(message); - pOut.close(); - - comData.close(); + try { + comData = new PGPCompressedDataGenerator(CompressionAlgorithmTags.ZIP); + OutputStream cos = comData.open(bOut); // open it with the final destination + + PGPLiteralDataGenerator lData = new PGPLiteralDataGenerator(); + + pOut = lData.open(cos, // the compressed output stream + PGPLiteralData.BINARY, + PGPLiteralDataGenerator.CONSOLE, // "filename" to store + message.length, // length of clear data + new Date() // current time + ); + pOut.write(message); + } catch(Exception e) { + log.error(e); + throw e; + } finally { + if (pOut != null) { + pOut.close(); + } + if (comData != null) { + comData.close(); + } + } return bOut.toByteArray(); } @@ -154,15 +165,30 @@ public class CryptoService extends PollenServiceSupport { ByteArrayOutputStream bout = new ByteArrayOutputStream(); - OutputStream out = new ArmoredOutputStream(bout); - - PGPEncryptedDataGenerator encryptedDataGenerator = createEncryptedDataGenerator(pgpPublicKey); - - OutputStream encOut = encryptedDataGenerator.open(out, compressMessage.length); - - encOut.write(compressMessage); - encOut.close(); - out.close(); + OutputStream out = null; + OutputStream encOut = null; + + try { + out = new ArmoredOutputStream(bout); + + PGPEncryptedDataGenerator encryptedDataGenerator = createEncryptedDataGenerator(pgpPublicKey); + + encOut = encryptedDataGenerator.open(out, compressMessage.length); + + encOut.write(compressMessage); + + } catch (Exception e) { + log.error(e); + throw e; + } finally { + + if (encOut != null) { + encOut.close(); + } + if (out != null) { + out.close(); + } + } return bout.toByteArray(); diff --git a/pollen-services/src/main/java/org/chorem/pollen/services/service/SocialAuthService.java b/pollen-services/src/main/java/org/chorem/pollen/services/service/SocialAuthService.java index d1c3bab8..9481c538 100644 --- a/pollen-services/src/main/java/org/chorem/pollen/services/service/SocialAuthService.java +++ b/pollen-services/src/main/java/org/chorem/pollen/services/service/SocialAuthService.java @@ -21,6 +21,7 @@ package org.chorem.pollen.services.service; * #L% */ +import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -238,27 +239,27 @@ public class SocialAuthService extends PollenServiceSupport { public List<String> getAvailableLoginProviders() { checkIsAdmin(); - return new ArrayList<String>() {{ - add(Constants.AMAZON); - add(Constants.FACEBOOK); - add(Constants.FLICKR); - add(Constants.FOURSQUARE); - add(Constants.GITHUB); - add(Constants.GOOGLE_PLUS); - add(Constants.HOTMAIL); - add(Constants.INSTAGRAM); - add(Constants.LINKEDIN); - add(Constants.LINKEDINOAUTH2); - add(Constants.MENDELEY); - add(Constants.MYSPACE); - add(Constants.NIMBLE); - add(Constants.RUNKEEPER); - add(Constants.SALESFORCE); - add(Constants.STACK_EXCHANGE); - add(Constants.TWITTER); - add(Constants.YAHOO); - add(Constants.YAMMER); - }}; + return Lists.newArrayList( + Constants.AMAZON, + Constants.FACEBOOK, + Constants.FLICKR, + Constants.FOURSQUARE, + Constants.GITHUB, + Constants.GOOGLE_PLUS, + Constants.HOTMAIL, + Constants.INSTAGRAM, + Constants.LINKEDIN, + Constants.LINKEDINOAUTH2, + Constants.MENDELEY, + Constants.MYSPACE, + Constants.NIMBLE, + Constants.RUNKEEPER, + Constants.SALESFORCE, + Constants.STACK_EXCHANGE, + Constants.TWITTER, + Constants.YAHOO, + Constants.YAMMER + ); } public LoginProviderBean saveLoginProvider(LoginProviderBean loginProvider, boolean loginProviderExists) { -- To stop receiving notification emails like this one, please contact chorem.org SCM administrator <admin+scm@chorem.org>.