Search in sources :

Example 6 with IUserService

use of org.cerberus.crud.service.IUserService in project cerberus-source by cerberustesting.

the class UpdateMyUserReporting method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse resp) throws ServletException, IOException {
    String reporting = request.getUserPrincipal().getName();
    String login = request.getUserPrincipal().getName();
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IUserService userService = appContext.getBean(UserService.class);
    try {
        User user = userService.findUserByKey(login);
        user.setReportingFavorite(reporting);
        userService.updateUser(user);
        ILogEventService logEventService = appContext.getBean(LogEventService.class);
        logEventService.createForPrivateCalls("/UpdateMyUserReporting", "UPDATE", "Update user reporting preference for user: " + login, request);
    } catch (CerberusException e) {
        // To change body of catch statement use File | Settings | File Templates.
        e.printStackTrace();
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) CerberusException(org.cerberus.exception.CerberusException) User(org.cerberus.crud.entity.User) IUserService(org.cerberus.crud.service.IUserService) ILogEventService(org.cerberus.crud.service.ILogEventService)

Example 7 with IUserService

use of org.cerberus.crud.service.IUserService in project cerberus-source by cerberustesting.

the class UpdateMyUserReporting1 method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    JSONObject jsonResponse = new JSONObject();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    String login = request.getUserPrincipal().getName();
    String charset = request.getCharacterEncoding();
    /**
     * Parse parameters - list of values
     */
    List<String> tcstatusList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("tcstatus"), null, charset);
    List<String> groupList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("group"), null, charset);
    List<String> tcactiveList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("tcactive"), null, charset);
    List<String> priorityList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("priority"), null, charset);
    List<String> countryList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("country"), null, charset);
    List<String> browserList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("browser"), null, charset);
    List<String> tcestatusList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("tcestatus"), null, charset);
    // environment
    List<String> environmentList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("environment"), null, charset);
    List<String> projectList = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("project"), null, charset);
    /**
     * Parse parameters - free text
     */
    String ip = StringEscapeUtils.escapeHtml4(request.getParameter("ip"));
    String port = StringEscapeUtils.escapeHtml4(request.getParameter("port"));
    String tag = StringEscapeUtils.escapeHtml4(request.getParameter("tag"));
    String browserversion = StringEscapeUtils.escapeHtml4(request.getParameter("browserversion"));
    String comment = StringEscapeUtils.escapeHtml4(request.getParameter("comment"));
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IUserService userService = appContext.getBean(UserService.class);
    try {
        User user = userService.findUserByKey(login);
        if (user != null) {
            JSONObject preferences = new JSONObject();
            if (tcstatusList != null) {
                preferences.put("s", tcstatusList);
            }
            if (groupList != null) {
                preferences.put("g", groupList);
            }
            if (tcactiveList != null) {
                preferences.put("a", tcactiveList);
            }
            if (priorityList != null) {
                preferences.put("pr", priorityList);
            }
            if (countryList != null) {
                preferences.put("co", countryList);
            }
            if (browserList != null) {
                preferences.put("b", browserList);
            }
            if (tcestatusList != null) {
                preferences.put("es", tcestatusList);
            }
            if (environmentList != null) {
                preferences.put("e", environmentList);
            }
            if (projectList != null) {
                preferences.put("prj", projectList);
            }
            if (!StringUtil.isNullOrEmpty(ip)) {
                preferences.put("ip", ip);
            }
            if (!StringUtil.isNullOrEmpty(port)) {
                preferences.put("p", port);
            }
            if (!StringUtil.isNullOrEmpty(tag)) {
                preferences.put("t", tag);
            }
            if (!StringUtil.isNullOrEmpty(browserversion)) {
                preferences.put("br", browserversion);
            }
            if (!StringUtil.isNullOrEmpty(comment)) {
                preferences.put("cm", comment);
            }
            user.setReportingFavorite(preferences.toString());
            // TODO: when converting to the new standard this should return an answer
            userService.updateUser(user);
            // re-send the updated preferences
            jsonResponse.put("preferences", preferences);
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
            msg.setDescription(msg.getDescription().replace("%ITEM%", "Execution reporting filters ").replace("%OPERATION%", "Update"));
            ILogEventService logEventService = appContext.getBean(LogEventService.class);
            logEventService.createForPrivateCalls("/UpdateMyUserReporting1", "UPDATE", "Update user reporting preference for user: " + login, request);
        } else {
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Unable to update User was not found!"));
        }
        jsonResponse.put("messageType", msg.getMessage().getCodeString());
        jsonResponse.put("message", msg.getDescription());
    } catch (JSONException ex) {
        LOG.warn(ex);
        // returns a default error message with the json format that is able to be parsed by the client-side
        response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
    } catch (CerberusException ex) {
        LOG.warn(ex);
        // returns a default error message with the json format that is able to be parsed by the client-side
        response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
    }
    response.getWriter().print(jsonResponse);
    response.getWriter().flush();
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) CerberusException(org.cerberus.exception.CerberusException) User(org.cerberus.crud.entity.User) JSONObject(org.json.JSONObject) MessageEvent(org.cerberus.engine.entity.MessageEvent) IUserService(org.cerberus.crud.service.IUserService) ILogEventService(org.cerberus.crud.service.ILogEventService) JSONException(org.json.JSONException)

Example 8 with IUserService

use of org.cerberus.crud.service.IUserService in project cerberus-source by cerberustesting.

the class UpdateMyUserRobotPreference method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IUserService userService = appContext.getBean(UserService.class);
    try {
        String ss_ip = ParameterParserUtil.parseStringParam(request.getParameter("ss_ip"), "");
        String ss_p = ParameterParserUtil.parseStringParam(request.getParameter("ss_p"), "");
        String platform = ParameterParserUtil.parseStringParam(request.getParameter("platform"), "");
        String browser = ParameterParserUtil.parseStringParam(request.getParameter("browser"), "");
        String version = ParameterParserUtil.parseStringParam(request.getParameter("version"), "");
        User usr = userService.findUserByKey(request.getUserPrincipal().getName());
        usr.setRobotHost(ss_ip);
        usr.setRobotPort(ss_p);
        usr.setRobotPlatform(platform);
        usr.setRobotBrowser(browser);
        usr.setRobotVersion(version);
        userService.updateUser(usr);
        ILogEventService logEventService = appContext.getBean(LogEventService.class);
        logEventService.createForPrivateCalls("/UpdateMyUserRobotPreference", "UPDATE", "Update user robot preference for user: " + usr.getLogin(), request);
        response.getWriter().print(usr.getLogin());
    } catch (CerberusException myexception) {
        response.getWriter().print(myexception.getMessageError().getDescription());
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) CerberusException(org.cerberus.exception.CerberusException) User(org.cerberus.crud.entity.User) IUserService(org.cerberus.crud.service.IUserService) ILogEventService(org.cerberus.crud.service.ILogEventService)

Example 9 with IUserService

use of org.cerberus.crud.service.IUserService in project cerberus-source by cerberustesting.

the class UpdateTestCaseWithDependencies method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 * @throws org.cerberus.exception.CerberusException
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException {
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    String initialTest = request.getParameter("informationInitialTest");
    String initialTestCase = request.getParameter("informationInitialTestCase");
    String test = request.getParameter("informationTest");
    String testCase = request.getParameter("informationTestCase");
    TestCase tc = getTestCaseFromParameter(request, appContext, test, testCase);
    boolean duplicate = false;
    ITestService tService = appContext.getBean(ITestService.class);
    ITestCaseService tcService = appContext.getBean(ITestCaseService.class);
    ITestCaseCountryService tccService = appContext.getBean(ITestCaseCountryService.class);
    ITestCaseCountryPropertiesService tccpService = appContext.getBean(ITestCaseCountryPropertiesService.class);
    ITestCaseStepService tcsService = appContext.getBean(ITestCaseStepService.class);
    ITestCaseStepActionService tcsaService = appContext.getBean(ITestCaseStepActionService.class);
    ITestCaseStepActionControlService tcsacService = appContext.getBean(ITestCaseStepActionControlService.class);
    IInvariantService invariantService = appContext.getBean(IInvariantService.class);
    IUserService userService = appContext.getBean(IUserService.class);
    IUserGroupService userGroupService = appContext.getBean(IUserGroupService.class);
    /**
     * Get User and Groups of this user
     */
    User user = userService.findUserByKey(request.getUserPrincipal().getName());
    // List<UserGroup> userGroupList = groupService.findGroupByUser(user);
    List<UserGroup> userGroupList = userGroupService.convert(userGroupService.readByUser(user.getLogin()));
    List<String> groupList = new ArrayList();
    for (UserGroup group : userGroupList) {
        groupList.add(group.getGroup());
    }
    /**
     * Verify the Test is the same than initialTest If it is the same > Do
     * nothing If it is not the same > Verify if test already exists If not
     * exist > create it If exist > do nothing
     */
    if (!tc.getTest().equals(initialTest)) {
        if (tService.findTestByKey(tc.getTest()) == null) {
            if (groupList.contains("TestAdmin")) {
                Test newTest = tService.findTestByKey(initialTest);
                newTest.setTest(tc.getTest());
                tService.convert(tService.create(newTest));
            } else {
                response.sendError(403, MessageGeneralEnum.GUI_TEST_CREATION_NOT_HAVE_RIGHT.getDescription());
                return;
            }
        }
    }
    if (!tc.getTest().equals(initialTest) || !tc.getTestCase().equals(initialTestCase)) {
        duplicate = true;
    }
    /**
     * If the testcase is a duplication, set the creator as the one which
     * duplicate the testcase and the status in the initial one.
     */
    if (duplicate) {
        tc.setUsrCreated(user.getLogin());
        // TODO: handle if the response does not turn ok
        AnswerList answer = invariantService.readByIdname("TCSTATUS");
        tc.setStatus(((List<Invariant>) answer.getDataList()).get(0).getValue());
    }
    /**
     * If not duplicate and test in Working status and user with no admin
     * right, raise an error
     */
    if (!duplicate && "WORKING".equals(tc.getStatus()) && !groupList.contains("TestAdmin")) {
        response.sendError(403, MessageGeneralEnum.GUI_TESTCASE_NON_ADMIN_SAVE_WORKING_TESTCASE.getDescription());
        return;
    }
    /**
     * Verify testcase is the same than initialTestCase If it is the same >
     * update If it is not the same, > verify if testcase already exist If
     * it already exist > Send Error If it do not already exists > Create it
     */
    if (!duplicate) {
        tcService.updateTestCase(tc);
    } else if (tcService.findTestCaseByKey(tc.getTest(), tc.getTestCase()) != null) {
        response.sendError(403, MessageGeneralEnum.GUI_TESTCASE_DUPLICATION_ALREADY_EXISTS.getDescription());
        return;
    } else {
        tcService.createTestCase(tc);
    }
    /**
     * For the list of testcase country verify it exists. If it does not
     * exists > create it If it exist, verify if it's the
     */
    List<TestCaseCountry> tccFromPage = getTestCaseCountryFromParameter(request, appContext, test, testCase);
    List<TestCaseCountry> tccFromDtb = tccService.findTestCaseCountryByTestTestCase(initialTest, initialTestCase);
    /**
     * Iterate on (TestCaseCountry From Page - TestCaseCountry From
     * Database) If TestCaseCountry in Database has same key : Update and
     * remove from the list. If TestCaseCountry in database does ot exist :
     * Insert it.
     */
    List<TestCaseCountry> tccToUpdateOrInsert = new ArrayList(tccFromPage);
    tccToUpdateOrInsert.removeAll(tccFromDtb);
    List<TestCaseCountry> tccToUpdateOrInsertToIterate = new ArrayList(tccToUpdateOrInsert);
    for (TestCaseCountry tccDifference : tccToUpdateOrInsertToIterate) {
        for (TestCaseCountry tccInDatabase : tccFromDtb) {
            if (tccDifference.hasSameKey(tccInDatabase)) {
                tccToUpdateOrInsert.remove(tccDifference);
            }
        }
    }
    tccService.insertListTestCaseCountry(tccToUpdateOrInsert);
    /**
     * Iterate on (TestCaseCountry From Database - TestCaseCountry From
     * Page). If TestCaseCountry in Page has same key : remove from the
     * list. Then delete the list of TestCaseCountry
     */
    if (!duplicate) {
        List<TestCaseCountry> tccToDelete = new ArrayList(tccFromDtb);
        tccToDelete.removeAll(tccFromPage);
        List<TestCaseCountry> tccToDeleteToIterate = new ArrayList(tccToDelete);
        for (TestCaseCountry tccDifference : tccToDeleteToIterate) {
            for (TestCaseCountry tccInPage : tccFromPage) {
                if (tccDifference.hasSameKey(tccInPage)) {
                    tccToDelete.remove(tccDifference);
                }
            }
        }
        tccService.deleteListTestCaseCountry(tccToDelete);
    }
    /**
     * For the list of testcase country verify it exists. If it does not
     * exists > create it If it exist, verify if it's the
     */
    List<TestCaseCountryProperties> tccpFromPage = getTestCaseCountryPropertiesFromParameter(request, appContext, test, testCase);
    List<TestCaseCountryProperties> tccpFromDtb = tccpService.findListOfPropertyPerTestTestCase(initialTest, initialTestCase);
    /**
     * Iterate on (TestCaseCountryProperties From Page -
     * TestCaseCountryProperties From Database) If TestCaseCountryProperties
     * in Database has same key : Update and remove from the list. If
     * TestCaseCountryProperties in database does ot exist : Insert it.
     */
    List<TestCaseCountryProperties> tccpToUpdateOrInsert = new ArrayList(tccpFromPage);
    tccpToUpdateOrInsert.removeAll(tccpFromDtb);
    List<TestCaseCountryProperties> tccpToUpdateOrInsertToIterate = new ArrayList(tccpToUpdateOrInsert);
    for (TestCaseCountryProperties tccpDifference : tccpToUpdateOrInsertToIterate) {
        for (TestCaseCountryProperties tccpInDatabase : tccpFromDtb) {
            if (tccpDifference.hasSameKey(tccpInDatabase)) {
                tccpService.updateTestCaseCountryProperties(tccpDifference);
                tccpToUpdateOrInsert.remove(tccpDifference);
            }
        }
    }
    tccpService.insertListTestCaseCountryProperties(tccpToUpdateOrInsert);
    /**
     * Iterate on (TestCaseCountryProperties From Database -
     * TestCaseCountryProperties From Page). If TestCaseCountryProperties in
     * Page has same key : remove from the list. Then delete the list of
     * TestCaseCountryProperties
     */
    if (!duplicate) {
        List<TestCaseCountryProperties> tccpToDelete = new ArrayList(tccpFromDtb);
        tccpToDelete.removeAll(tccpFromPage);
        List<TestCaseCountryProperties> tccpToDeleteToIterate = new ArrayList(tccpToDelete);
        for (TestCaseCountryProperties tccpDifference : tccpToDeleteToIterate) {
            for (TestCaseCountryProperties tccpInPage : tccpFromPage) {
                if (tccpDifference.hasSameKey(tccpInPage)) {
                    tccpToDelete.remove(tccpDifference);
                }
            }
        }
        tccpService.deleteListTestCaseCountryProperties(tccpToDelete);
    }
    /*
         * Get steps, actions and controls from page by:
         * - generating a new step, action or control number,
         * - setting the correct related step and action for action or control
         */
    List<TestCaseStep> tcsFromPage = getTestCaseStepFromParameter(request, appContext, test, testCase, duplicate);
    List<TestCaseStepAction> tcsaFromPage = new ArrayList();
    List<TestCaseStepActionControl> tcsacFromPage = new ArrayList();
    int nextStepNumber = getMaxStepNumber(tcsFromPage);
    for (TestCaseStep tcs : tcsFromPage) {
        if (tcs.getStep() == -1) {
            tcs.setStep(++nextStepNumber);
        }
        if (tcs.getTestCaseStepAction() != null) {
            int nextSequenceNumber = getMaxSequenceNumber(tcs.getTestCaseStepAction());
            for (TestCaseStepAction tcsa : tcs.getTestCaseStepAction()) {
                if (tcsa.getSequence() == -1) {
                    tcsa.setSequence(++nextSequenceNumber);
                }
                tcsa.setStep(tcs.getStep());
                if (tcsa.getTestCaseStepActionControl() != null) {
                    int nextControlNumber = getMaxControlNumber(tcsa.getTestCaseStepActionControl());
                    for (TestCaseStepActionControl tscac : tcsa.getTestCaseStepActionControl()) {
                        if (tscac.getControlSequence() == -1) {
                            tscac.setControlSequence(++nextControlNumber);
                        }
                        tscac.setStep(tcs.getStep());
                        tscac.setSequence(tcsa.getSequence());
                    }
                    tcsacFromPage.addAll(tcsa.getTestCaseStepActionControl());
                }
            }
            tcsaFromPage.addAll(tcs.getTestCaseStepAction());
        }
    }
    /*
         * Create, update or delete step, action and control according to the needs
         */
    List<TestCaseStep> tcsFromDtb = new ArrayList(tcsService.getListOfSteps(initialTest, initialTestCase));
    tcsService.compareListAndUpdateInsertDeleteElements(tcsFromPage, tcsFromDtb, duplicate);
    List<TestCaseStepAction> tcsaFromDtb = new ArrayList(tcsaService.findTestCaseStepActionbyTestTestCase(initialTest, initialTestCase));
    tcsaService.compareListAndUpdateInsertDeleteElements(tcsaFromPage, tcsaFromDtb, duplicate);
    List<TestCaseStepActionControl> tcsacFromDtb = new ArrayList(tcsacService.findControlByTestTestCase(initialTest, initialTestCase));
    tcsacService.compareListAndUpdateInsertDeleteElements(tcsacFromPage, tcsacFromDtb, duplicate);
    /**
     * Adding Log entry.
     */
    ILogEventService logEventService = appContext.getBean(LogEventService.class);
    logEventService.createForPrivateCalls("/UpdateTestCase", "UPDATE", "Update testcase : ['" + tc.getTest() + "'|'" + tc.getTestCase() + "']", request);
    String encodedTest = URLEncoder.encode(tc.getTest(), "UTF-8");
    String encodedTestCase = URLEncoder.encode(tc.getTestCase(), "UTF-8");
    response.sendRedirect(response.encodeRedirectURL("TestCase.jsp?Load=Load&Test=" + encodedTest + "&TestCase=" + encodedTestCase));
}
Also used : ITestCaseStepActionService(org.cerberus.crud.service.ITestCaseStepActionService) IFactoryTestCaseStepAction(org.cerberus.crud.factory.IFactoryTestCaseStepAction) TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) User(org.cerberus.crud.entity.User) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) ArrayList(java.util.ArrayList) IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) TestCaseStep(org.cerberus.crud.entity.TestCaseStep) IUserGroupService(org.cerberus.crud.service.IUserGroupService) ITestCaseCountryService(org.cerberus.crud.service.ITestCaseCountryService) UserGroup(org.cerberus.crud.entity.UserGroup) ApplicationContext(org.springframework.context.ApplicationContext) ITestService(org.cerberus.crud.service.ITestService) Test(org.cerberus.crud.entity.Test) ITestCaseCountryPropertiesService(org.cerberus.crud.service.ITestCaseCountryPropertiesService) ITestCaseService(org.cerberus.crud.service.ITestCaseService) TestCaseCountry(org.cerberus.crud.entity.TestCaseCountry) IFactoryTestCaseCountry(org.cerberus.crud.factory.IFactoryTestCaseCountry) ILogEventService(org.cerberus.crud.service.ILogEventService) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl) AnswerList(org.cerberus.util.answer.AnswerList) ITestCaseStepService(org.cerberus.crud.service.ITestCaseStepService) IInvariantService(org.cerberus.crud.service.IInvariantService) ITestCaseStepActionControlService(org.cerberus.crud.service.ITestCaseStepActionControlService) TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCase(org.cerberus.crud.factory.IFactoryTestCase) IUserService(org.cerberus.crud.service.IUserService)

Example 10 with IUserService

use of org.cerberus.crud.service.IUserService in project cerberus-source by cerberustesting.

the class ForgotPasswordEmailConfirmation method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("text/html;charset=UTF-8");
    try (PrintWriter out = response.getWriter()) {
        ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        IUserService userService = appContext.getBean(UserService.class);
        IParameterService parameterService = appContext.getBean(ParameterService.class);
        String system = "";
        JSONObject jsonResponse = new JSONObject();
        StringBuffer jb = new StringBuffer();
        String line = null;
        BufferedReader reader = request.getReader();
        while ((line = reader.readLine()) != null) {
            jb.append(line);
        }
        String[] parameters = jb.toString().split("&");
        JSONObject jo = new JSONObject();
        for (String parameter : parameters) {
            String[] param = parameter.split("=");
            jo.put(param[0], param[1]);
        }
        String login = jo.getString("login");
        String confirmation = jo.getString("confirmationToken");
        /**
         * If email not found in database, send error message
         */
        AnswerItem ai = userService.readByKey(login);
        User user = (User) ai.getItem();
        if (user == null) {
            jsonResponse.put("messageType", "KO");
            jsonResponse.put("message", "Login submitted is unknown !");
            response.getWriter().print(jsonResponse);
            response.getWriter().flush();
            return;
        }
        /**
         * Check the token
         */
        if (!userService.verifyResetPasswordToken(user, confirmation)) {
            jsonResponse.put("messageType", "KO");
            jsonResponse.put("message", "Token submitted is invalid !");
            response.getWriter().print(jsonResponse);
            response.getWriter().flush();
            return;
        }
        /**
         * Build Response Message
         */
        jsonResponse.put("messageType", "OK");
        jsonResponse.put("message", "Please, define your new password.");
        response.getWriter().print(jsonResponse);
        response.getWriter().flush();
    } catch (JSONException ex) {
        LOG.warn(ex);
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) User(org.cerberus.crud.entity.User) JSONObject(org.json.JSONObject) IUserService(org.cerberus.crud.service.IUserService) BufferedReader(java.io.BufferedReader) JSONException(org.json.JSONException) IParameterService(org.cerberus.crud.service.IParameterService) AnswerItem(org.cerberus.util.answer.AnswerItem) PrintWriter(java.io.PrintWriter)

Aggregations

IUserService (org.cerberus.crud.service.IUserService)15 ApplicationContext (org.springframework.context.ApplicationContext)15 User (org.cerberus.crud.entity.User)13 CerberusException (org.cerberus.exception.CerberusException)11 ILogEventService (org.cerberus.crud.service.ILogEventService)10 JSONObject (org.json.JSONObject)10 JSONException (org.json.JSONException)9 AnswerItem (org.cerberus.util.answer.AnswerItem)6 UserGroup (org.cerberus.crud.entity.UserGroup)4 IUserGroupService (org.cerberus.crud.service.IUserGroupService)4 MessageEvent (org.cerberus.engine.entity.MessageEvent)4 PrintWriter (java.io.PrintWriter)3 UserSystem (org.cerberus.crud.entity.UserSystem)3 Answer (org.cerberus.util.answer.Answer)3 ArrayList (java.util.ArrayList)2 IUserSystemService (org.cerberus.crud.service.IUserSystemService)2 JSONArray (org.json.JSONArray)2 PolicyFactory (org.owasp.html.PolicyFactory)2 BufferedReader (java.io.BufferedReader)1 IOException (java.io.IOException)1