jboss 在丛集环境中使用Flash时发生JSF1094错误

yvgpqqbh  于 2022-11-08  发布在  其他
关注(0)|答案(1)|浏览(149)

我在集群环境中使用primefaces 11(alb +两个wildfly 17 +可分发设置)。当我使用Flash将参数从page1传递到page2时,我得到了以下错误,参数无法传递。

  1. [javax.enterprise.resource.webcontainer.jsf.flash] (default task-29) JSF1094: Could not decode flash data from incoming cookie value Invalid characters in decrypted value. Processing will continue, but the flash is unavailable for this request.

如果我只在一个服务器上运行它,参数可以正常传递。

  • 设定数据
  1. Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
  2. flash.put(REDIRECT_DATA_KEY, rData);
  • 获取数据
  1. Flash flash = FacesContext.getCurrentInstance().getExternalContext().getFlash();
  2. return (RedirectData) flash.get(REDIRECT_DATA_KEY);

我怎么能解决它呢?

pbgvytdp

pbgvytdp1#

来自红帽官方支持:

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
  5. version="4.0">
  6. ...
  7. <env-entry>
  8. <env-entry-name>jsf/FlashSecretKey</env-entry-name>
  9. <env-entry-type>java.lang.String</env-entry-type>
  10. <!-- http://www.digitalsanctuary.com/aes-key-generator.php -->
  11. <env-entry-value>Ya+MAlSDzgC3LAXgfEoPA/J6saEp7MtjjF0P6LP69nGk=</env-entry-value>
  12. </env-entry>
  13. <distributable/>
  14. </web-app>

jsf/FlashSecretKey是base64编码的AES 256位密钥,用于加密闪存范围cookie,如csfcfc=K8auYBA%3D;.密钥可以由下面的代码生成:

  1. import javax.crypto.KeyGenerator;
  2. import javax.crypto.SecretKey;
  3. import java.security.NoSuchAlgorithmException;
  4. import java.util.Base64;
  5. public class Main {
  6. public static void main(String ... args) throws NoSuchAlgorithmException {
  7. KeyGenerator keyGen = KeyGenerator.getInstance("AES");
  8. keyGen.init(256); // key length is 256 byte
  9. SecretKey secretKey = keyGen.generateKey();
  10. System.out.println("key: " + Base64.getEncoder().encodeToString(secretKey.getEncoded()));
  11. }
  12. }

Flash Cookie值Set-Cookie:这是一个很好的例子。如果JNDI密钥java:comp/env/jsf/FlashSecretKey未设置,Mojarra将尝试创建一个随机密钥,用于Flash cookie值的AES加密。
在群集环境中,该行为将导致每个群集EAP示例具有不同的密钥。因此,Mojarra无法还原群集闪存cookie值,并显示以下错误消息:

  1. 20:09:40,317 SEVERE [javax.enterprise.resource.webcontainer.jsf.flash] (default task-1)
  2. JSF1094: Could not decode flash data from incoming cookie value Invalid characters in decrypted value. Processing will continue, but the flash is unavailable for this request.
展开查看全部

相关问题