Example #1
0
  @RequestMapping(value = {"/{login:login;?.*}"})
  // spring3.2.2 bug see http://jinnianshilongnian.iteye.com/blog/1831408
  public String loginForm(HttpServletRequest request, ModelMap model) {
    // 表示退出
    if (!StringUtils.isEmpty(request.getParameter("logout"))) {
      model.addAttribute(
          Constants.MESSAGE, messageSource.getMessage("user.logout.success", null, null));
    }

    // 表示用户删除了 @see org.apache.shiro.web.filter.user.SysUserFilter
    if (!StringUtils.isEmpty(request.getParameter("notfound"))) {
      model.addAttribute(Constants.ERROR, messageSource.getMessage("user.notfound", null, null));
    }

    // 表示用户被管理员强制退出
    if (!StringUtils.isEmpty(request.getParameter("forcelogout"))) {
      model.addAttribute(Constants.ERROR, messageSource.getMessage("user.forcelogout", null, null));
    }

    // 表示用户输入的验证码错误
    if (!StringUtils.isEmpty(request.getParameter("jcaptchaError"))) {
      model.addAttribute(
          Constants.ERROR, messageSource.getMessage("jcaptcha.validate.error", null, null));
    }

    // 表示用户锁定了 @see org.apache.shiro.web.filter.user.SysUserFilter
    if (!StringUtils.isEmpty(request.getParameter("blocked"))) {
      User user = (User) request.getAttribute(Constants.CURRENT_USER);
      String reason = userStatusHistoryService.getLastReason(user);
      model.addAttribute(
          Constants.ERROR, messageSource.getMessage("user.blocked", new Object[] {reason}, null));
    }

    if (!StringUtils.isEmpty(request.getParameter("unknown"))) {
      model.addAttribute(
          Constants.ERROR, messageSource.getMessage("user.unknown.error", null, null));
    }

    // 登录失败了 提取错误消息
    Exception shiroLoginFailureEx =
        (Exception) request.getAttribute(FormAuthenticationFilter.DEFAULT_ERROR_KEY_ATTRIBUTE_NAME);
    if (shiroLoginFailureEx != null) {
      model.addAttribute(Constants.ERROR, shiroLoginFailureEx.getMessage());
    }

    // 如果用户直接到登录页面 先退出一下
    // 原因:isAccessAllowed实现是subject.isAuthenticated()---->即如果用户验证通过 就允许访问
    // 这样会导致登录一直死循环
    Subject subject = SecurityUtils.getSubject();
    if ((subject != null) && subject.isAuthenticated()) {
      subject.logout();
    }

    // 如果同时存在错误消息 和 普通消息 只保留错误消息
    if (model.containsAttribute(Constants.ERROR)) {
      model.remove(Constants.MESSAGE);
    }

    return "front/login";
  }
 @RequestMapping(value = "/registration", method = RequestMethod.GET)
 public String initRegistrationForm(ModelMap model) {
   if (!model.containsAttribute("registrationForm")) {
     model.addAttribute("registrationForm", new UserRegistrationForm());
   }
   return "user/registration";
 }
  @Test
  @TransactionalReadWrite
  public void testInitSettingsPage() {
    User user =
        testUtils.createAuthenticatedTestUser("SettingsControllerTest@testInitSettingsPage");

    ModelMap model = new ModelMap();
    assertEquals("logged/settings", controller.initSettingsPage(model));
    assertTrue(model.containsAttribute("settingsform"));
    SettingsForm settingsForm = (SettingsForm) model.get("settingsform");
    assertEquals(user.getEmail(), settingsForm.getEmail());
    assertEquals(user.getEmail(), settingsForm.getCurrentEmail());
    assertEquals("no", settingsForm.getEditPassword());
    assertEquals(user.getLanguage().getCode(), settingsForm.getLang());
  }
  // @ModelAttribute
  public void userLoad(ModelMap model) {
    // System.out.println("xDamsController.userLoad() model.containsAttribute(\"userBean\"): " +
    // model.containsAttribute("userBean"));
    if (!model.containsAttribute("userBean")) {
      UserDetails userDetails = null;
      try {
        userDetails =
            (UserDetails)
                ((SecurityContext) SecurityContextHolder.getContext())
                    .getAuthentication()
                    .getPrincipal();
        UserBean userBean = LoadUserManager.executeLoad(userDetails, authenticationType);
        model.addAttribute("userBean", userBean);
      } catch (Exception e) {

      }
    }
  }
  public void execute() throws Exception {
    XWConnection xwconn = null;
    ConnectionManager connectionManager = new ConnectionManager();
    ConfBean confBean = null;
    PreInsertBean preInsertBean = null;
    List<String> confControl = new ArrayList<String>();
    confControl.add("docEdit");
    confControl.add("valoriControllati");
    confControl.add("titleManager");
    String physDoc = MyRequest.getParameter("physDoc", parameterMap);
    try {
      UserBean userBean = (UserBean) modelMap.get("userBean");
      confBean = (ConfBean) modelMap.get("confBean");
      WorkFlowBean workFlowBean = (WorkFlowBean) modelMap.get("workFlowBean");
      preInsertBean = new PreInsertBean();
      // serve quando sono in preinsert dalla lookup
      if (modelMap.containsAttribute("srcArchive")) {
        preInsertBean.setSrcArchive((String) modelMap.get("srcArchive"));
      }
      xwconn = connectionManager.getConnection(workFlowBean.getArchive());
      // Mi carico il file selezionato per l'inserimento se il physDoc e diverso da null
      if (!physDoc.equals("")) {
        // System.out.println("PreInsertPageCommand.execute() INIZIO CARICAMENTO DOCUMENTO
        // SELEZIONATO");
        preInsertBean.setPhysDocSelected(Integer.parseInt(physDoc));
        String docXML = xwconn.getSingleXMLFromNumDoc(preInsertBean.getPhysDocSelected());
        preInsertBean.setDocXmlSelected(docXML);
        HierPath hierPath = xwconn.getHierPath(Integer.parseInt(physDoc));
        XMLBuilder theXMLDoc = new XMLBuilder(preInsertBean.getDocXmlSelected(), "ISO-8859-1");
        preInsertBean.setXmlBuilderSelected(theXMLDoc);
        preInsertBean.setDepthSelected(hierPath.depth());
        preInsertBean.setTitleSelected(
            (xwconn.getTitle(xwconn.connection, xwconn.getTheDb(), Integer.parseInt(physDoc)))
                .getTitle());
        MultiEditingManager editingManager =
            new MultiEditingManager(parameterMap, confBean, userBean, workFlowBean);
        editingManager.setTheXML(theXMLDoc);
        confBean = editingManager.rewriteMultipleConf(confControl);
        // System.out.println("PreInsertPageCommand.execute() FINE CARICAMENTO DOCUMENTO
        // SELEZIONATO");
        // prendo il documento padre ma controllo che non sono il padre stesso...
        String ilPath = "/hierValues";
        preInsertBean.setXPathHierValues(ilPath);
        // System.out.println("aaaaaaaaaa " + "/" + ilPath + "/macroarea");
        int numeroMacroarea =
            (confBean.getTheXMLConfEditing()).contaNodi("/" + ilPath + "/macroarea");
        // System.out.println("numeroMacroarea " + numeroMacroarea);
        if (numeroMacroarea > 0) {
          int iLivelli =
              Integer.parseInt(
                  (confBean.getTheXMLConfEditing()).valoreNodo("/" + ilPath + "/@level"));
          int docFather = Integer.parseInt(physDoc);
          if (iLivelli > 0) {
            for (int i = 0; i < iLivelli; i++) {
              if (xwconn.getNumDocFather(docFather) > 0) {
                docFather = xwconn.getNumDocFather(docFather);
              }
            }
          }
          // System.out.println("PreInsertPageCommand.execute() INIZIO CARICAMENTO DOCUMENTO
          // PADRE");
          preInsertBean.setPhysDocFather(docFather);
          docXML = xwconn.getSingleXMLFromNumDoc(preInsertBean.getPhysDocFather());
          preInsertBean.setDocXmlFather(docXML);
          theXMLDoc = new XMLBuilder(preInsertBean.getDocXmlFather(), "ISO-8859-1");
          preInsertBean.setXmlBuilderFather(theXMLDoc);
          preInsertBean.setDepthFather(hierPath.depth() - 1);
          preInsertBean.setTitleFather(
              (xwconn.getTitle(
                      xwconn.connection, xwconn.getTheDb(), preInsertBean.getPhysDocFather()))
                  .getTitle());
          // System.out.println("PreInsertPageCommand.execute() FINE CARICAMENTO DOCUMENTO PADRE");

        }

        // prendo il documento root dell'archivio quello con detph==1
        if ((hierPath.depth()) - (hierPath.depth() - 1) == 1) {
          // System.out.println("PreInsertPageCommand.execute() INIZIO CARICAMENTO DOCUMENTO ROOT");
          preInsertBean.setPhysDocRoot(hierPath.docNumber(1));
          docXML = xwconn.getSingleXMLFromNumDoc(preInsertBean.getPhysDocRoot());
          preInsertBean.setDocXmlRoot(docXML);
          theXMLDoc = new XMLBuilder(preInsertBean.getDocXmlRoot(), "ISO-8859-1");
          preInsertBean.setXmlBuilderRoot(theXMLDoc);
          preInsertBean.setDepthRoot(1);
          preInsertBean.setTitleRoot(
              (xwconn.getTitle(
                      xwconn.connection, xwconn.getTheDb(), preInsertBean.getPhysDocRoot()))
                  .getTitle());
          // System.out.println("PreInsertPageCommand.execute() FINE CARICAMENTO DOCUMENTO ROOT");
        }

      } else {
        // in caso di nuovo documento senza il physDoc, come ad esempio un inserimento da lookup
        MultiEditingManager editingManager =
            new MultiEditingManager(parameterMap, confBean, userBean, workFlowBean);
        XMLBuilder builder = new XMLBuilder("root");
        editingManager.setTheXML(builder);
        confBean = editingManager.rewriteMultipleConf(confControl);
        preInsertBean.setXmlBuilderSelected(builder);
        preInsertBean.setXmlBuilderFather(builder);
      }
      // TODO DA VALUTARE introdotto per adv-editing
      preInsertBean.setXmlBuilderEmpty(new XMLBuilder(workFlowBean.getAlias()));

      modelMap.put("confBean", confBean);
      modelMap.put("preInsertBean", preInsertBean);

    } catch (Exception e) {
      e.printStackTrace();
      modelMap.put("confBean", confBean);
      modelMap.put("preInsertBean", preInsertBean);
      throw new Exception(e.toString());
    } finally {
      connectionManager.closeConnection(xwconn);
    }
  }
 /**
  * Whether model contains an attribute of the given name.
  *
  * @param name the name of the model attribute
  * @return {@code true} if the model contains an attribute by that name and the name is not an
  *     empty string
  */
 public boolean containsAttribute(String name) {
   return (StringUtils.hasText(name) && model.containsAttribute(name));
 }