Search in sources :

Example 26 with User

use of org.cerberus.crud.entity.User in project cerberus-source by cerberustesting.

the class UserDAOTest method testUpdateUser.

@Test
public void testUpdateUser() throws SQLException {
    when(databaseSpring.connect()).thenReturn(connection);
    when(connection.prepareStatement(anyString().toString())).thenReturn(statement);
    when(statement.executeUpdate()).thenReturn(1);
    User user = new User();
    boolean bool = userDAO.updateUser(user);
    Assert.assertEquals(true, bool);
}
Also used : User(org.cerberus.crud.entity.User) Test(org.junit.Test)

Example 27 with User

use of org.cerberus.crud.entity.User 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)

Example 28 with User

use of org.cerberus.crud.entity.User in project cerberus-source by cerberustesting.

the class GetUsers method doPost.

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String echo = request.getParameter("sEcho");
    // data that will be shown in the table
    JSONArray data = new JSONArray();
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    IUserService userService = appContext.getBean(UserService.class);
    IUserSystemService userSystemService = appContext.getBean(IUserSystemService.class);
    IUserGroupService userGroupService = appContext.getBean(UserGroupService.class);
    try {
        JSONObject jsonResponse = new JSONObject();
        try {
            for (User myUser : userService.findallUser()) {
                JSONObject u = new JSONObject();
                u.put("login", myUser.getLogin());
                u.put("name", myUser.getName());
                u.put("team", myUser.getTeam());
                u.put("defaultSystem", myUser.getDefaultSystem());
                u.put("request", myUser.getRequest());
                u.put("email", myUser.getEmail());
                JSONArray groups = new JSONArray();
                for (UserGroup group : userGroupService.findGroupByKey(myUser.getLogin())) {
                    groups.put(group.getGroup());
                }
                u.put("group", groups);
                JSONArray systems = new JSONArray();
                for (UserSystem sys : userSystemService.findUserSystemByUser(myUser.getLogin())) {
                    systems.put(sys.getSystem());
                }
                u.put("system", systems);
                data.put(u);
            }
        } catch (CerberusException ex) {
            response.setContentType("text/html");
            response.getWriter().print(ex.getMessageError().getDescription());
        }
        jsonResponse.put("aaData", data);
        jsonResponse.put("sEcho", echo);
        jsonResponse.put("iTotalRecords", data.length());
        jsonResponse.put("iTotalDisplayRecords", data.length());
        response.setContentType("application/json");
        response.getWriter().print(jsonResponse.toString());
    } catch (JSONException e) {
        LOG.warn(e);
        response.setContentType("text/html");
        response.getWriter().print(e.getMessage());
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) CerberusException(org.cerberus.exception.CerberusException) User(org.cerberus.crud.entity.User) JSONObject(org.json.JSONObject) UserSystem(org.cerberus.crud.entity.UserSystem) IUserService(org.cerberus.crud.service.IUserService) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IUserGroupService(org.cerberus.crud.service.IUserGroupService) IUserSystemService(org.cerberus.crud.service.IUserSystemService) UserGroup(org.cerberus.crud.entity.UserGroup)

Example 29 with User

use of org.cerberus.crud.entity.User in project cerberus-source by cerberustesting.

the class ReadMyUser 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);
    IUserSystemService userSystemService = appContext.getBean(IUserSystemService.class);
    IUserGroupService userGroupService = appContext.getBean(UserGroupService.class);
    response.setContentType("application/json");
    response.setCharacterEncoding("utf8");
    JSONObject data = new JSONObject();
    try {
        String user = request.getUserPrincipal().getName();
        User myUser = userService.findUserByKey(user);
        data.put("login", myUser.getLogin());
        data.put("name", myUser.getName());
        data.put("team", myUser.getTeam());
        data.put("defaultSystem", myUser.getDefaultSystem());
        data.put("request", myUser.getRequest());
        data.put("email", myUser.getEmail());
        data.put("language", myUser.getLanguage());
        data.put("robotHost", myUser.getRobotHost());
        data.put("robotPort", myUser.getRobotPort());
        data.put("robotPlatform", myUser.getRobotPort());
        data.put("robotBrowser", myUser.getRobotPort());
        data.put("robotVersion", myUser.getRobotPort());
        data.put("robot", myUser.getRobot());
        data.put("reportingFavorite", myUser.getReportingFavorite());
        data.put("userPreferences", myUser.getUserPreferences());
        JSONArray groups = new JSONArray();
        for (UserGroup group : userGroupService.findGroupByKey(myUser.getLogin())) {
            groups.put(group.getGroup());
        }
        data.put("group", groups);
        JSONArray systems = new JSONArray();
        for (UserSystem sys : userSystemService.findUserSystemByUser(myUser.getLogin())) {
            systems.put(sys.getSystem());
        }
        data.put("system", systems);
        HttpSession session = request.getSession();
        session.setAttribute("MySystem", myUser.getDefaultSystem());
        session.setAttribute("MyLang", myUser.getLanguage());
    } catch (CerberusException ex) {
        response.getWriter().print(ex.getMessageError().getDescription());
    } catch (JSONException ex) {
        LOG.warn(ex);
    } catch (NullPointerException ex) {
        response.sendRedirect("./Login.jsp");
    }
    response.getWriter().print(data.toString());
}
Also used : CerberusException(org.cerberus.exception.CerberusException) User(org.cerberus.crud.entity.User) UserSystem(org.cerberus.crud.entity.UserSystem) HttpSession(javax.servlet.http.HttpSession) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) IUserGroupService(org.cerberus.crud.service.IUserGroupService) UserGroup(org.cerberus.crud.entity.UserGroup) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) IUserService(org.cerberus.crud.service.IUserService) IUserSystemService(org.cerberus.crud.service.IUserSystemService)

Example 30 with User

use of org.cerberus.crud.entity.User in project cerberus-source by cerberustesting.

the class ReadUser method readByKey.

private AnswerItem readByKey(ApplicationContext appContext, HttpServletRequest request) throws JSONException {
    String login = ParameterParserUtil.parseStringParam(request.getParameter("login"), "");
    boolean userHasPermissions = request.isUserInRole("IntegratorRO");
    AnswerItem item = new AnswerItem();
    JSONObject jsonResponse = new JSONObject();
    userService = appContext.getBean(UserService.class);
    AnswerItem resp = userService.readByKey(login);
    if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null) {
        User user = (User) resp.getItem();
        JSONObject response = convertUserToJSONObject(user);
        if (request.getParameter("systems") != null) {
            IUserSystemService userSystemService = appContext.getBean(IUserSystemService.class);
            AnswerList a = userSystemService.readByUser(login);
            if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && a.getDataList() != null) {
                JSONArray JSONsystems = new JSONArray();
                List<UserSystem> systems = a.getDataList();
                for (UserSystem u : systems) {
                    JSONsystems.put(convertUserSystemToJSONObject(u));
                }
                response.put("systems", JSONsystems);
            }
        }
        if (request.getParameter("groups") != null) {
            IUserGroupService userGroupService = appContext.getBean(UserGroupService.class);
            AnswerList a = userGroupService.readByUser(login);
            if (a.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && a.getDataList() != null) {
                JSONArray JSONgroups = new JSONArray();
                List<UserGroup> groups = a.getDataList();
                for (UserGroup u : groups) {
                    JSONgroups.put(convertUserGroupToJSONObject(u));
                }
                response.put("groups", JSONgroups);
            }
        }
        jsonResponse.put("contentTable", response);
    }
    jsonResponse.put("hasPermissions", userHasPermissions);
    item.setItem(jsonResponse);
    item.setResultMessage(resp.getResultMessage());
    return item;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) User(org.cerberus.crud.entity.User) UserSystem(org.cerberus.crud.entity.UserSystem) IUserService(org.cerberus.crud.service.IUserService) UserService(org.cerberus.crud.service.impl.UserService) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) IUserGroupService(org.cerberus.crud.service.IUserGroupService) UserGroup(org.cerberus.crud.entity.UserGroup) JSONObject(org.json.JSONObject) IUserSystemService(org.cerberus.crud.service.IUserSystemService)

Aggregations

User (org.cerberus.crud.entity.User)34 IUserService (org.cerberus.crud.service.IUserService)16 ApplicationContext (org.springframework.context.ApplicationContext)14 JSONObject (org.json.JSONObject)13 IFactoryUser (org.cerberus.crud.factory.IFactoryUser)11 CerberusException (org.cerberus.exception.CerberusException)11 AnswerItem (org.cerberus.util.answer.AnswerItem)9 JSONException (org.json.JSONException)9 Connection (java.sql.Connection)8 PreparedStatement (java.sql.PreparedStatement)8 SQLException (java.sql.SQLException)8 FactoryUser (org.cerberus.crud.factory.impl.FactoryUser)8 ILogEventService (org.cerberus.crud.service.ILogEventService)8 ResultSet (java.sql.ResultSet)7 MessageEvent (org.cerberus.engine.entity.MessageEvent)7 JSONArray (org.json.JSONArray)7 UserGroup (org.cerberus.crud.entity.UserGroup)6 IUserGroupService (org.cerberus.crud.service.IUserGroupService)6 AnswerList (org.cerberus.util.answer.AnswerList)6 Test (org.junit.Test)6