use of org.apache.ranger.view.VXResponse in project ranger by apache.
the class TestUserMgr method test15ChangePasswordAsUser.
@Test
public void test15ChangePasswordAsUser() {
setupUser();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
VXPortalUser userProfile = userProfile();
VXPasswordChange pwdChange = new VXPasswordChange();
pwdChange.setId(userProfile.getId());
pwdChange.setLoginId(userProfile.getLoginId());
pwdChange.setOldPassword(userProfile.getPassword());
pwdChange.setEmailAddress(userProfile.getEmailAddress());
pwdChange.setUpdPassword(userProfile.getPassword());
XXPortalUser user = new XXPortalUser();
user.setId(userProfile.getId());
user.setLoginId(userProfile.getLoginId());
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(user);
Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.nullable(String.class))).thenReturn(true);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(stringUtil.validatePassword(Mockito.anyString(), Mockito.any(String[].class))).thenReturn(true);
VXResponse dbVXResponse = userMgr.changePassword(pwdChange);
Assert.assertNotNull(dbVXResponse);
Assert.assertEquals(userProfile.getStatus(), dbVXResponse.getStatusCode());
Mockito.verify(stringUtil).equals(Mockito.anyString(), Mockito.nullable(String.class));
Mockito.verify(stringUtil).validatePassword(Mockito.anyString(), Mockito.any(String[].class));
}
use of org.apache.ranger.view.VXResponse in project ranger by apache.
the class TestUserMgr method test14ChangePasswordAsKeyAdmin.
@Test
public void test14ChangePasswordAsKeyAdmin() {
setupKeyAdmin();
XXPortalUserDao userDao = Mockito.mock(XXPortalUserDao.class);
VXPortalUser userProfile = userProfile();
VXPasswordChange pwdChange = new VXPasswordChange();
pwdChange.setId(userProfile.getId());
pwdChange.setLoginId(userProfile.getLoginId());
pwdChange.setOldPassword(userProfile.getPassword());
pwdChange.setEmailAddress(userProfile.getEmailAddress());
pwdChange.setUpdPassword(userProfile.getPassword());
XXPortalUser userKeyAdmin = new XXPortalUser();
userKeyAdmin.setId(userProfile.getId());
userKeyAdmin.setLoginId(userProfile.getLoginId());
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(userDao.findByLoginId(Mockito.anyString())).thenReturn(userKeyAdmin);
Mockito.when(stringUtil.equals(Mockito.anyString(), Mockito.nullable(String.class))).thenReturn(true);
Mockito.when(daoManager.getXXPortalUser()).thenReturn(userDao);
Mockito.when(stringUtil.validatePassword(Mockito.anyString(), Mockito.any(String[].class))).thenReturn(true);
VXResponse dbVXResponse = userMgr.changePassword(pwdChange);
Assert.assertNotNull(dbVXResponse);
Assert.assertEquals(userProfile.getStatus(), dbVXResponse.getStatusCode());
Mockito.verify(stringUtil).equals(Mockito.anyString(), Mockito.nullable(String.class));
Mockito.verify(stringUtil).validatePassword(Mockito.anyString(), Mockito.any(String[].class));
}
use of org.apache.ranger.view.VXResponse in project ranger by apache.
the class UserService method validateForUpdate.
@Override
protected void validateForUpdate(VXPortalUser userProfile, XXPortalUser xXPortalUser) {
List<VXMessage> messageList = new ArrayList<VXMessage>();
if (userProfile.getEmailAddress() != null && !userProfile.getEmailAddress().equalsIgnoreCase(xXPortalUser.getEmailAddress())) {
throw restErrorUtil.createRESTException("serverMsg.userEmail", MessageEnums.DATA_NOT_UPDATABLE, null, "emailAddress", userProfile.getEmailAddress());
}
// Login Id can't be changed
if (userProfile.getLoginId() != null && !xXPortalUser.getLoginId().equalsIgnoreCase(userProfile.getLoginId())) {
throw restErrorUtil.createRESTException("serverMsg.userUserName", MessageEnums.DATA_NOT_UPDATABLE, null, "loginId", userProfile.getLoginId());
}
// }
userProfile.setFirstName(restErrorUtil.validateStringForUpdate(userProfile.getFirstName(), xXPortalUser.getFirstName(), StringUtil.VALIDATION_NAME, "serverMsg.userFirstName", MessageEnums.INVALID_INPUT_DATA, null, "firstName"));
userProfile.setFirstName(restErrorUtil.validateStringForUpdate(userProfile.getFirstName(), xXPortalUser.getFirstName(), StringUtil.VALIDATION_NAME, "serverMsg.userFirstName", MessageEnums.INVALID_INPUT_DATA, null, "firstName"));
userProfile.setLastName(restErrorUtil.validateStringForUpdate(userProfile.getLastName(), xXPortalUser.getLastName(), StringUtil.VALIDATION_NAME, "serverMsg.userLastName", MessageEnums.INVALID_INPUT_DATA, null, "lastName"));
// firstName
if (!stringUtil.isValidName(userProfile.getFirstName())) {
logger.info("Invalid first name." + userProfile);
messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "firstName"));
}
// lastName
if (!stringUtil.isValidName(userProfile.getLastName())) {
logger.info("Invalid last name." + userProfile);
messageList.add(MessageEnums.INVALID_INPUT_DATA.getMessage(null, "lastName"));
}
userProfile.setNotes(restErrorUtil.validateStringForUpdate(userProfile.getNotes(), xXPortalUser.getNotes(), StringUtil.VALIDATION_NAME, "serverMsg.userNotes", MessageEnums.INVALID_INPUT_DATA, null, "notes"));
// validate status
restErrorUtil.validateMinMax(userProfile.getStatus(), 0, RangerConstants.ActivationStatus_MAX, "Invalid status", null, "status");
// validate user roles
if (userProfile.getUserRoleList() != null) {
// First let's normalize it
splitUserRoleList(userProfile.getUserRoleList());
for (String userRole : userProfile.getUserRoleList()) {
restErrorUtil.validateStringList(userRole, configUtil.getRoles(), "serverMsg.userRole", null, "userRoleList");
}
}
if (!messageList.isEmpty()) {
VXResponse gjResponse = new VXResponse();
gjResponse.setStatusCode(VXResponse.STATUS_ERROR);
gjResponse.setMsgDesc("Validation failure");
gjResponse.setMessageList(messageList);
logger.info("Validation Error in updateUser() userProfile=" + userProfile + ", error=" + gjResponse);
throw restErrorUtil.createRESTException(gjResponse);
}
}
use of org.apache.ranger.view.VXResponse in project ranger by apache.
the class RESTErrorUtil method createRESTException.
public WebApplicationException createRESTException(String errorMessage, MessageEnums messageEnum, Long objectId, String fieldName, String logMessage, int statusCode) {
List<VXMessage> messageList = new ArrayList<VXMessage>();
messageList.add(messageEnum.getMessage(objectId, fieldName));
VXResponse vResponse = new VXResponse();
vResponse.setStatusCode(vResponse.STATUS_ERROR);
vResponse.setMsgDesc(errorMessage);
vResponse.setMessageList(messageList);
Response errorResponse = Response.status(statusCode).entity(vResponse).build();
WebApplicationException restException = new WebApplicationException(errorResponse);
restException.fillInStackTrace();
UserSessionBase userSession = ContextUtil.getCurrentUserSession();
String loginId = null;
if (userSession != null) {
loginId = userSession.getLoginId();
}
logger.info("Request failed. loginId=" + loginId + ", logMessage=" + vResponse.getMsgDesc(), restException);
return restException;
}
use of org.apache.ranger.view.VXResponse in project ranger by apache.
the class RESTErrorUtil method createRESTException.
public WebApplicationException createRESTException(String errorMessage) {
VXResponse gjResponse = new VXResponse();
gjResponse.setStatusCode(VXResponse.STATUS_ERROR);
gjResponse.setMsgDesc(errorMessage);
WebApplicationException webAppEx = createRESTException(gjResponse);
logger.info("Operation error. response=" + gjResponse, webAppEx);
return webAppEx;
}
Aggregations