diff options
Diffstat (limited to 'catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java')
-rw-r--r-- | catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java | 99 |
1 files changed, 28 insertions, 71 deletions
diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java index 783d1fc754..636c7ce140 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/ecomp/EcompIntImpl.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= */ - package org.openecomp.sdc.be.ecomp; import fj.data.Either; @@ -49,10 +48,11 @@ import org.springframework.context.ApplicationContext; import org.springframework.web.context.ContextLoader; public class EcompIntImpl implements IPortalRestAPIService { - private static final String FAILED_TO_CONVERT_ROLES = "Failed to convert Roles"; + public static final String FAILED_TO_GET_ROLES = "Failed to get Roles"; - private static final String GET_USER_ROLES = "GetUserRoles"; public static final String ERROR_FAILED_TO_GET_ROLES = "Error: Failed to get Roles"; + private static final String FAILED_TO_CONVERT_ROLES = "Failed to convert Roles"; + private static final String GET_USER_ROLES = "GetUserRoles"; private static final String PUSH_USER_ROLE = "PushUserRole"; private static final String FAILED_TO_FETCH_ROLES = "Failed to fetch roles"; private static final String FAILED_TO_CONVERT_USER2 = "Failed to convert User {}"; @@ -79,17 +79,13 @@ public class EcompIntImpl implements IPortalRestAPIService { log.debug("Start handle request of ECOMP pushUser"); try { if (user == null) { - BeEcompErrorManager.getInstance() - .logInvalidInputError(PUSH_USER, RECEIVED_NULL_FOR_ARGUMENT_USER, ErrorSeverity.INFO); + BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, RECEIVED_NULL_FOR_ARGUMENT_USER, ErrorSeverity.INFO); log.debug(RECEIVED_NULL_FOR_ARGUMENT_USER); throw new PortalAPIException(RECEIVED_NULL_FOR_ARGUMENT_USER); } - UserBusinessLogic userBusinessLogic = getUserBusinessLogic(); - final String modifierAttId = JH0003; log.debug("modifier id is {}", modifierAttId); - User convertedAsdcUser = EcompUserConverter.convertEcompUserToUser(user); userBusinessLogic.createUser(modifierAttId, convertedAsdcUser); log.debug("User created {}", user); @@ -98,14 +94,12 @@ public class EcompIntImpl implements IPortalRestAPIService { log.debug("User already exist {}", user); } else { log.debug(FAILED_TO_CREATE_USER, user); - BeEcompErrorManager.getInstance() - .logInvalidInputError(PUSH_USER, FAILED_TO_CREATE_USER, ErrorSeverity.ERROR); + BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CREATE_USER, ErrorSeverity.ERROR); throw new PortalAPIException(FAILED_TO_CREATE_USER + ce.getActionStatus()); } } catch (Exception e) { log.debug(FAILED_TO_CREATE_USER, user, e); - BeEcompErrorManager.getInstance() - .logInvalidInputError(PUSH_USER, FAILED_TO_CREATE_USER, ErrorSeverity.ERROR); + BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER, FAILED_TO_CREATE_USER, ErrorSeverity.ERROR); throw new PortalAPIException(FAILED_TO_CREATE_USER, e); } } @@ -120,46 +114,35 @@ public class EcompIntImpl implements IPortalRestAPIService { @Override public void editUser(String loginId, EcompUser user) throws PortalAPIException { log.debug("Start handle request of ECOMP editUser"); - try { if (user == null) { log.debug(RECEIVED_NULL_FOR_ARGUMENT_USER); - BeEcompErrorManager.getInstance() - .logInvalidInputError(EDIT_USER, RECEIVED_NULL_FOR_ARGUMENT_USER, ErrorSeverity.INFO); + BeEcompErrorManager.getInstance().logInvalidInputError(EDIT_USER, RECEIVED_NULL_FOR_ARGUMENT_USER, ErrorSeverity.INFO); throw new PortalAPIException(RECEIVED_NULL_FOR_ARGUMENT_USER); } else if (loginId == null) { log.debug(RECEIVED_NULL_FOR_ARGUMENT_LOGIN_ID); - BeEcompErrorManager.getInstance() - .logInvalidInputError(EDIT_USER, RECEIVED_NULL_FOR_ARGUMENT_LOGIN_ID, ErrorSeverity.INFO); + BeEcompErrorManager.getInstance().logInvalidInputError(EDIT_USER, RECEIVED_NULL_FOR_ARGUMENT_LOGIN_ID, ErrorSeverity.INFO); throw new PortalAPIException(RECEIVED_NULL_FOR_ARGUMENT_LOGIN_ID); } - UserBusinessLogic userBusinessLogic = getUserBusinessLogic(); - if (user.getLoginId() != null && !user.getLoginId().equals(loginId)) { log.debug("loginId and user loginId not equal"); - BeEcompErrorManager.getInstance() - .logInvalidInputError(EDIT_USER, "loginId and user loginId not equal", ErrorSeverity.INFO); + BeEcompErrorManager.getInstance().logInvalidInputError(EDIT_USER, "loginId and user loginId not equal", ErrorSeverity.INFO); throw new PortalAPIException("loginId not equals to the user loginId field"); } else if (user.getLoginId() == null) { user.setLoginId(loginId); } - User asdcUser = EcompUserConverter.convertEcompUserToUser(user); - Either<User, ResponseFormat> updateUserCredentialsResponse = - userBusinessLogic.updateUserCredentials(asdcUser); - + Either<User, ResponseFormat> updateUserCredentialsResponse = userBusinessLogic.updateUserCredentials(asdcUser); if (updateUserCredentialsResponse.isRight()) { log.debug(FAILED_TO_UPDATE_USER_CREDENTIALS); - BeEcompErrorManager.getInstance() - .logInvalidInputError(EDIT_USER, FAILED_TO_UPDATE_USER_CREDENTIALS, ErrorSeverity.ERROR); + BeEcompErrorManager.getInstance().logInvalidInputError(EDIT_USER, FAILED_TO_UPDATE_USER_CREDENTIALS, ErrorSeverity.ERROR); throw new PortalAPIException(FAILED_TO_EDIT_USER + updateUserCredentialsResponse.right().value()); } } catch (Exception e) { log.debug(FAILED_TO_UPDATE_USER_CREDENTIALS); throw new PortalAPIException(FAILED_TO_EDIT_USER, e); } - } @Override @@ -168,8 +151,7 @@ public class EcompIntImpl implements IPortalRestAPIService { try { if (loginId == null) { log.debug(RECEIVED_NULL_FOR_ARGUMENT_LOGIN_ID); - BeEcompErrorManager.getInstance() - .logInvalidInputError(GET_USER, RECEIVED_NULL_FOR_ARGUMENT_LOGIN_ID, ErrorSeverity.INFO); + BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER, RECEIVED_NULL_FOR_ARGUMENT_LOGIN_ID, ErrorSeverity.INFO); throw new PortalAPIException(RECEIVED_NULL_FOR_ARGUMENT_LOGIN_ID); } UserBusinessLogic userBusinessLogic = getUserBusinessLogic(); @@ -179,15 +161,13 @@ public class EcompIntImpl implements IPortalRestAPIService { return ecompUser.left().value(); } else { log.debug(FAILED_TO_GET_USER); - BeEcompErrorManager.getInstance() - .logInvalidInputError(GET_USER, FAILED_TO_GET_USER, ErrorSeverity.INFO); + BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER, FAILED_TO_GET_USER, ErrorSeverity.INFO); throw new PortalAPIException(ecompUser.right().value()); } } catch (ComponentException ce) { log.debug(FAILED_TO_GET_USER); BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER, FAILED_TO_GET_USER, ErrorSeverity.INFO); throw new PortalAPIException(FAILED_TO_GET_USER + ce.getActionStatus()); - } catch (Exception e) { log.debug(FAILED_TO_GET_USER); throw new PortalAPIException(FAILED_TO_GET_USER, e); @@ -197,7 +177,6 @@ public class EcompIntImpl implements IPortalRestAPIService { @Override public List<EcompUser> getUsers() throws PortalAPIException { log.debug("Start handle request of ECOMP getUsers"); - try { UserBusinessLogic userBusinessLogic = getUserBusinessLogic(); List<User> users = userBusinessLogic.getUsersList(JH0003, null, null); @@ -207,8 +186,7 @@ public class EcompIntImpl implements IPortalRestAPIService { if (ecompUser.isRight() || ecompUser.left().value() == null) { log.debug(FAILED_TO_CONVERT_USER2, user); BeEcompErrorManager.getInstance() - .logInvalidInputError(GET_USERS, "Failed to convert User" + user.toString(), - ErrorSeverity.WARNING); + .logInvalidInputError(GET_USERS, "Failed to convert User" + user.toString(), ErrorSeverity.WARNING); continue; } ecompUserList.add(ecompUser.left().value()); @@ -232,19 +210,15 @@ public class EcompIntImpl implements IPortalRestAPIService { ecompRole.setName(role.name()); ecompRolesList.add(ecompRole); } - if (ecompRolesList.isEmpty()) { throw new PortalAPIException(); } - return ecompRolesList; } catch (Exception e) { log.debug(FAILED_TO_FETCH_ROLES); - BeEcompErrorManager.getInstance() - .logInvalidInputError("GetAvailableRoles", FAILED_TO_FETCH_ROLES, ErrorSeverity.INFO); + BeEcompErrorManager.getInstance().logInvalidInputError("GetAvailableRoles", FAILED_TO_FETCH_ROLES, ErrorSeverity.INFO); throw new PortalAPIException("Roles fetching failed", e); } - } /** @@ -253,14 +227,10 @@ public class EcompIntImpl implements IPortalRestAPIService { @Override public void pushUserRole(String loginId, List<EcompRole> roles) throws PortalAPIException { log.debug("Start handle request of ECOMP pushUserRole"); - final String modifierAttId = JH0003; log.debug("modifier id is {}", modifierAttId); - UserBusinessLogic userBusinessLogic = getUserBusinessLogic(); - String updatedRole; - if (roles == null) { throw new PortalAPIException("Error: Received null for roles"); } else if (roles.iterator().hasNext()) { @@ -271,21 +241,18 @@ public class EcompIntImpl implements IPortalRestAPIService { userBusinessLogic.updateUserRole(modifierAttId, loginId, updatedRole); } catch (Exception e) { log.debug("Error: Failed to update role"); - BeEcompErrorManager.getInstance() - .logInvalidInputError(PUSH_USER_ROLE, "Failed to update role", ErrorSeverity.INFO); + BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER_ROLE, "Failed to update role", ErrorSeverity.INFO); throw new PortalAPIException("Failed to update role" + e); } } else { log.debug("Error: No roles in List"); - BeEcompErrorManager.getInstance() - .logInvalidInputError(PUSH_USER_ROLE, FAILED_TO_FETCH_ROLES, ErrorSeverity.INFO); + BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER_ROLE, FAILED_TO_FETCH_ROLES, ErrorSeverity.INFO); //in this cases we want to deactivate the user try { getUserBusinessLogicExt().deActivateUser(modifierAttId, loginId); } catch (Exception e) { log.debug("Error: Failed to deactivate user {}", loginId); - BeEcompErrorManager.getInstance() - .logInvalidInputError(PUSH_USER_ROLE, "Failed to deactivate user", ErrorSeverity.INFO); + BeEcompErrorManager.getInstance().logInvalidInputError(PUSH_USER_ROLE, "Failed to deactivate user", ErrorSeverity.INFO); throw new PortalAPIException("Error: Failed to deactivate user" + e); } } @@ -300,41 +267,34 @@ public class EcompIntImpl implements IPortalRestAPIService { Either<EcompUser, String> ecompUser = EcompUserConverter.convertUserToEcompUser(user); if (ecompUser.isRight()) { log.debug("Error: Failed to convert Roles"); - BeEcompErrorManager.getInstance() - .logInvalidInputError(GET_USER_ROLES, FAILED_TO_CONVERT_ROLES, ErrorSeverity.ERROR); + BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER_ROLES, FAILED_TO_CONVERT_ROLES, ErrorSeverity.ERROR); throw new PortalAPIException(ecompUser.right().value()); } else if (ecompUser.left().value() == null) { log.debug("Error: Failed to convert Roles"); - BeEcompErrorManager.getInstance() - .logInvalidInputError(GET_USER_ROLES, FAILED_TO_CONVERT_ROLES, ErrorSeverity.ERROR); + BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER_ROLES, FAILED_TO_CONVERT_ROLES, ErrorSeverity.ERROR); throw new PortalAPIException(); } return new LinkedList<>(ecompUser.left().value().getRoles()); } catch (ComponentException ce) { log.debug(ERROR_FAILED_TO_GET_ROLES); - BeEcompErrorManager.getInstance() - .logInvalidInputError(GET_USER_ROLES, FAILED_TO_GET_ROLES, ErrorSeverity.INFO); + BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER_ROLES, FAILED_TO_GET_ROLES, ErrorSeverity.INFO); throw new PortalAPIException(FAILED_TO_GET_ROLES + ce.getActionStatus()); } catch (Exception e) { log.debug(ERROR_FAILED_TO_GET_ROLES); - BeEcompErrorManager.getInstance() - .logInvalidInputError(GET_USER_ROLES, FAILED_TO_GET_ROLES, ErrorSeverity.INFO); + BeEcompErrorManager.getInstance().logInvalidInputError(GET_USER_ROLES, FAILED_TO_GET_ROLES, ErrorSeverity.INFO); throw new PortalAPIException(FAILED_TO_GET_ROLES, e); } } @Override - public boolean isAppAuthenticated(HttpServletRequest request, Map<String, String> appCredentials) - throws PortalAPIException { + public boolean isAppAuthenticated(HttpServletRequest request, Map<String, String> appCredentials) throws PortalAPIException { final String portal_key = PortalApiProperties.getProperty("portal_pass"); final String portal_user = PortalApiProperties.getProperty("portal_user"); final String username = request.getHeader("username"); final String password = request.getHeader("password"); - if (username != null && password != null) { try { - if (username.equals(CipherUtil.decryptPKC(portal_user)) - && password.equals(CipherUtil.decryptPKC(portal_key))) { + if (username.equals(CipherUtil.decryptPKC(portal_user)) && password.equals(CipherUtil.decryptPKC(portal_key))) { log.debug("User authenticated - Username: {}", username); return true; } @@ -358,13 +318,10 @@ public class EcompIntImpl implements IPortalRestAPIService { } /** - * Gets and returns the userId for the logged-in user based on the request. - * If any error occurs, the method should throw PortalApiException with an - * appropriate message. The FW library will catch the exception and send an - * appropriate response to Portal. - * However, the app can always choose to have a custom implementation of - * this method. For Open-source implementation, for example, the app will - * have a totally different implementation for this method. + * Gets and returns the userId for the logged-in user based on the request. If any error occurs, the method should throw PortalApiException with + * an appropriate message. The FW library will catch the exception and send an appropriate response to Portal. However, the app can always choose + * to have a custom implementation of this method. For Open-source implementation, for example, the app will have a totally different + * implementation for this method. * * @param request The HttpServletRequest * @return true if the request contains appropriate credentials, else false. |