Xitrum学习笔记23 - HOWTO

上传人:nt****6 文档编号:35171749 上传时间:2018-03-11 格式:PDF 页数:9 大小:892.46KB
返回 下载 相关 举报
Xitrum学习笔记23 - HOWTO_第1页
第1页 / 共9页
Xitrum学习笔记23 - HOWTO_第2页
第2页 / 共9页
Xitrum学习笔记23 - HOWTO_第3页
第3页 / 共9页
Xitrum学习笔记23 - HOWTO_第4页
第4页 / 共9页
Xitrum学习笔记23 - HOWTO_第5页
第5页 / 共9页
点击查看更多>>
资源描述

《Xitrum学习笔记23 - HOWTO》由会员分享,可在线阅读,更多相关《Xitrum学习笔记23 - HOWTO(9页珍藏版)》请在金锄头文库上搜索。

1、博 客 园 新 随 笔 联 系 订 阅 管 理 随 笔 -35 章 -0 评 论 -0 秦 Xitrum 学 习 笔 记 23 - HOWTO 1. HTTP 基 本 认 证 ( Basic Authentication ) 使 HTTP 基 本 认 证 可 以 保 护 整 个 站 点 或 是 特 定 的 action 。 Xitrum 不 持 摘 要 认 证 ( Digest Authentication ),因为它容易受到中间攻击 (man-in-the-middle attack) 。 更 好 的 安 全 机 制 , 要 使 Xitrum 内建持的 HTTPS 。 为 整 个 站 点 配

2、 置 HTTP 基 本 认 证 : 在 config/xitrum.conf: “basicAuth“: “realm“: “xitrum“, “username“: “xitrum“, “password“: “xitrum“ 为 某 个 Action 配 置 HTTP 基 本 认 证 : import xitrum.Action class MyAction extends Action beforeFilter basicAuth(“Realm“) (username, password) = username = “username“ & password = “password“ 公

3、 告 昵 称 : 秦 园 龄 : 1 年 2 个 粉 丝 : 2 关 注 : 1 + 加 关 注 三 四 五 六 31 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 1 2 3 4 5 6 7 8 9 10 搜 索 找 找 看 歌 搜 索 常 链 接 我 的 随 笔 我 的 评 论 我 的 参 与 最 新 评 论 我 的 标 签 Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROW

4、D 2. 加 载 配 置 件 JSON 件 把 定 义 的 配 置 件 保 存 在 config 路 径 下 , 这个路径会被放在开发环境和产环境的 classpath 中。 开 发 环 境 的 classpath 配 置 由 build.sbt 设 置 , 产环境的 classpath 配置由 script/runner 设置 在 Action 中 加 载 个 配 置 件 , 如 myconfig.json : import xitrum.util.Loader case class MyConfig(username: String, password: String, children:

5、 SeqString) val myConfig = Loader.jsonFromClasspathMyConfig(“myconfig.json“) myconfig.json: “username“: “God“, “password“: “Does God need a password?“, “children“: “Adam“, “Eva“ 注 意 : key 和 字 符 串 必 须 被 双 引 号 扩 起 ; 不 能 再 JSON 件中写注释 属 性 件 (properties files) 也 可 以 使 属 性 件 , 但 是 它 不 是 类 型 安 全 的 ,也不持 UTF

6、-8 和嵌套结构,还是 JSON 更好些。 myconfig.properties: 我 的 标 签 Xitrum(2) 随 笔 分 类 AngularJS(2) hadoop HBase-1.2(8) Storm-1.1.0(6) Xitrum(18) Xitrum-Scalate-Jade(1) 随 笔 档 案 2017 年 10 (1) 2017 年 9 (8) 2017 年 8 (5) 2017 年 7 (1) 2017 年 5 (20) 阅 读 排 榜 1. Xitrum 学 习 笔 记 01 - 简 介 (189) 2. Xitrum 学 习 笔 记 04 - RESTful AP

7、Is(147) 3. Xitrum 学 习 笔 记 03 - Action 和 View(93) 4. Storm HBase 集 成 (80) 5. Xitrum 学 习 笔 记 19 - 部 署 到 产 环 境 (79) Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWDusername = God password = Does God need a password? children = Adam, Eva 加 载 properties 件 import xitrum.util.Load

8、er / Here you get an instance of java.util.Properties val properties = Loader.propertiesFromClasspath(“myconfig.properties“) 类 型 安 全 的 配 置 件 可 以 使 https:/ 提供的配置件库来加载配置件,是种更好的加 载 式 。 这 个 库 的 sbt dependency: libraryDependencies += “com.typesafe“ % “config“ % “1.3.1“ myconfig.conf: username = God passw

9、ord = Does God need a password? children = “Adam“, “Eva“ 加 载 件 import com.typesafe.config.Config, ConfigFactory val config = ConfigFactory.load(“myconfig.conf“) val username = config.getString(“username“) val password = config.getString(“password“) val children = config.getStringList(“children“) 3.

10、序 列 化 和 反 序 列 化 Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD序 列 化 成 ArrayByte: import xitrum.util.SeriDeseri val bytes = SeriDeseri.toBytes(“my serializable object“) 从 ArrayByte 反 序 列 化 : val option = SeriDeseri.fromBytesMyType(bytes) / OptionMyType 保 存 到 件 : import xit

11、rum.util.Loader Loader.bytesToFile(bytes, “myObject.bin“) 从 件 中 加 载 : val bytes = Loader.bytesFromFile(“myObject.bin“) 4. 加 密 数 据 如 果 加 密 数 据 后 不 需 解 密 , 可 以 使 MD5 如 果 要 解 密 数 据 , 可 以 使 Xitrum 提 供 的 具类 import xitrum.util.Secure / ArrayByte val encrypted = Secure.encrypt(“my data“.getBytes) / OptionA

12、rrayByte val decrypted = Secure.decrypt(encrypted) 可 以 使 xitrum.util.UrlSafeBase64 编 码 和 解码进制数据成普通字符串(嵌 HTML ) / String that can be included in URL, cookie etc. val string = UrlSafeBase64.noPaddingEncode(encrypted) Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWD/ OptionArr

13、ayByte val encrypted2 = UrlSafeBase64.autoPaddingDecode(string) 将 以 上 步 骤 合 并 为 步 import xitrum.util.SeriDeseri val mySerializableObject = new MySerializableClass / String val encrypted = SeriDeseri.toSecureUrlSafeBase64(mySerializableObject) / OptionMySerializableClass val decrypted = SeriDeseri.fr

14、omSecureUrlSafeBase64MySerializableClass(encrypted) SeriDeseri 使 Twitter Chill 进 序 列 化 和 反序列化,数据必须是可以序列化的 可 以 为 加 密 指 定 key val encrypted = Secure.encrypt(“my data“.getBytes, “my key“) val decrypted = Secure.decrypt(encrypted, “my key“) val encrypted = SeriDeseri.toSecureUrlSafeBase64(mySerializable

15、Object, “my key“) val decrypted = SeriDeseri.fromSecureUrlSafeBase64MySerializableClass(encrypted, “my key“) 如 果 没 有 指 定 key , xitrum.conf 中 指 定 的 secureKey 值会被当做 key 使。 5. 以 相 同 的 域 名 运 多 个 站 点 如 果 想 使 反 向 代 理 ( 如 Nginx ) 以 相 同 的 域名运多个站点 Create PDF in your applications with the Pdfcrowd HTML to PDF API PDFCROWDhttp:/ http:/ 可 以 在 config/xitrum.conf 中 配 置 baseUrl 在 JS 代 码 中 , 使 xitrum.js 中 的 withBaseUrl 为 Ajax 请求获取正确的 URLs # If the current sites baseUrl is “site1“, the result will be: # /site1/pa

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 大杂烩/其它

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号