@Test public void test17ChangePassword() { XXPortalUserDao xxPortalUserDao = Mockito.mock(XXPortalUserDao.class); Mockito.when(daoManager.getXXPortalUser()).thenReturn(xxPortalUserDao); Mockito.when(restErrorUtil.createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.nullable(Long.class), Mockito.nullable(String.class), Mockito.nullable(String.class))).thenReturn(new WebApplicationException()); thrown.expect(WebApplicationException.class); userREST.changePassword(userId, changePassword); Mockito.verify(daoManager).getXXPortalUser(); Mockito.verify(xxPortalUserDao).getById(userId); Mockito.verify(restErrorUtil).createRESTException(Mockito.anyString(), (MessageEnums) Mockito.any(), Mockito.anyLong(), Mockito.anyString(), Mockito.anyString()); }
@POST @Path("{userId}/passwordchange") @Produces({ "application/xml", "application/json" }) public VXResponse changePassword(@PathParam("userId") Long userId, VXPasswordChange changePassword) { if(changePassword==null || stringUtil.isEmpty(changePassword.getLoginId())){ logger.warn("SECURITY:changePassword(): Invalid loginId provided. loginId was empty or null"); throw restErrorUtil.createRESTException("serverMsg.userRestUser",MessageEnums.DATA_NOT_FOUND, null, null,""); } logger.info("changePassword:" + changePassword.getLoginId()); XXPortalUser gjUser = daoManager.getXXPortalUser().findByLoginId(changePassword.getLoginId()); if (gjUser == null) { logger.warn("SECURITY:changePassword(): Invalid loginId provided: loginId="+ changePassword.getLoginId()); throw restErrorUtil.createRESTException("serverMsg.userRestUser",MessageEnums.DATA_NOT_FOUND, null, null, changePassword.getLoginId()); } userManager.checkAccessForUpdate(gjUser); changePassword.setId(gjUser.getId()); VXResponse ret = userManager.changePassword(changePassword); return ret; }
UserREST { @POST @Path("{userId}/passwordchange") @Produces({ "application/xml", "application/json" }) public VXResponse changePassword(@PathParam("userId") Long userId, VXPasswordChange changePassword) { if(changePassword==null || stringUtil.isEmpty(changePassword.getLoginId())){ logger.warn("SECURITY:changePassword(): Invalid loginId provided. loginId was empty or null"); throw restErrorUtil.createRESTException("serverMsg.userRestUser",MessageEnums.DATA_NOT_FOUND, null, null,""); } logger.info("changePassword:" + changePassword.getLoginId()); XXPortalUser gjUser = daoManager.getXXPortalUser().findByLoginId(changePassword.getLoginId()); if (gjUser == null) { logger.warn("SECURITY:changePassword(): Invalid loginId provided: loginId="+ changePassword.getLoginId()); throw restErrorUtil.createRESTException("serverMsg.userRestUser",MessageEnums.DATA_NOT_FOUND, null, null, changePassword.getLoginId()); } userManager.checkAccessForUpdate(gjUser); changePassword.setId(gjUser.getId()); VXResponse ret = userManager.changePassword(changePassword); return ret; } }
UserREST { @POST @Path("{userId}/passwordchange") @Produces({ "application/xml", "application/json" }) public VXResponse changePassword(@PathParam("userId") Long userId, VXPasswordChange changePassword) { if(changePassword==null || stringUtil.isEmpty(changePassword.getLoginId())){ logger.warn("SECURITY:changePassword(): Invalid loginId provided. loginId was empty or null"); throw restErrorUtil.createRESTException("serverMsg.userRestUser",MessageEnums.DATA_NOT_FOUND, null, null,""); } logger.info("changePassword:" + changePassword.getLoginId()); XXPortalUser gjUser = daoManager.getXXPortalUser().findByLoginId(changePassword.getLoginId()); if (gjUser == null) { logger.warn("SECURITY:changePassword(): Invalid loginId provided: loginId="+ changePassword.getLoginId()); throw restErrorUtil.createRESTException("serverMsg.userRestUser",MessageEnums.DATA_NOT_FOUND, null, null, changePassword.getLoginId()); } userManager.checkAccessForUpdate(gjUser); changePassword.setId(gjUser.getId()); VXResponse ret = userManager.changePassword(changePassword); return ret; }  }
UserREST { @POST @Path("{userId}/passwordchange") @Produces({ "application/xml", "application/json" }) public VXResponse changePassword(@PathParam("userId") Long userId, VXPasswordChange changePassword) { if(changePassword==null || stringUtil.isEmpty(changePassword.getLoginId())){ logger.warn("SECURITY:changePassword(): Invalid loginId provided. loginId was empty or null"); throw restErrorUtil.createRESTException("serverMsg.userRestUser",MessageEnums.DATA_NOT_FOUND, null, null,""); } logger.info("changePassword:" + changePassword.getLoginId()); XXPortalUser gjUser = daoManager.getXXPortalUser().findByLoginId(changePassword.getLoginId()); if (gjUser == null) { logger.warn("SECURITY:changePassword(): Invalid loginId provided: loginId="+ changePassword.getLoginId()); throw restErrorUtil.createRESTException("serverMsg.userRestUser",MessageEnums.DATA_NOT_FOUND, null, null, changePassword.getLoginId()); } userManager.checkAccessForUpdate(gjUser); changePassword.setId(gjUser.getId()); VXResponse ret = userManager.changePassword(changePassword); return ret; }  @GET @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.SEARCH_USERS + "\")") VXPortalUserList searchUsers(@Context HttpServletRequest request); @GET @Path("{userId}") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_USER_PROFILE_FOR_USER + "\")") VXPortalUser getUserProfileForUser(@PathParam("userId") Long userId); @POST @Consumes({ "application/json", "application/xml" }) @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.CREATE + "\")") VXPortalUser create(VXPortalUser userProfile,
			@Context HttpServletRequest servletRequest); @POST @Path("/default") @Consumes({ "application/json", "application/xml" }) @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.CREATE_DEFAULT_ACCOUNT_USER + "\")") VXPortalUser createDefaultAccountUser(VXPortalUser userProfile,
			@Context HttpServletRequest servletRequest); @PUT @Consumes({ "application/json", "application/xml" }) @Produces({ "application/xml", "application/json" }) @RangerAnnotationRestAPI(updates_classes = "VUserProfile") @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.UPDATE + "\")") VXPortalUser update(VXPortalUser userProfile,
			@Context HttpServletRequest servletRequest); @PUT @Path("/{userId}/roles") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.SET_USER_ROLES + "\")") VXResponse setUserRoles(@PathParam("userId") Long userId,
			VXStringList roleList); @POST @Path("{userId}/deactivate") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.DEACTIVATE_USER + "\")") @RangerAnnotationClassName(class_name = VXPortalUser.class) VXPortalUser deactivateUser(@PathParam("userId") Long userId); @GET @Path("/profile") @Produces({ "application/xml", "application/json" }) VXPortalUser getUserProfile(@Context HttpServletRequest request); @GET @Path("/firstnames") @Produces({ "application/xml", "application/json" }) String suggestUserFirstName(@QueryParam("letters") String letters,
			@Context HttpServletRequest req); @POST @Path("{userId}/passwordchange") @Produces({ "application/xml", "application/json" }) VXResponse changePassword(@PathParam("userId") Long userId,
			VXPasswordChange changePassword); @POST @Path("{userId}/emailchange") @Produces({ "application/xml", "application/json" }) VXPortalUser changeEmailAddress(@PathParam("userId") Long userId,
			VXPasswordChange changeEmail); }
UserREST { @POST @Path("{userId}/passwordchange") @Produces({ "application/xml", "application/json" }) public VXResponse changePassword(@PathParam("userId") Long userId, VXPasswordChange changePassword) { if(changePassword==null || stringUtil.isEmpty(changePassword.getLoginId())){ logger.warn("SECURITY:changePassword(): Invalid loginId provided. loginId was empty or null"); throw restErrorUtil.createRESTException("serverMsg.userRestUser",MessageEnums.DATA_NOT_FOUND, null, null,""); } logger.info("changePassword:" + changePassword.getLoginId()); XXPortalUser gjUser = daoManager.getXXPortalUser().findByLoginId(changePassword.getLoginId()); if (gjUser == null) { logger.warn("SECURITY:changePassword(): Invalid loginId provided: loginId="+ changePassword.getLoginId()); throw restErrorUtil.createRESTException("serverMsg.userRestUser",MessageEnums.DATA_NOT_FOUND, null, null, changePassword.getLoginId()); } userManager.checkAccessForUpdate(gjUser); changePassword.setId(gjUser.getId()); VXResponse ret = userManager.changePassword(changePassword); return ret; }  @GET @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.SEARCH_USERS + "\")") VXPortalUserList searchUsers(@Context HttpServletRequest request); @GET @Path("{userId}") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.GET_USER_PROFILE_FOR_USER + "\")") VXPortalUser getUserProfileForUser(@PathParam("userId") Long userId); @POST @Consumes({ "application/json", "application/xml" }) @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.CREATE + "\")") VXPortalUser create(VXPortalUser userProfile,
			@Context HttpServletRequest servletRequest); @POST @Path("/default") @Consumes({ "application/json", "application/xml" }) @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.CREATE_DEFAULT_ACCOUNT_USER + "\")") VXPortalUser createDefaultAccountUser(VXPortalUser userProfile,
			@Context HttpServletRequest servletRequest); @PUT @Consumes({ "application/json", "application/xml" }) @Produces({ "application/xml", "application/json" }) @RangerAnnotationRestAPI(updates_classes = "VUserProfile") @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.UPDATE + "\")") VXPortalUser update(VXPortalUser userProfile,
			@Context HttpServletRequest servletRequest); @PUT @Path("/{userId}/roles") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.SET_USER_ROLES + "\")") VXResponse setUserRoles(@PathParam("userId") Long userId,
			VXStringList roleList); @POST @Path("{userId}/deactivate") @Produces({ "application/xml", "application/json" }) @PreAuthorize("@rangerPreAuthSecurityHandler.isAPIAccessible(\"" + RangerAPIList.DEACTIVATE_USER + "\")") @RangerAnnotationClassName(class_name = VXPortalUser.class) VXPortalUser deactivateUser(@PathParam("userId") Long userId); @GET @Path("/profile") @Produces({ "application/xml", "application/json" }) VXPortalUser getUserProfile(@Context HttpServletRequest request); @GET @Path("/firstnames") @Produces({ "application/xml", "application/json" }) String suggestUserFirstName(@QueryParam("letters") String letters,
			@Context HttpServletRequest req); @POST @Path("{userId}/passwordchange") @Produces({ "application/xml", "application/json" }) VXResponse changePassword(@PathParam("userId") Long userId,
			VXPasswordChange changePassword); @POST @Path("{userId}/emailchange") @Produces({ "application/xml", "application/json" }) VXPortalUser changeEmailAddress(@PathParam("userId") Long userId,
			VXPasswordChange changeEmail);  }