*
* ============LICENSE_END============================================
*
- * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
*/
package org.onap.portalapp.portal.service;
import org.onap.portalapp.portal.domain.EPEndpoint;
import org.onap.portalapp.portal.domain.EPEndpointAccount;
import org.onap.portalapp.portal.logging.aop.EPMetricsLog;
+import org.onap.portalapp.portal.utils.EPCommonSystemProperties;
+import org.onap.portalapp.validation.DataValidator;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.onboarding.util.CipherUtil;
+import org.onap.portalsdk.core.onboarding.util.KeyConstants;
+import org.onap.portalsdk.core.onboarding.util.KeyProperties;
import org.onap.portalsdk.core.service.DataAccessService;
import org.onap.portalsdk.core.util.SystemProperties;
import org.springframework.beans.factory.annotation.Autowired;
@EPMetricsLog
public class BasicAuthAccountServiceImpl implements BasicAuthAccountService{
EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MicroserviceServiceImpl.class);
-
+ private final DataValidator dataValidator = new DataValidator();
@Autowired
private DataAccessService dataAccessService;
@Override
public Long saveBasicAuthAccount(BasicAuthCredentials newCredential) throws Exception {
+
+ if(!dataValidator.isValid(newCredential)){
+ throw new Exception("saveBasicAuthAccount() failed, new credential are not safe");
+ }
if (newCredential.getPassword() != null)
newCredential.setPassword(encryptedPassword(newCredential.getPassword()));
try{
public void updateBasicAuthAccount(Long accountId, BasicAuthCredentials newCredential) throws Exception {
try {
newCredential.setId(accountId);
- if (newCredential.getPassword() != null)
- newCredential.setPassword(encryptedPassword(newCredential.getPassword()));
+ if (newCredential.getPassword() != null){
+ if(newCredential.getPassword().equals(EPCommonSystemProperties.APP_DISPLAY_PASSWORD)){
+ BasicAuthCredentials oldMS = getBasicAuthCredentialsById(accountId);
+ newCredential.setPassword(oldMS.getPassword()); // keep the old password
+ }else
+ newCredential.setPassword(encryptedPassword(newCredential.getPassword())); //new password
+ }
getDataAccessService().saveDomainObject(newCredential, null);
List<EPEndpoint> endpoints = newCredential.getEndpoints();
List<BasicAuthCredentials> list = (List<BasicAuthCredentials>) dataAccessService.getList(BasicAuthCredentials.class, null);
for (int i = 0; i < list.size(); i++) {
if (list.get(i).getPassword() != null)
- list.get(i).setPassword(decryptedPassword(list.get(i).getPassword()));
+ list.get(i).setPassword(EPCommonSystemProperties.APP_DISPLAY_PASSWORD);
list.get(i).setEndpoints(getEPEndpoints(list.get(i).getId()));
}
return list;
private String decryptedPassword(String encryptedPwd) throws Exception {
String result = "";
- if (encryptedPwd != null & encryptedPwd.length() > 0) {
+ if (encryptedPwd != null && encryptedPwd.length() > 0) {
try {
result = CipherUtil.decryptPKC(encryptedPwd,
- SystemProperties.getProperty(SystemProperties.Decryption_Key));
+ KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY));
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "decryptedPassword() failed", e);
throw e;
private String encryptedPassword(String decryptedPwd) throws Exception {
String result = "";
- if (decryptedPwd != null & decryptedPwd.length() > 0) {
+ if (decryptedPwd != null && decryptedPwd.length() > 0) {
try {
result = CipherUtil.encryptPKC(decryptedPwd,
- SystemProperties.getProperty(SystemProperties.Decryption_Key));
+ KeyProperties.getProperty(KeyConstants.CIPHER_ENCRYPTION_KEY));
} catch (Exception e) {
logger.error(EELFLoggerDelegate.errorLogger, "encryptedPassword() failed", e);
throw e;
public DataAccessService getDataAccessService() {
return dataAccessService;
}
+
+ @Override
+ public BasicAuthCredentials getBasicAuthCredentialsById(long id) throws Exception {
+ try {
+ @SuppressWarnings("unchecked")
+ List<BasicAuthCredentials> list = (List<BasicAuthCredentials>) dataAccessService
+ .getList(BasicAuthCredentials.class, null);
+ for (BasicAuthCredentials auth : list) {
+ if (auth != null && auth.getId() == id)
+ return auth;
+ }
+ } catch (Exception e) {
+ logger.error(EELFLoggerDelegate.errorLogger, "getBasicAuthCredentialsDataById failed", e);
+ throw e;
+ }
+ return null;
+
+ }
}