⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 modifypersonaction.java

📁 OPIAM stands for Open Identity and Access Management. This Suite will provide modules for user & rig
💻 JAVA
字号:
/*
 * OPIAM Suite
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */

package opiam.admin.applis.demo.actions;

import opiam.admin.applis.demo.beans.Person;
import opiam.admin.applis.demo.forms.PersonForm;
import opiam.admin.applis.demo.utils.PasswordUtils;

import opiam.admin.faare.service.UserContext;
import opiam.admin.faare.service.services.StandardService;
import opiam.admin.faare.struts.actions.SecureAction;
import opiam.admin.faare.struts.utils.SessionContext;

import org.apache.log4j.Logger;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import java.io.IOException;


/**
 * This class allows to modify a person entry for the "user" profile.
 *
 * This Action class inherits from SecureAction class.
 * The SecureAction class checks that the user is connected before calling
 * the action methods.
 */
public class ModifyPersonAction extends SecureAction
{
    /** Instance of the log4j logger.
     * Used to generate the execution traces. */
    private static Logger _logger = Logger.getLogger(ModifyPersonAction.class);

    /**
     * This method is called to execute the action once the checks have been
     * performed by the SecureAction class.
     *
     * @param mapping              Struts mapping data.
     * @param actionForm           FormBean associated with the action.
     * @param request              HTTP request.
     * @param httpServletResponse  HTTP response.
     *
     * @return An ActionForward.
     *
     * @throws IOException  An I/O exception if failed or interrupted I/O operations occurs.
     * @throws ServletException  A ServletException if the servlet has a problem.
     */
    public ActionForward secureExecute(ActionMapping mapping,
                                       ActionForm actionForm,
                                       HttpServletRequest request,
                                       HttpServletResponse httpServletResponse
                                      ) throws IOException, ServletException
    {
        SessionContext sessionContext = null;
        ActionMessages msgErrors = new ActionMessages();

        try
        {
            // Gets the session.
            HttpSession session = request.getSession();

            // Gets the session context.
            sessionContext = SessionContext.getInstance(session);

            // Gets the user context.
            UserContext userContext = sessionContext.getUserContext();

            // Gets the formBean.
            PersonForm pf = (PersonForm) actionForm;

            // Gets the user.
            Person person = pf.getUser();

            // Writes the operation on the output defined in the
            // logger_config.properties.
            _logger.info("Modify person : " + person.getDn() + " by user: " +
                         sessionContext.getUserContext().getDn()
                        );

            //TODO Tratiter attribut multi
            // Manages the password attribute
            String newP = pf.getNewPassword();
            String confP = pf.getConfirmPassword();

            _logger.debug("New password : " + newP);

            /*V閞ification de la double saisie du mot de passe*/
            if ((newP != null) && (newP.trim().length() > 0))
            {
                if (!newP.equals(confP))
                {
                    msgErrors.add(ActionMessages.GLOBAL_MESSAGE,
                                  new ActionMessage("error.password.nomatch")
                                 );
                    saveErrors(request, msgErrors);

                    return mapping.findForward("error");
                }

                person.setPassword(newP);

                /*Suppression des valeurs dans le form*/
                pf.setNewPassword("");
                pf.setConfirmPassword("");

                /*Contr鬺es sur le mot de passe*/
                if (!PasswordUtils.checkPassword(newP))
                {
                    msgErrors.add(ActionMessages.GLOBAL_MESSAGE,
                                  new ActionMessage("error.password.constraints")
                                 );
                    saveErrors(request, msgErrors);

                    return mapping.findForward("error");
                }
            }

            // Manages the description
            if (pf.getDescription() != null)
            {
                _logger.debug("Description : " + pf.getDescription());

                person.setDescription(pf.getDescription());
                pf.setDescription(null);
            }

            // Calls the StandardService to modify the entry.
            StandardService.modify(person, sessionContext.getUserContext());

            // Loads the person entry to get the last updated entry.
            person = (Person) StandardService.load(person.getDn(), userContext);

            // Writes the operation on the output defined in the
            // logger_config.properties.
            _logger.info("Load person : " + person.getDn() + " by user: " +
                         sessionContext.getUserContext().getDn()
                        );

            // Sets the modified entry in the session with the "currentEntry"
            // name.
            // This name is used in the jsp page by the Struts tags to
            // recover the attributes values of the person entry.
            session.setAttribute("currentEntry", person);

            session.setAttribute("succeededOperation", "showFullPerson.do");

            // Returns the URI corresponding to the action success
            // as defined in the action configuration in the struts-config.xml.
            return (mapping.findForward("success"));
        }
        catch (Exception se)
        {
            // Writes the error on the standard ouput console.
            se.printStackTrace();

            // Writes the error on the output defined in the
            // logger_config.properties.
            _logger.error(se.getMessage());

            // Gets the error message from the message-resources file
            // defined in the struts-config.xml
            msgErrors.add(ActionMessages.GLOBAL_MESSAGE,
                          new ActionMessage("error.service.unknown")
                         );

            // Save the error message in the request to display it in the jsp
            // page.
            saveErrors(request, msgErrors);

            // Returns the Action-Forward corresponding to the error.
            return (mapping.findForward("error"));
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -