Search in sources :

Example 1 with VXResponse

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));
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXPasswordChange(org.apache.ranger.view.VXPasswordChange) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 2 with VXResponse

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));
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) XXPortalUser(org.apache.ranger.entity.XXPortalUser) VXPasswordChange(org.apache.ranger.view.VXPasswordChange) XXPortalUserDao(org.apache.ranger.db.XXPortalUserDao) VXPortalUser(org.apache.ranger.view.VXPortalUser) VXString(org.apache.ranger.view.VXString) Test(org.junit.Test)

Example 3 with VXResponse

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) {
    List<VXMessage> messageList = new ArrayList<VXMessage>();
    messageList.add(messageEnum.getMessage(objectId, fieldName));
    VXResponse gjResponse = new VXResponse();
    gjResponse.setStatusCode(VXResponse.STATUS_ERROR);
    gjResponse.setMsgDesc(errorMessage);
    gjResponse.setMessageList(messageList);
    WebApplicationException webAppEx = createRESTException(gjResponse);
    logger.info("Validation error:logMessage=" + logMessage + ", response=" + gjResponse, webAppEx);
    return webAppEx;
}
Also used : VXResponse(org.apache.ranger.view.VXResponse) WebApplicationException(javax.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) VXMessage(org.apache.ranger.view.VXMessage)

Example 4 with VXResponse

use of org.apache.ranger.view.VXResponse in project ranger by apache.

the class RESTErrorUtil method generateRESTException.

public WebApplicationException generateRESTException(VXResponse gjResponse) {
    Response errorResponse = Response.status(gjResponse.getStatusCode()).entity(gjResponse).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=" + gjResponse.getMsgDesc(), restException);
    return restException;
}
Also used : Response(javax.ws.rs.core.Response) RESTResponse(org.apache.ranger.admin.client.datatype.RESTResponse) VXResponse(org.apache.ranger.view.VXResponse) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 5 with VXResponse

use of org.apache.ranger.view.VXResponse in project ranger by apache.

the class RESTErrorUtil method createRESTException.

public WebApplicationException createRESTException(VXResponse gjResponse) {
    Response errorResponse = Response.status(javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST).entity(gjResponse).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=" + gjResponse.getMsgDesc(), restException);
    return restException;
}
Also used : Response(javax.ws.rs.core.Response) RESTResponse(org.apache.ranger.admin.client.datatype.RESTResponse) VXResponse(org.apache.ranger.view.VXResponse) WebApplicationException(javax.ws.rs.WebApplicationException)

Aggregations

VXResponse (org.apache.ranger.view.VXResponse)57 Test (org.junit.Test)25 ArrayList (java.util.ArrayList)20 WebApplicationException (javax.ws.rs.WebApplicationException)17 XXPortalUser (org.apache.ranger.entity.XXPortalUser)13 VXString (org.apache.ranger.view.VXString)11 XXPortalUserDao (org.apache.ranger.db.XXPortalUserDao)10 UserSessionBase (org.apache.ranger.common.UserSessionBase)9 XXResource (org.apache.ranger.entity.XXResource)9 VXPortalUser (org.apache.ranger.view.VXPortalUser)8 VXResource (org.apache.ranger.view.VXResource)8 VXMessage (org.apache.ranger.view.VXMessage)7 IOException (java.io.IOException)6 VXPasswordChange (org.apache.ranger.view.VXPasswordChange)6 Path (javax.ws.rs.Path)5 Produces (javax.ws.rs.Produces)5 RESTResponse (org.apache.ranger.admin.client.datatype.RESTResponse)5 VXAuditMap (org.apache.ranger.view.VXAuditMap)5 VXAuditMapList (org.apache.ranger.view.VXAuditMapList)5 VXPermMap (org.apache.ranger.view.VXPermMap)5