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

📄 clientplugin.java

📁 java开源的企业总线.xmlBlaster
💻 JAVA
字号:
package org.xmlBlaster.authentication.plugins.demo;import org.xmlBlaster.util.Global;import org.xmlBlaster.util.plugin.PluginInfo;import org.xmlBlaster.util.XmlBlasterException;import org.xmlBlaster.util.MsgUnitRaw;import org.xmlBlaster.authentication.plugins.CryptDataHolder;import org.xmlBlaster.authentication.plugins.I_ClientPlugin;import org.xmlBlaster.authentication.plugins.I_SecurityQos;/** * Class for java clients, decrypting messages which * came from the corresponding security plugin.  * <p /> * If for example the server security plugin crypts * messages with rot13, we need to decrypt it on the * client side with the same algorithm. This is done here. */public class ClientPlugin implements I_ClientPlugin {   public static final String ME = "ClientPlugin";   private Global glob;   public ClientPlugin() {   }   public void init(Global glob, PluginInfo pluginInfo) {      this.glob = glob;   }   public String getType()   {      return "gui";   }   public String getVersion()   {      return "1.0";   }   /**    * The client application can use this method to get a new I_SecurityQos instance,    * and use it to set userId/password etc.    */   public I_SecurityQos createSecurityQos()   {      return new SecurityQos(this.glob); // "demo" "1.0"   }   public void setSessionData(String sessionData)   {   }   // --- message handling ----------------------------------------------------   /**    * decrypt, check, unseal an incomming message.     * <p/>    * @param MsgUnitRaw The the received message    * @param MethodName The name of the method which is intercepted    * @return MsgUnitRaw The original message    * @exception XmlBlasterException Thrown i.e. if the message has been modified    */   public MsgUnitRaw importMessage(CryptDataHolder dataHolder) throws XmlBlasterException {      MsgUnitRaw msg = dataHolder.getMsgUnitRaw();      msg = new MsgUnitRaw(msg.getMsgUnit(),                           importMessage(msg.getKey()),                           importMessage(msg.getContent()),                           importMessage(msg.getQos()));      return msg;   }   /**    * decrypt, check, unseal etc an incomming message.     * <p/>    * @param String The the received message    * @return String The original message    * @exception XmlBlasterException Thrown i.e. if the message has been modified    */   private String importMessage(String xmlMsg) throws XmlBlasterException   {      if (xmlMsg==null) return null;      return new String(crypt(xmlMsg.getBytes()));   }   private byte[] importMessage(byte[] byteArr) throws XmlBlasterException   {      return crypt(byteArr);   }   /**    * encrypt, sign, seal an outgoing message.     * <p/>    * @param MsgUnitRaw The source message    * @return MsgUnitRaw    * @exception XmlBlasterException Thrown if the message cannot be processed    */   public MsgUnitRaw exportMessage(CryptDataHolder dataHolder) throws XmlBlasterException {      MsgUnitRaw msg = dataHolder.getMsgUnitRaw();      msg = new MsgUnitRaw(msg.getMsgUnit(),                           exportMessage(msg.getKey()),                            exportMessage(msg.getContent()),                           exportMessage(msg.getQos()));      return msg;   }   private String exportMessage(String xmlMsg) throws XmlBlasterException   {      if (xmlMsg==null) return null;//      return new String(crypt(xmlMsg.toCharArray()));      return new String(crypt(xmlMsg.getBytes()));    }   private byte[] exportMessage(byte[] byteArr) throws XmlBlasterException   {      return crypt(byteArr);   }   /**    * Well, rot13 is no encryption, but it illustrates what importMessage and    * ExportMessage could do.    */   private byte[] crypt(byte[] byteArr) {      if (byteArr==null) return null;      byte[] newByteArr = new byte[byteArr.length];      int tmp;      for (int i=0; i<byteArr.length; i++) {         tmp = byteArr[i];         tmp = ((tmp >= 'A') && (tmp <= 'Z')) ? ((tmp - 'A' + 13) % 26 + 'A') : tmp;         tmp = ((tmp >= 'a') && (tmp <= 'z')) ? ((tmp - 'a' + 13) % 26 + 'a') : tmp;         newByteArr[i]=(byte)tmp;      }      return newByteArr;   }/*   private char[] crypt(char[] charArr) {      if (charArr==null) return null;      char[] newCharArr = new char[charArr.length];      int cap;      int tmp;      for (int i=0; i<charArr.length; i++) {         tmp = charArr[i];         tmp = ((tmp >= 'A') && (tmp <= 'Z')) ? ((tmp - 'A' + 13) % 26 + 'A') : tmp;         tmp = ((tmp >= 'a') && (tmp <= 'z')) ? ((tmp - 'a' + 13) % 26 + 'a') : tmp;         newCharArr[i]=(char)tmp;      }      return newCharArr;   }*/}

⌨️ 快捷键说明

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