<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">

  <title><![CDATA[POEMS]]></title>
  <link href="http://pieux.github.io/atom.xml" rel="self"/>
  <link href="http://pieux.github.io/"/>
  <updated>2014-01-15T23:59:44+08:00</updated>
  <id>http://pieux.github.io/</id>
  <author>
    <name><![CDATA[Pieux Xi]]></name>
    
  </author>

  
  <entry>
    <title type="html"><![CDATA[seajs]]></title>
    <link href="http://pieux.github.io/blog/2014/01/09/seajs/"/>
    <updated>2014-01-09T20:54:10+08:00</updated>
    <id>http://pieux.github.io/blog/2014/01/09/seajs</id>
    <content type="html"><![CDATA[<h1>[摘要]前端模块化开发的价值</h1>

<p><a href="https://github.com/seajs/seajs/issues/547">link</a></p>

<h2>恼人的命名冲突</h2>

<p> 看不懂，也没必要深究历史，略过</p>

<h2>烦琐的文件依赖</h2>

<h2>使用 Sea.js 来解决</h2>

<p>使用 Sea.js，在书写文件时，需要遵守 CMD （Common Module Definition）模
块定义规范。</p>

<p><strong>一个文件就是一个模块。</strong></p>

<p>前面例子中的 util.js</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>var org = {};
</span><span class='line'>org.CoolSite = {};
</span><span class='line'>org.CoolSite.Utils = {};
</span><span class='line'>
</span><span class='line'>org.CoolSite.Utils.each = function (arr) {
</span><span class='line'>  // 实现代码
</span><span class='line'>};
</span><span class='line'>
</span><span class='line'>org.CoolSite.Utils.log = function (str) {
</span><span class='line'>  // 实现代码
</span><span class='line'>};</span></code></pre></td></tr></table></div></figure>


<p>变成:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>define(function(require, exports) {
</span><span class='line'>  exports.each = function (arr) {
</span><span class='line'>    // 实现代码
</span><span class='line'>  };
</span><span class='line'>
</span><span class='line'>  exports.log = function (str) {
</span><span class='line'>    // 实现代码
</span><span class='line'>  };
</span><span class='line'>});</span></code></pre></td></tr></table></div></figure>


<p>通过 <code>exports</code> 就可以向外提供接口。这样，dialog.js 的代码变成:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>define(function(require, exports) {
</span><span class='line'>  var util = require('./util.js');
</span><span class='line'>
</span><span class='line'>  exports.init = function() {
</span><span class='line'>    // 实现代码
</span><span class='line'>  };
</span><span class='line'>});</span></code></pre></td></tr></table></div></figure>


<blockquote><p>所以： define API</p></blockquote>

<p>关键部分到了！我们通过 <code>require('./util.js')</code> 就可以拿到 util.js 中通过 <code>exports</code> 暴露的接口。</p>

<p>这里的 <code>require</code> 可以认为是 Sea.js 给 JavaScript 语言增加的一个 语法关键字，通过 require 可以获取其他模块提供的接口。</p>

<p>类似于 css 中的：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>@import url("base.css");
</span><span class='line'>
</span><span class='line'>#id { ... }
</span><span class='line'>.class { ... }</span></code></pre></td></tr></table></div></figure>


<p>Sea.js 增加的 require 语法关键字，就如 CSS 文件中的 @import 一样，给我们的源码赋予了依赖引入功能。</p>

<p>如果你是后端开发工程师，更不会陌生。Java、Python、C# 等等语言，都有 include、import 等功能。JavaScript 语言本身也有类似功能，但目前还处于草案阶段，需要等到 ES6 标准得到主流浏览器支持后才能使用。</p>

<p>这样，在页面中使用 dialog.js 将变得非常简单。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;script src="sea.js"&gt;&lt;/script&gt;
</span><span class='line'>&lt;script&gt;
</span><span class='line'>seajs.use('dialog', function(Dialog) {
</span><span class='line'>  Dialog.init(/* 传入配置 */);
</span><span class='line'>});
</span><span class='line'>&lt;/script&gt;</span></code></pre></td></tr></table></div></figure>


<p>首先要在页面中引入 sea.js 文件，这一般通过页头全局把控，也方便更新维护。</p>

<p>想在页面中使用某个组件时，只要通过 <code>seajs.use</code> 方法调用。</p>

<blockquote><p>所以： seajs.use API</p></blockquote>

<p>好好琢磨以上代码，我相信你已经看到了 Sea.js 带来的两大好处：</p>

<ol>
<li><p>通过 <code>exports</code> 暴露接口。这意味着不需要命名空间了，更不需要全局变量。这是一种彻底的命名冲突解决方案。</p></li>
<li><p>通过 <code>require</code> 引入依赖。这可以让依赖内置，开发者只需关心当前模块的依赖，其他事情 Sea.js 都会自动处理好。对模块开发者来说，这是一种很好的 关注度分离，能让程序员更多地享受编码的乐趣。</p></li>
</ol>


<h1>[摘要] 5 分钟上手 Sea.js</h1>

<h2>目录结构</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>examples/
</span><span class='line'>  |-- sea-modules      存放 seajs、jquery 等文件，这也是模块的部署目录
</span><span class='line'>  |-- static           存放各个项目的 js、css 文件
</span><span class='line'>  |     |-- hello
</span><span class='line'>  |     |-- lucky
</span><span class='line'>  |     `-- todo
</span><span class='line'>  `-- app              存放 html 等文件
</span><span class='line'>        |-- hello.html
</span><span class='line'>        |-- lucky.html
</span><span class='line'>        `-- todo.html</span></code></pre></td></tr></table></div></figure>


<p>我们从 hello.html 入手，来瞧瞧使用 Sea.js 如何组织代码。</p>

<h2>在页面中加载模块</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>// seajs 的简单配置
</span><span class='line'>seajs.config({
</span><span class='line'>  base: "../sea-modules/",
</span><span class='line'>  alias: {
</span><span class='line'>    "jquery": "jquery/jquery/1.10.1/jquery.js"
</span><span class='line'>  }
</span><span class='line'>})
</span><span class='line'>
</span><span class='line'>// 加载入口模块
</span><span class='line'>seajs.use("../static/hello/src/main")</span></code></pre></td></tr></table></div></figure>


<blockquote><p>seajs.config API
seajs.use API</p></blockquote>

<h2>模块代码</h2>

<p>这个小游戏有两个模块 spinning.js 和 main.js，遵循统一的写法：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>// 所有模块都通过 define 来定义
</span><span class='line'>define(function(require, exports, module) {
</span><span class='line'>
</span><span class='line'>  // 通过 require 引入依赖
</span><span class='line'>  var $ = require('jquery');
</span><span class='line'>  var Spinning = require('./spinning');
</span><span class='line'>
</span><span class='line'>  // 通过 exports 对外提供接口
</span><span class='line'>  exports.doSomething = ...
</span><span class='line'>
</span><span class='line'>  // 或者通过 module.exports 提供整个接口
</span><span class='line'>  module.exports = ...
</span><span class='line'>
</span><span class='line'>});</span></code></pre></td></tr></table></div></figure>


<h1>[摘要] API 快速参考</h1>

<h2>seajs.config</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>seajs.config({
</span><span class='line'>
</span><span class='line'>  // 设置路径，方便跨目录调用
</span><span class='line'>  paths: {
</span><span class='line'>    'arale': 'https://a.alipayobjects.com/arale',
</span><span class='line'>    'jquery': 'https://a.alipayobjects.com/jquery'
</span><span class='line'>  },
</span><span class='line'>
</span><span class='line'>  // 设置别名，方便调用
</span><span class='line'>  alias: {
</span><span class='line'>    'class': 'arale/class/1.0.0/class',
</span><span class='line'>    'jquery': 'jquery/jquery/1.10.1/jquery'
</span><span class='line'>  }
</span><span class='line'>
</span><span class='line'>});</span></code></pre></td></tr></table></div></figure>


<p>更多配置项请参考：#262</p>

<h2>seajs.use</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>// 加载一个模块
</span><span class='line'>seajs.use('./a');
</span><span class='line'>
</span><span class='line'>// 加载一个模块，在加载完成时，执行回调
</span><span class='line'>seajs.use('./a', function(a) {
</span><span class='line'>  a.doSomething();
</span><span class='line'>});
</span><span class='line'>
</span><span class='line'>// 加载多个模块，在加载完成时，执行回调
</span><span class='line'>seajs.use(['./a', './b'], function(a, b) {
</span><span class='line'>  a.doSomething();
</span><span class='line'>  b.doSomething();
</span><span class='line'>});</span></code></pre></td></tr></table></div></figure>


<p>更多配置项请参考：#260</p>

<h2>define</h2>

<p>用来定义模块。Sea.js 推崇一个模块一个文件，遵循统一的写法：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>define(function(require, exports, module) {
</span><span class='line'>
</span><span class='line'>  // 模块代码
</span><span class='line'>
</span><span class='line'>});</span></code></pre></td></tr></table></div></figure>


<p>也可以手动指定模块 id 和依赖，详情请参考：#242
require, exports 和 module 三个参数可酌情省略，具体用法如下。</p>

<h3>require</h3>

<p>require 用来获取指定模块的接口。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>define(function(require) {
</span><span class='line'>
</span><span class='line'>  // 获取模块 a 的接口
</span><span class='line'>  var a = require('./a');
</span><span class='line'>
</span><span class='line'>  // 调用模块 a 的方法
</span><span class='line'>  a.doSomething();
</span><span class='line'>});</span></code></pre></td></tr></table></div></figure>


<p>注意，require 只接受字符串直接量作为参数，详细约定请阅读：#259</p>

<h3>require.async</h3>

<p>用来在模块内部异步加载一个或多个模块。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>define(function(require) {
</span><span class='line'>
</span><span class='line'>  // 异步加载一个模块，在加载完成时，执行回调
</span><span class='line'>  require.async('./b', function(b) {
</span><span class='line'>    b.doSomething();
</span><span class='line'>  });
</span><span class='line'>
</span><span class='line'>  // 异步加载多个模块，在加载完成时，执行回调
</span><span class='line'>  require.async(['./c', './d'], function(c, d) {
</span><span class='line'>    c.doSomething();
</span><span class='line'>    d.doSomething();
</span><span class='line'>  });
</span><span class='line'>
</span><span class='line'>});</span></code></pre></td></tr></table></div></figure>


<p>详细说明请参考：#242</p>

<h3>exports</h3>

<p>用来在模块内部对外提供接口。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>define(function(require, exports) {
</span><span class='line'>
</span><span class='line'>  // 对外提供 foo 属性
</span><span class='line'>  exports.foo = 'bar';
</span><span class='line'>
</span><span class='line'>  // 对外提供 doSomething 方法
</span><span class='line'>  exports.doSomething = function() {};
</span><span class='line'>
</span><span class='line'>});</span></code></pre></td></tr></table></div></figure>


<p>详细说明请参考：#242</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[begin ios development]]></title>
    <link href="http://pieux.github.io/blog/2014/01/08/begin-ios-development/"/>
    <updated>2014-01-08T20:30:45+08:00</updated>
    <id>http://pieux.github.io/blog/2014/01/08/begin-ios-development</id>
    <content type="html"><![CDATA[<h1>开始 iOS 开发</h1>

<h2>iOS 开发环境</h2>

<ul>
<li>MapKit</li>
<li>WebKit</li>
<li>StoreKit</li>
<li>MediaPlayer</li>
<li>Social</li>
<li>CoreData</li>
</ul>


<p>Model-View-Controller(MVC)</p>

<h2>使用 Xcode</h2>

<p>storyboard 文件</p>

<p>XCode 界面</p>

<ul>
<li>Utilities</li>
<li>UIKit</li>
</ul>


<h1>创建一个 iOS 应用</h1>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[jasig cas server cacerts]]></title>
    <link href="http://pieux.github.io/blog/2014/01/08/jasig-cas-server-cacerts/"/>
    <updated>2014-01-08T10:49:34+08:00</updated>
    <id>http://pieux.github.io/blog/2014/01/08/jasig-cas-server-cacerts</id>
    <content type="html"><![CDATA[<p>由于 SSO 域名切换成好记的域名，需要重新生成证书，并导入：</p>

<h1>删除 Client 中曾导入的旧的证书</h1>

<p>先找到 CAS Client 部署服务器的
存储 所有信任证书（cacerts） 的位置：<code>/usr/local/jdk/jre/lib/security/cacerts</code></p>

<p> 从中删除原来导入的 cacert。 注： 之前 这里取的别名是 smalllove，这次
 重新取个好记的名字 ssoalpha</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[dianping@host_214-74 security]$ keytool -delete -trustcacerts -alias smalllove -keystore /usr/local/jdk/jre/lib/security/cacerts -storepass changeit</span></code></pre></td></tr></table></div></figure>


<h1>Server 重新生成证书</h1>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>keytool -genkey -alias ssoalpha -keyalg RSA -storepass changeit  -keystore ~/keys/.keystore -validity 3600</span></code></pre></td></tr></table></div></figure>




<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[dianping@host_214-124 ~]$ keytool -genkey -alias ssoalpha -keyalg RSA -storepass changeit  -keystore ~/keys/.keystore -validity 3600
</span><span class='line'>您的名字与姓氏是什么？
</span><span class='line'>  [Unknown]：  sso.a.alpha.dp
</span><span class='line'>您的组织单位名称是什么？
</span><span class='line'>  [Unknown]：  ssoalpha
</span><span class='line'>您的组织名称是什么？
</span><span class='line'>  [Unknown]：  ssoalpha
</span><span class='line'>您所在的城市或区域名称是什么？
</span><span class='line'>  [Unknown]：  ssoalpha
</span><span class='line'>您所在的州或省份名称是什么？
</span><span class='line'>  [Unknown]：  ssoalpha
</span><span class='line'>该单位的两字母国家代码是什么
</span><span class='line'>  [Unknown]：  CN
</span><span class='line'>CN=sso.a.alpha.dp, OU=ssoalpha, O=ssoalpha, L=ssoalpha, ST=ssoalpha, C=CN 正确吗？
</span><span class='line'>  [否]：  y
</span><span class='line'>
</span><span class='line'>输入&lt;ssoalpha&gt;的主密码
</span><span class='line'>    （如果和 keystore 密码相同，按回车）：
</span><span class='line'>[dianping@host_214-124 ~]$</span></code></pre></td></tr></table></div></figure>


<h1>JBOSS 配置 SSL</h1>

<p>因为重新生成了 keystore，而 JBoss 的 SSL 配置有一部分需要用到
<code>keystore</code> 文件。</p>

<p>JBoss 配置 SSL 需要动到的文件：
<code>$JBOSS_HOME/server/default/deploy/jboss-web.deployer/server.xml</code></p>

<p> 其中的 keystoreFile 的位置是：<code>$JBOSS_HOME/server/default/conf/server.keystore</code>。</p>

<p> 这个 keystore 就是生成证书时生成的。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;!-- Define a SSL HTTP/1.1 Connector on port 8443
</span><span class='line'>     This connector uses the JSSE configuration, when using APR, the
</span><span class='line'>     connector should be using the OpenSSL style configuration
</span><span class='line'>     described in the APR documentation --&gt;
</span><span class='line'>
</span><span class='line'>&lt;Connector port="8443" address="${jboss.bind.address}"
</span><span class='line'>            protocol="HTTP/1.1" SSLEnabled="true"
</span><span class='line'>           maxThreads="150" scheme="https" secure="true"
</span><span class='line'>           clientAuth="false" sslProtocol="TLS"
</span><span class='line'>           keystoreFile="${jboss.server.home.dir}/conf/server.keystore"
</span><span class='line'>           keystorePass="changeit"
</span><span class='line'>           /&gt;</span></code></pre></td></tr></table></div></figure>


<p> 特别注意下：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>同样的war在tomcat下运行是没有问题的，但在jboss下却包上面的异常。这说明正常情况下HibernatePersistence 应该能转换成PersistenceProvider，不能转换的原因就是这两个类是由不同的加载器加载的。搜索jboss classloader查找解决方案，设置server\default\deploy\JBoss-web.deploy\META-INF\JBoss-service.xml 文件中的&lt;attribute name="UseJBossWebLoader"&gt;true&lt;/attribute&gt;.</span></code></pre></td></tr></table></div></figure>


<h1>Server 导出证书</h1>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[dianping@host_214-124 keys]$ keytool -export -file ~/keys/ssoalpha.crt -alias ssoalpha -keystore ~/keys/.keystore -storepass changeit
</span><span class='line'>保存在文件中的认证 &lt;/home/dianping/keys/ssoalpha.crt&gt;</span></code></pre></td></tr></table></div></figure>


<h1>使用 SCP 工具从 server 下载证书</h1>

<p>注意写成完整路径：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>scp -P 58422 dianping@192.168.214.124:$1 $2
</span><span class='line'>copy-from-alpha-cas-server /home/dianping/keys/ssoalpha.crt .</span></code></pre></td></tr></table></div></figure>


<h1>使用 SCP 工具把证书上传到 client 部署机器</h1>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>scp -P 58422 $1 dianping@192.168.214.74:$2
</span><span class='line'>copy-to-alpha-employee-port ./ssoalpha.crt /home/dianping/keys/.</span></code></pre></td></tr></table></div></figure>


<h1>client 导入证书</h1>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>[dianping@host_214-74 keys]$ keytool -import -keystore /usr/local/jdk/jre/lib/security/cacerts -file ./ssoalpha.crt -alias ssoalpha
</span><span class='line'>输入keystore密码：
</span><span class='line'>所有者:CN=sso.a.alpha.dp, OU=ssoalpha, O=ssoalpha, L=ssoalpha, ST=ssoalpha, C=CN
</span><span class='line'>签发人:CN=sso.a.alpha.dp, OU=ssoalpha, O=ssoalpha, L=ssoalpha, ST=ssoalpha, C=CN
</span><span class='line'>序列号:52ccbfcc
</span><span class='line'>有效期: XXX
</span><span class='line'>证书指纹:
</span><span class='line'>     XXX
</span><span class='line'>     签名算法名称:SHA1withRSA
</span><span class='line'>     版本: X
</span><span class='line'>信任这个认证？ [否]：  y
</span><span class='line'>认证已添加至keystore中</span></code></pre></td></tr></table></div></figure>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[A Intro to Ionic &amp; AngularJS]]></title>
    <link href="http://pieux.github.io/blog/2014/01/07/a-intro-to-ionic-and-angularjs/"/>
    <updated>2014-01-07T12:07:40+08:00</updated>
    <id>http://pieux.github.io/blog/2014/01/07/a-intro-to-ionic-and-angularjs</id>
    <content type="html"><![CDATA[<h1>Phonegap</h1>

<p> Phonegap 到底是什么？</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Gradle Installation on Mac OS X]]></title>
    <link href="http://pieux.github.io/blog/2014/01/06/gradle-installation-on-mac-os-x/"/>
    <updated>2014-01-06T18:55:29+08:00</updated>
    <id>http://pieux.github.io/blog/2014/01/06/gradle-installation-on-mac-os-x</id>
    <content type="html"><![CDATA[<h1>Installation</h1>

<p>refer <a href="http://www.gradle.org/installation">link</a></p>

<p> 看文档发现了一个好玩的东西：</p>

<p><strong>For Un*x users</strong></p>

<p>You need a GNU compatible tool to unzip Gradle, if you want the file permissions to be properly set. We mention this as some zip front ends for Mac OS X don&rsquo;t restore the file permissions properly.</p>

<p> 权限要正确被设置，注意下。</p>

<p><strong>ENVIRONMENT VARIABLES</strong></p>

<p>add <code>GRADLE_HOME/bin</code> to PATH.</p>

<p><strong>TEST INSTALLATION</strong></p>

<p><code>gradle -v</code></p>

<h1>Build Scripts Basics</h1>

<p>basic concepts: <em>projects</em> and <em>tasks</em>.</p>

<p>below is the <code>build.gradle</code> of
<a href="https://github.com/JakeWharton/hugo">JakeWharton/hugo</a>. Take is as a
start to learn gradle.</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>allprojects {
</span><span class='line'>  buildscript {
</span><span class='line'>    repositories {
</span><span class='line'>      mavenCentral()
</span><span class='line'>    }
</span><span class='line'>  }
</span><span class='line'>
</span><span class='line'>  dependencies {
</span><span class='line'>    repositories {
</span><span class='line'>      mavenCentral()
</span><span class='line'>    }
</span><span class='line'>  }
</span><span class='line'>
</span><span class='line'>  group = GROUP
</span><span class='line'>  version = VERSION_NAME
</span><span class='line'>
</span><span class='line'>  apply plugin: 'maven'
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>task wrapper(type: Wrapper) {
</span><span class='line'>  gradleVersion = '1.8'
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>task cleanExample(type: Exec) {
</span><span class='line'>  executable = 'gradle'
</span><span class='line'>  workingDir = project.file('hugo-example')
</span><span class='line'>  args = [ 'clean' ]
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>task assembleExample(type: Exec) {
</span><span class='line'>  executable = 'gradle'
</span><span class='line'>  workingDir = project.file('hugo-example')
</span><span class='line'>  args = [ 'assemble' ]
</span><span class='line'>}
</span><span class='line'>
</span><span class='line'>task installExample(type: Exec) {
</span><span class='line'>  executable = 'gradle'
</span><span class='line'>  workingDir = project.file('hugo-example')
</span><span class='line'>  args = [ 'installDebug' ]
</span><span class='line'>}</span></code></pre></td></tr></table></div></figure>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Resources for Starting Phonegap]]></title>
    <link href="http://pieux.github.io/blog/2014/01/05/resources-for-starting-phonegap/"/>
    <updated>2014-01-05T10:57:10+08:00</updated>
    <id>http://pieux.github.io/blog/2014/01/05/resources-for-starting-phonegap</id>
    <content type="html"><![CDATA[<p> 起步 phonegap 的一些文章和资源：</p>

<ul>
<li>前端 f2e 的框架和学习资源</li>
<li>JavaScript 的框架和学习资源</li>
<li>Phonegap 的文档和一些工具</li>
<li>apple 开发者的一些准备工作</li>
</ul>


<h1>phonegap</h1>

<p>resources:</p>

<ul>
<li><a href="http://docs.phonegap.com/en/edge/guide_cli_index.md.html#The%20Command-Line%20Interface">The Command-Line Interface</a></li>
</ul>


<p>使用的是 ionic 提供的 seed project，所以不需要使用 phonegap 的 create
指令。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ phonegap build ios # Build the App
</span><span class='line'>$ phonegap install android # Test the App on an Emulator or Device</span></code></pre></td></tr></table></div></figure>


<p> 更新 App，但是貌似没有我想的效果：</p>

<p> <code>
$ phonegap platform update android
$ phonegap platform update ios
</code></p>

<p> 该文章中其他部分：
 &ndash; 添加插件
 &ndash; 使用 phonegap build</p>

<h1>框架</h1>

<ul>
<li>ionic</li>
<li>angularjs</li>
</ul>


<p>AngularJS 的学习资源参见一个 github repo :
<a href="https://github.com/jmcunningham/AngularJS-Learning">jmcunningham/AngularJS-Learning</a></p>

<h1>工具</h1>

<ul>
<li>phonegap build

<h2>&ndash; firebase</h2></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Git Brune Stale Branchs]]></title>
    <link href="http://pieux.github.io/blog/2013/12/25/git-brune-stale-branchs/"/>
    <updated>2013-12-25T14:28:20+08:00</updated>
    <id>http://pieux.github.io/blog/2013/12/25/git-brune-stale-branchs</id>
    <content type="html"><![CDATA[
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Some cheating parts when use spring test with junit]]></title>
    <link href="http://pieux.github.io/blog/2013/12/25/some-cheating-parts-when-use-spring-test-with-junit/"/>
    <updated>2013-12-25T10:33:19+08:00</updated>
    <id>http://pieux.github.io/blog/2013/12/25/some-cheating-parts-when-use-spring-test-with-junit</id>
    <content type="html"><![CDATA[<p>refer section:</p>

<ol>
<li><a href="https://www.evernote.com/shard/s30/sh/cc6585d7-d14f-44a3-a20a-d99886ccb8eb/d4799edf2864d020fce50318e75e0825">why test not run</a></li>
<li><a href="http://forum.spring.io/forum/spring-projects/container/52022-spring-test-breaks-in-junit-4-5">spring-test breaks in Junit 4.5</a></li>
</ol>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[use gist.el]]></title>
    <link href="http://pieux.github.io/blog/2013/12/21/use-gist-dot-el/"/>
    <updated>2013-12-21T21:05:30+08:00</updated>
    <id>http://pieux.github.io/blog/2013/12/21/use-gist-dot-el</id>
    <content type="html"><![CDATA[<p><a href="https://github.com/defunkt/gist.el">github repo</a></p>

<p>gist buffer:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>g : reload the gist list from server
</span><span class='line'>e : edit current gist description
</span><span class='line'>k : delete current gist
</span><span class='line'>+ : add a file to the current gist
</span><span class='line'>- : remove a file from the current gist</span></code></pre></td></tr></table></div></figure>


<p>in-place edition. While viewing a gist file buffer, you can:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>C-x C-s : save a new version of the gist
</span><span class='line'>C-x C-w : rename some file</span></code></pre></td></tr></table></div></figure>


<p>Functions:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>gist-list - Lists your gists in a new buffer. Use arrow keys
</span><span class='line'>to browse, RET to open one in the other buffer.
</span><span class='line'>
</span><span class='line'>gist-region - Copies Gist URL into the kill ring.
</span><span class='line'>With a prefix argument, makes a private gist.
</span><span class='line'>
</span><span class='line'>gist-region-private - Explicitly create a private gist.
</span><span class='line'>
</span><span class='line'>gist-buffer - Copies Gist URL into the kill ring.
</span><span class='line'>With a prefix argument, makes a private gist.
</span><span class='line'>
</span><span class='line'>gist-buffer-private - Explicitly create a private gist.
</span><span class='line'>
</span><span class='line'>gist-region-or-buffer - Post either the current region, or if mark
</span><span class='line'>is not set, the current buffer as a new paste at gist.github.com .
</span><span class='line'>Copies the URL into the kill ring.
</span><span class='line'>With a prefix argument, makes a private paste.
</span><span class='line'>
</span><span class='line'>gist-region-or-buffer-private - Explicitly create a gist from the
</span><span class='line'>region or buffer.</span></code></pre></td></tr></table></div></figure>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Things about Tomcat SSL Certification and CAS(SAML)]]></title>
    <link href="http://pieux.github.io/blog/2013/12/12/things-about-tomcat-ssl-certification-and-cas-saml/"/>
    <updated>2013-12-12T03:07:00+08:00</updated>
    <id>http://pieux.github.io/blog/2013/12/12/things-about-tomcat-ssl-certification-and-cas-saml</id>
    <content type="html"><![CDATA[<p>这里是对Tomcat配置证书（生成/导出/导入）的 spike 总结。也不一定是总结
啦。</p>

<p>会总结哪些方面呢？</p>

<ol>
<li>keytool 相关的命令和作用；</li>
<li>Tomcat 的 SSL 配置；</li>
<li>什么是证书？</li>
<li>服务端和客户端都在本地的配置（开发配置）；</li>
<li>服务端部署在其他域名上；</li>
<li>etc.</li>
</ol>


<p>目前想到的几个问题：
&ndash; <code>~/.keystore</code>，为什么 client 会找这个文件？</p>

<ul>
<li><code>self-signed certificate</code></li>
</ul>


<h2>CAS Java Client 配置 SAML 1.1</h2>

<p>在 client 需要添加这些依赖：</p>

<ul>
<li>cas-client-core-3.1.3.jar</li>
<li>commons-codec-1.4.jar</li>
<li>commons-logging-1.1.jar</li>
<li>opensaml-1.1.jar</li>
<li>xmlsec-1.4.0.jar</li>
<li>log4j-1.2.15.jar</li>
</ul>


<p>关于版本，core的话，目前最新的是 3.2。opensaml肯定使用 1.1，因为是
SAML1.1 协议。</p>

<p>其他几个包是什么呢？不需要深入了解，从名称猜测，commons-codec 提供了一
些 encode，decode 方法。xmlsec 应该是安全的XML。</p>

<p>cas-client-core
<a href="http://mvnrepository.com/artifact/org.jasig.cas">http://mvnrepository.com/artifact/org.jasig.cas</a></p>

<p>commons-codec
<a href="http://mvnrepository.com/artifact/commons-codec/commons-codec">http://mvnrepository.com/artifact/commons-codec/commons-codec</a></p>

<p>opensaml
<a href="http://mvnrepository.com/artifact/org.opensaml/opensaml/1.1">http://mvnrepository.com/artifact/org.opensaml/opensaml/1.1</a></p>

<p>xmlsec
<a href="http://mvnrepository.com/artifact/org.apache.santuario/xmlsec">http://mvnrepository.com/artifact/org.apache.santuario/xmlsec</a></p>

<h2>Tomcat 配置 SSL</h2>

<p>关于 Tomcat 配置 SSL</p>

<h3>什么是 SSL?</h3>

<blockquote><p>主要参考文章 <a href="http://www.sunchis.com/html/java/javaweb/2010/0313/68.html">SSL简介</a></p></blockquote>

<p>SSL(Server Socket Layer)</p>

<blockquote><p>SSL（Server Socket Layer）是一种保证网络上的两个节点进行安全通信的协议。IETF（Internet Engineering Task Force）组织对SSL作了标准化，制订了RFC2246规范，并将其称为TLS（Transport Layer Security）。从技术上讲，目前TLS 1.0与TLS 3.0的差别非常微小。</p></blockquote>

<p>从引用看出一个经常看到的术语：TLS，就是标准化的 SSL 通信协议。换句话说，
TLS 是基于 SSL 开发的。准确地说，TLS 1.0 替代了 SSL 2.0，并且 TLS 1.0
和 SSL 3.0 的差别不大，但不能忽操作。</p>

<p>这方面的参考链接：</p>

<ol>
<li><p><a href="http://luxsci.com/blog/ssl-versus-tls-whats-the-difference.html">SSL versus TLS – What’s the difference?</a></p></li>
<li><p><a href="http://msdn.microsoft.com/en-us/library/windows/desktop/aa380515(v=vs.85).aspx">TLS vs. SSL</a></p></li>
<li><p><a href="http://www.cnblogs.com/adforce/archive/2012/11/27/2790937.html">SSL/TLS 协议详解</a></p></li>
</ol>


<p>SSL和TLS建立在TCP/IP协议的基础上，一些应用层协议，如HTTP和IMAP协议都可
以采用SSL来保证通信的安全。建立在SSL协议上的HTTP被称为HTTPS协议。HTTP
使用的默认端口为80，而HTTPS使用的默认端口为443。</p>

<table>
<thead>
<tr>
<th align="center">协议层</th>
<th align="center">协议</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">应用层</td>
<td align="center">HTTP、IMAP、NNTP、Telnet、FTP等</td>
</tr>
<tr>
<td align="center">安全套接字层</td>
<td align="center">SSL、TLS</td>
</tr>
<tr>
<td align="center">传输层</td>
<td align="center">TCP</td>
</tr>
<tr>
<td align="center">网络层</td>
<td align="center">IP</td>
</tr>
</tbody>
</table>


<p>SSL采用加密技术来实现安全通信，保证通信数据的保密性和完整性，并且保证
通信双方可以验证对方的身份。</p>

<h3>SSL 中的证书</h3>

<p>除了对数据通信进行加密外，SSL还采用了身份认证机制，确保通信双方都可以
验证对方的真实身份。</p>

<p>SSL通过安全证书来证明客户或服务器的身份。当客户通过安全的连接和服务器
通信时，服务器会先向客户出示它的安全证书，这个证书声明该服务器是安全的，
而且的确是这个服务器。每一个证书在全球范围内都是唯一的，其他非法服务器
无法假冒原始服务器的身份。可以把安全证书比做电子身份证。</p>

<p>获取安全证书是一件麻烦的事情。一些服务器会向客户出示自己的安全证书，但
另一方面，为了扩大客户群并且便于客户访问，许多服务器不要求客户出示安全
证书。在某些情况下，服务器也会要求客户出示安全证书，以便核实客户的身份，
这主要用于B2B（Business to Business）事务中。</p>

<p>获取安全证书有两种方式，一种方式是从权威机构购买证书，还有一种方式是创建自我签名的证书。</p>

<p><strong>1 从权威机构获得证书</strong></p>

<p>安全证书可以有效地保证通信双方身份的可信性。安全证书采用加密技术制作而
成，他人几乎无法伪造。安全证书由国际权威的证书机构（Certificate
Authority，CA）如VeriSign（www.verisign.com）和Thawte（www.thawte.com）
颁发，它们保证了证书的可信性。申请安全证书时，必须支付一定的费用。一个
安全证书只对一个IP地址有效，如果用户的系统环境中有多个IP，那么必须为每
个IP地址购买安全证书。</p>

<p><strong>2 创建自我签名证书</strong></p>

<p>在某些场合，通信双方只关心数据在网络上可以安全传输，并不需要对对方进行
身份验证，在这种情况下，可以创建自我签名（self-assign）的证书，比如通
过SUN公司提供的keytool工具就可以创建这样的证书。</p>

<p>即，只需要数据加密传输，而不需要额外的一层身份校验。</p>

<h2>使用 keytool 工具</h2>

<p>这方面的参考文章很多。</p>

<p>对于 .Net，请参考：
<a href="http://www.cnblogs.com/zhenyulu/archive/2013/01/22/2870838.html">Yale CAS + .net Client 实现 SSO（1）</a></p>

<p>对于 Java，请参考：
<a href="http://blog.csdn.net/small_love/article/details/6664831">CAS实现单点登录（SSO）经典完整教程</a>
。</p>

<p>这里唯一需要注意的一点是：生成证书时，要求输入名称和姓氏(First Name
and Last Name)时，需要输入部署 cas server 的计算机名，比如：
pieux-macbook-pro.local 或者 tech-w-xishanshan。在后面的配置 cas
client 的 Authentication Filter 和 Validation Filter 时，配置的服务器
地址应该也是以计算机名开头，不要使用 localhost 或者 ip：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;init-param&gt;
</span><span class='line'>    &lt;param-name&gt;casServerLoginUrl&lt;/param-name&gt;
</span><span class='line'>    &lt;param-value&gt;https://pieux-macbook-pro.local:8443/cas/login&lt;/param-value&gt;
</span><span class='line'>&lt;/init-param&gt;
</span><span class='line'>...
</span><span class='line'>&lt;filter-name&gt;CAS Validation Filter&lt;/filter-name&gt;
</span><span class='line'>&lt;filter-class&gt;org.jasig.cas.client.validation.Saml11TicketValidationFilter&lt;/filter-class&gt;
</span><span class='line'>&lt;init-param&gt;
</span><span class='line'>    &lt;param-name&gt;casServerUrlPrefix&lt;/param-name&gt;
</span><span class='line'>    &lt;param-value&gt;https://pieux-macbook-pro.local:8443/cas&lt;/param-value&gt;
</span><span class='line'>&lt;/init-param&gt;</span></code></pre></td></tr></table></div></figure>


<h2>自我签名证书在开发中的注意事项</h2>

<p>如果 cas server 和 cas client 都部署在相同的机器上（一般是开发过程中），
那如果你按照上面和上面提到的参考文章的步骤，就应该不会有错误了。</p>

<p>但是，有一个大坑。如果 cas server 和 cas client 不是部署在一台机器上，
你很有可能会遇到一个<strong>异常</strong>是：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>sun.security.validator.ValidatorException: PKIX path building failed:</span></code></pre></td></tr></table></div></figure>


<p> The problem here is that the CAS client does not trust the
 certificate presented by the CAS server; most often this occurs
 because of using a self-signed certificate on the CAS server.</p>

<p>该问题一般是 cas client 不信任 cas server 展示的证书，而且绝大多数情况
下（按我目前遇到的，就是所有情况下），是 cas server 向 client 展示的是
self-signed certificate。</p>

<p>而且，使用SAML11的时候会报错（难道是SAML11也需要检验证书的真实性？），
使用CAS20就不会报错。因为按理说，SSL可以不需要证书，只利用加密通信的特
性。这块持续挖掘下。</p>

<p>那怎么解决这个问题呢？很简单，让 client 信任 server 的证书就行了。把
server 端生成的证书拷贝到 client 端部署的机器上，然后用 keytool 工具导
入到 client 机器 JDK 的 cacerts 里。</p>

<h2>SSL握手通信过程</h2>

<blockquote><p>主要参考文章 <a href="http://www.sunchis.com/html/java/javaweb/2010/0313/68.html">SSL握手通信过程</a></p></blockquote>

<p>暂时先不了解。</p>

<h2>什么是 <code>.keystore</code> 文件？</h2>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[First Touch of Travis CI]]></title>
    <link href="http://pieux.github.io/blog/2013/12/11/first-touch-of-travis-ci/"/>
    <updated>2013-12-11T02:37:00+08:00</updated>
    <id>http://pieux.github.io/blog/2013/12/11/first-touch-of-travis-ci</id>
    <content type="html"><![CDATA[<p>目前 Travis CI 给我的感觉和 Jekins 类似，每次 push 到 github 上，
Travis 会自动跑一遍，比如按官方文档所说，对于 Java 项目，如果发现
pom.xml 文件，会使用 Maven 3 的一些 lifecycle。</p>

<p>对于一个 Java 项目，需要在 .git/ 目录下，新建文件 <code>.travis.yml</code>，最简
单的内容是：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>language: java</span></code></pre></td></tr></table></div></figure>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[NOTE: Everything about CAS]]></title>
    <link href="http://pieux.github.io/blog/2013/12/08/note-everything-about-cas/"/>
    <updated>2013-12-08T02:12:00+08:00</updated>
    <id>http://pieux.github.io/blog/2013/12/08/note-everything-about-cas</id>
    <content type="html"><![CDATA[<p>假设 CAS Server 的域名是 cas.server.com</p>

<p>CAS Server 的 webapp 是 spring web flow，登陆地址为：<a href="https://cas.server.com/cas/login">https://cas.server.com/cas/login</a></p>

<p>登出地址为：<a href="https://cas.server.com/cas/logout">https://cas.server.com/cas/logout</a></p>

<p>语言参数为：locale=zh_CN，locale=en</p>

<p>除了配置 CAS Server 和 Client 外，需要配置环境，包括生成和导出导入证书，Tomcat配置SSL等。</p>

<h2>CAS Server</h2>

<h3>原理（认证流程）</h3>

<p><img src="http://i.imgur.com/MDSRTIc.jpg" alt="CAS 基本模式" /></p>

<p><strong>原理</strong>：按照此图来说</p>

<ol>
<li><p>用户访问CAS Client</p></li>
<li><p>其配置的 AuthenticationFilter 会拦截此请求，生成 service 参数，并重定向到 CAS Server 的登陆接口，url为 <a href="https://cas.server.com/login?service=redirect_url">https://cas.server.com/login?service=redirect_url</a></p></li>
<li><p>用户在 CAS Server 输入 Credentials(一般就是用户名和密码)进行身份验证，成功后，CAS Server 会生成认证 cookie，即TGC。（另：TGC作为 cookie之外，也会换存在服务器本地，我猜测是不是服务器运行实例的内存中。）</p></li>
<li><p>CAS Server还会根据 service 参数，生成 Ticket，即ST。ST会保存在服务器，也会加在 url 后面，重定向回 client。url为 <a href="http://client_server_url:port/app_name?ticket=ST-*-*">http://client_server_url:port/app_name?ticket=ST-*-*</a></p></li>
<li><p>Client 的 AuthenticationFilter 看到 ticket 参数后，会跳过，交由后面的 TicketValidationFilter 来处理。TicketValidationFilter 会利用 httpclient 工具访问 cas server 的 /serviceValidate 接口，将 ticket, service 传入该接口，验证 ticket 的有效性。</p></li>
<li><p>如果返回验证成功，就会把用户信息写入 client 的 session 里。</p></li>
</ol>


<p>至此，SSO 会话就建立起来了。</p>

<p>结果就是：</p>

<ol>
<li><p>用户在同一浏览器访问同一 client，不会去 CAS Server 认证，因为 AuthenticationFilter 会在 session 读取到用户信息。</p></li>
<li><p>用户在同一浏览器访问其他 client，AuthenticationFilter 在 session 里读不到用户信息，会去 cas login 接口认证，但是此时 cas login 接口会读取到存储在cas server域名下的 TGC，所以，CAS Server不会跳到登录页，只会根据 service 参数生成一个 ticket，传给 client。然后由TicketValidationFilter做一次交互验证。</p></li>
</ol>


<h3>CAS Server 提供的接口</h3>

<p>cas server 一共定义了9个接口。client 会通过 url redirect 和 httpclient 的方式和 server 交互。</p>

<table>
<thead>
<tr>
<th align="center">接口 </th>
<th align="left"> 说明</th>
</tr>
</thead>
<tbody>
<tr>
<td align="center">/login        </td>
<td align="left"> 认证接口</td>
</tr>
<tr>
<td align="center">/logout       </td>
<td align="left"> 退出接口，销毁 TGC</td>
</tr>
<tr>
<td align="center">/validate     </td>
<td align="left"> 验证 ticket 接口，CAS1.0</td>
</tr>
<tr>
<td align="center">/serviceValidate </td>
<td align="left"> 同上，CAS2.0</td>
</tr>
<tr>
<td align="center">/proxy        </td>
<td align="left"> 支持代理功能的接口</td>
</tr>
<tr>
<td align="center">/proxyValidate </td>
<td align="left"> 同上</td>
</tr>
<tr>
<td align="center">/CentralAuthenticationService </td>
<td align="left"> 用于和远程的 web services 交互</td>
</tr>
<tr>
<td align="center">/remoteLogin  </td>
<td align="left"> 认证接口（新增）</td>
</tr>
<tr>
<td align="center">/directLogin  </td>
<td align="left"> 认证接口（新增）</td>
</tr>
</tbody>
</table>


<h2>认证相关的术语</h2>

<ul>
<li><p><strong>Credentials</strong> 用户提供的凭证，比如 用户名/密码，证书，IP地址，Cookie值等。</p></li>
<li><p><strong>AuthenticationHandler</strong> 认证Handler，比如：AbstractUsernamePasswordAuthenticationHandler 负责处理 UsernamePasswordCredentials.</p></li>
<li><p><strong>CredentialsToPrincipalResolvers</strong> 负责由 Credentials 生成 Principal 对象，每种 CredentialsToPrincipalResolvers 只处理 一种Credentials ，比如 UsernamePasswordCredentialsToPrincipalResolver 负责从 UsernamePasswordCredentials 中取出用户名，然后将其赋给生成的 SimplePrincipal 的 ID 属性。</p></li>
<li><p><strong>AuthenticationMetaDataPopulators</strong> 负责将 Credentials 的一些属性赋值给 Authentication 的 attributes 属性。</p></li>
<li><p><strong>Authentication</strong>  Authentication是认证管理器的最终处理结果， Authentication 封装了 Principal ，认证时间，及其他一些属性（可能来自 Credentials）。</p></li>
<li><p><strong>AuthenticationManager</strong> 认证管理器得到 Credentials 对象后，负责调度AuthenticationHandler 去完成认证工作，最后返回的结果是 Authentication 对象。</p></li>
<li><p><strong>CentralAuthenticationService</strong> CAS 的服务类，对 Web 层提供了一些方法。该类还负责调用 AuthenticationManager 完成认证逻辑。</p></li>
</ul>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Maven Archetype Plugin]]></title>
    <link href="http://pieux.github.io/blog/2013/12/08/maven-archetype-plugin/"/>
    <updated>2013-12-08T01:31:00+08:00</updated>
    <id>http://pieux.github.io/blog/2013/12/08/maven-archetype-plugin</id>
    <content type="html"><![CDATA[<h2>Struts 2 Maven Archetype</h2>

<h3>The Blank Archetype (struts2-archetype-blank)</h3>

<h3>The Starter Archetype (struts2-archetype-starter)</h3>

<p>Compared to the former, it adds more features like &ldquo;Spring Integration&rdquo;.</p>

<h3>The Blank Convention Archetype (struts2-archetype-convention)</h3>

<p>Features like &ldquo;Convention-based validation&rdquo;, &ldquo;GAE aware&rdquo;.</p>

<h2>Creating an Application Using a Maven Archetyp</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>mvn archetype:generate -B \
</span><span class='line'>                       -DgroupId=tutorial \
</span><span class='line'>                       -DartifactId=tutorial \
</span><span class='line'>                       -DarchetypeGroupId=org.apache.struts \
</span><span class='line'>                       -DarchetypeArtifactId=struts2-archetype-blank \
</span><span class='line'>                       -DarchetypeVersion=&lt;version&gt;</span></code></pre></td></tr></table></div></figure>


<p>If the above command will fail because of missing archetypes in central repository, you can try to use staging repository like below</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>mvn archetype:generate -DarchetypeCatalog=http://people.apache.org/builds/struts/&lt;version&gt;/m2-staging-repository/</span></code></pre></td></tr></table></div></figure>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[NOTE: CAS Java Client]]></title>
    <link href="http://pieux.github.io/blog/2013/12/05/note-cas-java-client/"/>
    <updated>2013-12-05T08:43:00+08:00</updated>
    <id>http://pieux.github.io/blog/2013/12/05/note-cas-java-client</id>
    <content type="html"><![CDATA[<h1>CAS Client for Java 3.1</h1>

<h2>通过 web.xml 配置 Jasig CAS Client for Java</h2>

<p>CAS Client for Java 3.1/3.2 可以通过配置 web.xml 里的 context-params 和 filter init-params。每个 filter 都需要配置一系列的属性（properties）。filters 会查找这些属性：</p>

<ol>
<li>首先检查 filter 的本地 init-params（local init-params），看是否有相符合的属性名；</li>
<li>其次检查 context 的参数 ，看是否有相符合的属性名；</li>
</ol>


<p>如果在 filter 的 init-params 和 context 的参数中找到相同的值，则选用 init-params。</p>

<p>同样，filter 的顺序为：</p>

<ol>
<li>SingleLogOutFilter (if you&rsquo;re using it)</li>
<li>AuthenticationFilter</li>
<li>TicketValidationFilter (whichever one is chosen)</li>
<li>HttpServletRequestWrapperFilter</li>
<li>AssertionThreadLocalFilter</li>
</ol>


<blockquote><p>! 如果使用 serverName 属性，请注意 fragment-URL(#后的 URL)不会发送给服务器。</p></blockquote>

<p>一一介绍可用的 filters:</p>

<h3>org.jasig.cas.client.authentication.AuthenticationFilter</h3>

<p>AuthenticationFilter 判断一个用户是否需要验证。如果需要，则重定向到 CAS server。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;filter&gt;
</span><span class='line'>  &lt;filter-name&gt;CAS Authentication Filter&lt;/filter-name&gt;
</span><span class='line'>  &lt;filter-class&gt;org.jasig.cas.client.authentication.AuthenticationFilter&lt;/filter-class&gt;
</span><span class='line'>  &lt;init-param&gt;
</span><span class='line'>    &lt;!--cas server login url--&gt;
</span><span class='line'>    &lt;param-name&gt;casServerLoginUrl&lt;/param-name&gt;
</span><span class='line'>    &lt;param-value&gt;https://battags.ad.ess.rutgers.edu:8443/cas/login&lt;/param-value&gt;
</span><span class='line'>  &lt;/init-param&gt;
</span><span class='line'>  &lt;init-param&gt;
</span><span class='line'>    &lt;!--cas server name--&gt;
</span><span class='line'>    &lt;param-name&gt;serverName&lt;/param-name&gt;
</span><span class='line'>    &lt;param-value&gt;http://www.acme-client.com&lt;/param-value&gt;
</span><span class='line'>  &lt;/init-param&gt;
</span><span class='line'>&lt;/filter&gt;</span></code></pre></td></tr></table></div></figure>


<p><strong>Required Properties</strong></p>

<ul>
<li>casServerLoginUrl: CAS server 的登录页地址，i.e. <a href="https://localhost:8443/cas/login">https://localhost:8443/cas/login</a></li>
<li>service or serverName

<ul>
<li>service: 发送给 CAS server 的服务的 URL，e.g. <a href="https://localhost:8443/yourwebapp/index.html">https://localhost:8443/yourwebapp/index.html</a></li>
<li>serverName: 应用部署的服务器名。service URL 会据此动态生成。i.e. <a href="https://localhost:8443">https://localhost:8443</a> (需要指定协议，如果是标准端口，则端口可隐式)。</li>
</ul>
</li>
</ul>


<p><strong>Optional Properties</strong>:</p>

<p>有 <em>renew</em>, <em>gateway</em>, <em>artifactParameterName</em>, <em>serviceParameterName</em>。</p>

<h3>org.jasig.cas.client.authentication.Saml11AuthenticationFilter</h3>

<p>猜测是支持 SAML 1.1 的 authentication filter。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;filter&gt;
</span><span class='line'>  &lt;filter-name&gt;CAS Authentication Filter&lt;/filter-name&gt;
</span><span class='line'>  &lt;filter-class&gt;org.jasig.cas.client.authentication.AuthenticationFilter&lt;/filter-class&gt;
</span><span class='line'>  &lt;init-param&gt;
</span><span class='line'>    &lt;param-name&gt;casServerLoginUrl&lt;/param-name&gt;
</span><span class='line'>    &lt;param-value&gt;https://battags.ad.ess.rutgers.edu:8443/cas/login&lt;/param-value&gt;
</span><span class='line'>  &lt;/init-param&gt;
</span><span class='line'>  &lt;init-param&gt;
</span><span class='line'>    &lt;param-name&gt;serverName&lt;/param-name&gt;
</span><span class='line'>    &lt;param-value&gt;http://www.acme-client.com&lt;/param-value&gt;
</span><span class='line'>  &lt;/init-param&gt;
</span><span class='line'>&lt;/filter&gt;</span></code></pre></td></tr></table></div></figure>


<h3>org.jasig.cas.client.validation.Saml11TicketValidationFilter</h3>

<p>使用 SAML 1.1 协议验证 tickets。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;filter&gt;
</span><span class='line'>  &lt;filter-name&gt;CAS Validation Filter&lt;/filter-name&gt;
</span><span class='line'>  &lt;filter-class&gt;org.jasig.cas.client.validation.Saml11TicketValidationFilter&lt;/filter-class&gt;
</span><span class='line'>  &lt;init-param&gt;
</span><span class='line'>    &lt;param-name&gt;casServerUrlPrefix&lt;/param-name&gt;
</span><span class='line'>    &lt;param-value&gt;https://battags.ad.ess.rutgers.edu:8443/cas&lt;/param-value&gt;
</span><span class='line'>  &lt;/init-param&gt;
</span><span class='line'>  &lt;init-param&gt;
</span><span class='line'>    &lt;param-name&gt;serverName&lt;/param-name&gt;
</span><span class='line'>    &lt;param-value&gt;http://www.acme-client.com&lt;/param-value&gt;
</span><span class='line'>  &lt;/init-param&gt;
</span><span class='line'> &lt;/filter&gt;</span></code></pre></td></tr></table></div></figure>


<p><strong>Required Properties</strong></p>

<ul>
<li>casServerUrlPrefix: CAS 服务器的URL起始页，i.e. <a href="https://localhost:8443/cas">https://localhost:8443/cas</a></li>
<li>serverName or service: 同上</li>
</ul>


<p><strong>Optional Properties</strong></p>

<ul>
<li>redirectAfterValidation (default: true)</li>
<li>useSession (default: true)</li>
<li>exceptionOnValidationFailure (default: true)</li>
<li>tolerance (default: 1000 mSec)</li>
<li>renew (default: false)</li>
</ul>


<h3>org.jasig.cas.client.util.HttpServletRequestWrapperFilter</h3>

<p>Wraps an HttpServletRequest so that the getRemoteUser and getPrincipal return the CAS related entries.</p>

<p>包裹 HttpServletRequest，使 getRemoteUser 和 getPrincipal 返回 CAS 相关的入口。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;filter&gt;
</span><span class='line'>  &lt;filter-name&gt;CAS HttpServletRequest Wrapper Filter&lt;/filter-name&gt;
</span><span class='line'>  &lt;filter-class&gt;org.jasig.cas.client.util.HttpServletRequestWrapperFilter&lt;/filter-class&gt;
</span><span class='line'>&lt;/filter&gt;</span></code></pre></td></tr></table></div></figure>


<p><strong>Required Properties</strong></p>

<p>None</p>

<p><strong>Optional Properties</strong></p>

<p>None</p>

<h3>org.jasig.cas.client.util.AssertionThreadLocalFilter</h3>

<p>Places the Assertion in a ThreadLocal for portions of the application that need access to it. This is useful when the Web application that this filter &ldquo;fronts&rdquo; needs to get the Principal name, but it has no access to the HttpServletRequest, hence making getRemoteUser() call impossible.</p>

<p>把这个 Assertion 放进 ThreadLocal 中，因为有些应用可能需要。比如：当 Web 应用需要拿到 Principal 的名字，但是它无法访问 HttpServletRequest，因此 getRemoteUser() 没有用。</p>

<blockquote><p>! 没搞懂什么意思，猜测是 CAS Client 应用想要拿到登陆的用户名，但是用户名存储在 CAS Server 上。这个 filter 的作用就是把 Principal 放到 ThreadLocal 变量中。</p></blockquote>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;filter&gt;
</span><span class='line'>  &lt;filter-name&gt;CAS Assertion Thread Local Filter&lt;/filter-name&gt;
</span><span class='line'>  &lt;filter-class&gt;org.jasig.cas.client.util.AssertionThreadLocalFilter&lt;/filter-class&gt;
</span><span class='line'>&lt;/filter&gt;</span></code></pre></td></tr></table></div></figure>


<p>e.g. 一份稍完整的 CAS Client for Java 的 web.xml（未使用 SAML 1.1，为 CAS 协议）</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
<span class='line-number'>47</span>
<span class='line-number'>48</span>
<span class='line-number'>49</span>
<span class='line-number'>50</span>
<span class='line-number'>51</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
</span><span class='line'>&lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
</span><span class='line'>    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
</span><span class='line'>    version="2.4"&gt;
</span><span class='line'>
</span><span class='line'>    &lt;display-name&gt;CAS client demo : application&lt;/display-name&gt;
</span><span class='line'>
</span><span class='line'>    &lt;filter&gt;
</span><span class='line'>        &lt;!--配置 AuthenticationFilter--&gt;
</span><span class='line'>        &lt;filter-name&gt;CAS Authentication Filter&lt;/filter-name&gt;
</span><span class='line'>        &lt;filter-class&gt;org.jasig.cas.client.authentication.AuthenticationFilter&lt;/filter-class&gt;
</span><span class='line'>        &lt;init-param&gt;
</span><span class='line'>            &lt;!--property: 登陆页配置--&gt;
</span><span class='line'>            &lt;param-name&gt;casServerLoginUrl&lt;/param-name&gt;
</span><span class='line'>            &lt;param-value&gt;http://localhost:8080/cas/login&lt;/param-value&gt;
</span><span class='line'>        &lt;/init-param&gt;
</span><span class='line'>        &lt;init-param&gt;
</span><span class='line'>            &lt;!--property: 部署服务器地址--&gt;
</span><span class='line'>            &lt;param-name&gt;serverName&lt;/param-name&gt;
</span><span class='line'>            &lt;param-value&gt;http://localhost:8080&lt;/param-value&gt;
</span><span class='line'>        &lt;/init-param&gt;
</span><span class='line'>        &lt;!-- init-param&gt;
</span><span class='line'>            &lt;param-name&gt;service&lt;/param-name&gt;
</span><span class='line'>            &lt;param-value&gt;http://localhost:8080/default.jsp&lt;/param-value&gt;
</span><span class='line'>        &lt;/init-param--&gt;
</span><span class='line'>    &lt;/filter&gt;
</span><span class='line'>
</span><span class='line'>    &lt;filter&gt;
</span><span class='line'>        &lt;filter-name&gt;CAS Validation Filter&lt;/filter-name&gt;
</span><span class='line'>        &lt;filter-class&gt;org.jasig.cas.client.validation.Cas10TicketValidationFilter&lt;/filter-class&gt;
</span><span class='line'>        &lt;init-param&gt;
</span><span class='line'>            &lt;param-name&gt;casServerUrlPrefix&lt;/param-name&gt;
</span><span class='line'>            &lt;param-value&gt;http://localhost:8080/cas&lt;/param-value&gt;
</span><span class='line'>        &lt;/init-param&gt;
</span><span class='line'>        &lt;init-param&gt;
</span><span class='line'>            &lt;param-name&gt;serverName&lt;/param-name&gt;
</span><span class='line'>            &lt;param-value&gt;http://localhost:8080&lt;/param-value&gt;
</span><span class='line'>        &lt;/init-param&gt;
</span><span class='line'>    &lt;/filter&gt;
</span><span class='line'>
</span><span class='line'>    &lt;filter-mapping&gt;
</span><span class='line'>        &lt;filter-name&gt;CAS Authentication Filter&lt;/filter-name&gt;
</span><span class='line'>        &lt;url-pattern&gt;/protected/*&lt;/url-pattern&gt;
</span><span class='line'>    &lt;/filter-mapping&gt;
</span><span class='line'>
</span><span class='line'>    &lt;filter-mapping&gt;
</span><span class='line'>        &lt;filter-name&gt;CAS Validation Filter&lt;/filter-name&gt;
</span><span class='line'>        &lt;url-pattern&gt;*&lt;/url-pattern&gt;
</span><span class='line'>    &lt;/filter-mapping&gt;
</span><span class='line'>
</span><span class='line'>&lt;/web-app&gt;</span></code></pre></td></tr></table></div></figure>


<p>e.g. 使用 SAML 1.1</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
<span class='line-number'>43</span>
<span class='line-number'>44</span>
<span class='line-number'>45</span>
<span class='line-number'>46</span>
<span class='line-number'>47</span>
<span class='line-number'>48</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;?xml version="1.0" encoding="ISO-8859-1"?&gt;
</span><span class='line'>&lt;web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
</span><span class='line'>  xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
</span><span class='line'>  version="2.4"&gt;
</span><span class='line'>
</span><span class='line'>  &lt;display-name&gt;CAS client demo : application&lt;/display-name&gt;
</span><span class='line'>
</span><span class='line'>  &lt;filter&gt;
</span><span class='line'>      &lt;filter-name&gt;CAS Authentication Filter&lt;/filter-name&gt;
</span><span class='line'>      &lt;filter-class&gt;org.jasig.cas.client.authentication.Saml11AuthenticationFilter&lt;/filter-class&gt;
</span><span class='line'>      &lt;init-param&gt;
</span><span class='line'>          &lt;param-name&gt;casServerLoginUrl&lt;/param-name&gt;
</span><span class='line'>          &lt;param-value&gt;http://localhost:8080/cas/login&lt;/param-value&gt;
</span><span class='line'>      &lt;/init-param&gt;
</span><span class='line'>      &lt;init-param&gt;
</span><span class='line'>          &lt;param-name&gt;serverName&lt;/param-name&gt;
</span><span class='line'>          &lt;param-value&gt;http://localhost:8080&lt;/param-value&gt;
</span><span class='line'>      &lt;/init-param&gt;
</span><span class='line'>      &lt;init-param&gt;
</span><span class='line'>          &lt;param-name&gt;onlyFullyAuthenticated&lt;/param-name&gt;
</span><span class='line'>            &lt;param-value&gt;true&lt;/param-value&gt;
</span><span class='line'>        &lt;/init-param&gt;
</span><span class='line'>  &lt;/filter&gt;
</span><span class='line'>
</span><span class='line'>  &lt;filter&gt;
</span><span class='line'>      &lt;filter-name&gt;CAS Validation Filter&lt;/filter-name&gt;
</span><span class='line'>      &lt;filter-class&gt;org.jasig.cas.client.validation.Saml11TicketValidationFilter&lt;/filter-class&gt;
</span><span class='line'>      &lt;init-param&gt;
</span><span class='line'>          &lt;param-name&gt;casServerUrlPrefix&lt;/param-name&gt;
</span><span class='line'>          &lt;param-value&gt;http://localhost:8080/cas&lt;/param-value&gt;
</span><span class='line'>      &lt;/init-param&gt;
</span><span class='line'>      &lt;init-param&gt;
</span><span class='line'>          &lt;param-name&gt;serverName&lt;/param-name&gt;
</span><span class='line'>          &lt;param-value&gt;http://localhost:8080&lt;/param-value&gt;
</span><span class='line'>      &lt;/init-param&gt;
</span><span class='line'>  &lt;/filter&gt;
</span><span class='line'>
</span><span class='line'>  &lt;filter-mapping&gt;
</span><span class='line'>      &lt;filter-name&gt;CAS Authentication Filter&lt;/filter-name&gt;
</span><span class='line'>      &lt;url-pattern&gt;/protected/*&lt;/url-pattern&gt;
</span><span class='line'>  &lt;/filter-mapping&gt;
</span><span class='line'>
</span><span class='line'>  &lt;filter-mapping&gt;
</span><span class='line'>      &lt;filter-name&gt;CAS Validation Filter&lt;/filter-name&gt;
</span><span class='line'>      &lt;url-pattern&gt;*&lt;/url-pattern&gt;
</span><span class='line'>  &lt;/filter-mapping&gt;
</span><span class='line'>
</span><span class='line'>&lt;/web-app&gt;</span></code></pre></td></tr></table></div></figure>


<h2>配置单点登出 Single Sign Out</h2>

<blockquote><p>! <em>SingleSignOutFilter</em> 会影响到 character encoding。建议显式地配置下 <a href="http://code.google.com/p/vt-middleware/wiki/vtservletfilters#CharacterEncodingFilter">VT Character Encoding Filter</a> 或 <a href="http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/web/filter/CharacterEncodingFilter.html">Spring Character Encoding Filter</a>。</p></blockquote>

<p>CAS 对 Single Sign Out support 的支持，涉及到对一个 filter 和一个 ContextListener 的配置。需要注意的一点是，如果以 Web filters 的形式为 Java 配置 CAS Client，登出的 filter 需要在其他 filters 前面。</p>

<p><strong>PS</strong>: Order of Required Filters <a href="https://wiki.jasig.org/display/CASC/CAS+Client+for+Java+3.1">全文链接</a>
Order of Required Filters</p>

<p>How to configure the filters is described on the pages above. This section details the order in which the filters should appear:</p>

<ol>
<li>SingleLogOutFilter (if you&rsquo;re using it)</li>
<li>AuthenticationFilter</li>
<li>TicketValidationFilter (whichever one is chosen)</li>
<li>HttpServletRequestWrapperFilter</li>
<li>AssertionThreadLocalFilter</li>
</ol>


<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;listenerclass&gt;
</span><span class='line'>  org.jasig.cas.client.session.SingleSignOutHttpSessionListener&lt;/listener-class&gt;
</span><span class='line'>&lt;/listener&gt;</span></code></pre></td></tr></table></div></figure>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[NOTE: Special Things about CAS]]></title>
    <link href="http://pieux.github.io/blog/2013/12/05/note-special-things-about-cas/"/>
    <updated>2013-12-05T02:49:00+08:00</updated>
    <id>http://pieux.github.io/blog/2013/12/05/note-special-things-about-cas</id>
    <content type="html"><![CDATA[<h1>1</h1>

<p><strong>Create the Certificate</strong></p>

<p>打开终端，进到 home 目录，运行命令：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>keytool -genkey -alias tomcat -keyalg RSA -validity 365</span></code></pre></td></tr></table></div></figure>


<p>需要输入：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Enter keystore password:
</span><span class='line'>Re-enter new password:
</span><span class='line'>What is your first and last name?
</span><span class='line'>  [Unknown]:  $REPLACE_WITH_FULL_MACHINE_NAME
</span><span class='line'>What is the name of your organizational unit?
</span><span class='line'>  [Unknown]:  Test
</span><span class='line'>What is the name of your organization?
</span><span class='line'>  [Unknown]:  Test
</span><span class='line'>What is the name of your City or Locality?
</span><span class='line'>  [Unknown]:  Test
</span><span class='line'>What is the name of your State or Province?
</span><span class='line'>  [Unknown]:  Test
</span><span class='line'>What is the two-letter country code for this unit?
</span><span class='line'>  [Unknown]:  US
</span><span class='line'>Is CN=$FULL_MACHINE_NAME, OU=Test, O=Test, L=Test, ST=Test, C=US correct?
</span><span class='line'>  [no]:  yes</span></code></pre></td></tr></table></div></figure>


<p>如何给这些值？</p>

<p>For the keystore password you should enter &ldquo;changeit&rdquo; without the quotation marks. When prompted for the first and last name, you should enter your machine name during development. The rest of the data does not matter. Then obviously answer &ldquo;yes&rdquo; to the question of whether it&rsquo;s correct.</p>

<blockquote><p>注意： CAS 协议需要走 HTTPS，为了保证能够工作， &ldquo;first and last name&rdquo; 为 $FULL_MACHINE_NAME。Mac 上获取计算机全名的方法是：<code>scutil --get ComputerName</code> 或者 <code>scutil --get LocalHostName</code>。</p></blockquote>

<p>下一步，打开 <code>$TOMCAT_HOME/conf/server.xml</code>，找到这一块，去掉注释即可：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>&lt;!--
</span><span class='line'>&lt;Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
</span><span class='line'>    maxThreads="150" scheme="https" secure="true"
</span><span class='line'>    clientAuth="false" sslProtocol="TLS" /&gt;
</span><span class='line'>--&gt;</span></code></pre></td></tr></table></div></figure>


<p>重启 Tomcat，访问</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>https://$FULL_MACHINE_NAME:8443/</span></code></pre></td></tr></table></div></figure>


<p>Any application that wishes to securely connect to this Tomcat instance would need to import the certificate. You can export the certificate that&rsquo;s compatible with other JVM keystores by executing the following command:</p>

<p>所有想访问该 Tomcat 实例的应用都需要导入证书。首先导出证书，需要输入 keystore 的密码，这里就是 changeit：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>keytool -export -alias tomcat -file server.crt</span></code></pre></td></tr></table></div></figure>


<p>输出是：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Enter keystore password:
</span><span class='line'>Certificate stored in file &lt;server.crt&gt;</span></code></pre></td></tr></table></div></figure>


<p>You can then import the server.crt into other JVM keystore&rsquo;s by executing a command similar to this:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>keytool -import -file server.crt -keystore $JAVA_HOME/jre/lib/security/cacerts -alias tomcat</span></code></pre></td></tr></table></div></figure>


<p>It&rsquo;s recommended that you add it to the JVM keystore of your local development machine to facilitate testing.</p>

<h1>2</h1>

<p><strong>Maven War Overlay</strong><sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup></p>
<div class="footnotes">
<hr/>
<ol>
<li id="fn:1">
<p><a href="https://wiki.jasig.org/display/CASUM/Best+Practice+-+Setting+Up+CAS+Locally+using+the+Maven+WAR+Overlay+Method">Best Practice &ndash; Setting Up CAS Locally using the Maven WAR Overlay Method</a><a href="#fnref:1" rev="footnote">&#8617;</a></p></li>
</ol>
</div>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Deploy war to Tomcat]]></title>
    <link href="http://pieux.github.io/blog/2013/12/05/deploy-war-to-tomcat/"/>
    <updated>2013-12-05T02:28:00+08:00</updated>
    <id>http://pieux.github.io/blog/2013/12/05/deploy-war-to-tomcat</id>
    <content type="html"><![CDATA[<p>非常简单，<code>mvn package</code> 生成的 war 包，直接扔进 Tomcat 安装目录下的 webApps 目录。然后重启下 Tomcat。</p>

<p>不需要任何额外的配置，默认是 localhost:8080/war_name/</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[NOTE: Writing GNU Emacs Extensions]]></title>
    <link href="http://pieux.github.io/blog/2013/12/04/note-writing-gnu-emacs-extensions/"/>
    <updated>2013-12-04T11:59:00+08:00</updated>
    <id>http://pieux.github.io/blog/2013/12/04/note-writing-gnu-emacs-extensions</id>
    <content type="html"><![CDATA[<h1>1￼</h1>

<p><strong>列表处理</strong></p>

<h2>1.1</h2>

<p><strong>Lisp 列表</strong></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>'(rose
</span><span class='line'>  violet
</span><span class='line'>  daisy
</span><span class='line'>  buttercup)</span></code></pre></td></tr></table></div></figure>


<h3>1.1.1</h3>

<p><strong>Lisp 原子</strong></p>

<p><code>()</code> 空列表</p>

<p>空列表既是原子，也是列表</p>

<p>原子和列表都叫做 <strong>符号表达式</strong>(symbolic expression)，简称 s-expression。</p>
]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Emacs Help Command]]></title>
    <link href="http://pieux.github.io/blog/2013/11/30/emacs-help-command/"/>
    <updated>2013-11-30T03:30:00+08:00</updated>
    <id>http://pieux.github.io/blog/2013/11/30/emacs-help-command</id>
    <content type="html"><![CDATA[<p>You have typed C-h, the help character.  Type a Help option:
(Use SPC or DEL to scroll through this text.  Type q to exit the Help command.)</p>

<p>常用的是：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
<span class='line-number'>17</span>
<span class='line-number'>18</span>
<span class='line-number'>19</span>
<span class='line-number'>20</span>
<span class='line-number'>21</span>
<span class='line-number'>22</span>
<span class='line-number'>23</span>
<span class='line-number'>24</span>
<span class='line-number'>25</span>
<span class='line-number'>26</span>
<span class='line-number'>27</span>
<span class='line-number'>28</span>
<span class='line-number'>29</span>
<span class='line-number'>30</span>
<span class='line-number'>31</span>
<span class='line-number'>32</span>
<span class='line-number'>33</span>
<span class='line-number'>34</span>
<span class='line-number'>35</span>
<span class='line-number'>36</span>
<span class='line-number'>37</span>
<span class='line-number'>38</span>
<span class='line-number'>39</span>
<span class='line-number'>40</span>
<span class='line-number'>41</span>
<span class='line-number'>42</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>a PATTERN   Show commands whose name matches the PATTERN (a list of words
</span><span class='line'>              or a regexp).  See also the `apropos' command.              
</span><span class='line'>b           Display all key bindings.
</span><span class='line'>c KEYS      Display the command name run by the given key sequence.
</span><span class='line'>C CODING    Describe the given coding system, or RET for current ones.
</span><span class='line'>d PATTERN   Show a list of functions, variables, and other items whose
</span><span class='line'>              documentation matches the PATTERN (a list of words or a regexp).
</span><span class='line'>e           Go to the *Messages* buffer which logs echo-area messages.
</span><span class='line'>f FUNCTION  Display documentation for the given function.
</span><span class='line'>F COMMAND   Show the on-line manual's section that describes the command.
</span><span class='line'>g           Display information about the GNU project.
</span><span class='line'>h           Display the HELLO file which illustrates various scripts.
</span><span class='line'>i           Start the Info documentation reader: read on-line manuals.
</span><span class='line'>I METHOD    Describe a specific input method, or RET for current.
</span><span class='line'>k KEYS      Display the full documentation for the key sequence.
</span><span class='line'>K KEYS      Show the on-line manual's section for the command bound to KEYS.
</span><span class='line'>l           Show last 300 input keystrokes (lossage).
</span><span class='line'>L LANG-ENV  Describes a specific language environment, or RET for current.
</span><span class='line'>m           Display documentation of current minor modes and current major mode,
</span><span class='line'>              including their special commands.
</span><span class='line'>n           Display news of recent Emacs changes.
</span><span class='line'>p TOPIC     Find packages matching a given topic keyword.
</span><span class='line'>r           Display the Emacs manual in Info mode.
</span><span class='line'>s           Display contents of current syntax table, plus explanations.
</span><span class='line'>S SYMBOL    Show the section for the given symbol in the on-line manual
</span><span class='line'>              for the programming language used in this buffer.
</span><span class='line'>t           Start the Emacs learn-by-doing tutorial.
</span><span class='line'>v VARIABLE  Display the given variable's documentation and value.
</span><span class='line'>w COMMAND   Display which keystrokes invoke the given command (where-is).
</span><span class='line'>.           Display any available local help at point in the echo area.
</span><span class='line'>
</span><span class='line'>C-a         Information about Emacs.
</span><span class='line'>C-c         Emacs copying permission (GNU General Public License).
</span><span class='line'>C-d         Instructions for debugging GNU Emacs.
</span><span class='line'>C-e         External packages and information about Emacs.
</span><span class='line'>C-f         Emacs FAQ.
</span><span class='line'>C-m         How to order printed Emacs manuals.
</span><span class='line'>C-n         News of recent Emacs changes.
</span><span class='line'>C-o         Emacs ordering and distribution information.
</span><span class='line'>C-p         Info about known Emacs problems.
</span><span class='line'>C-t         Emacs TODO list.
</span><span class='line'>C-w         Information on absence of warranty for GNU Emacs.
</span></code></pre></td></tr></table></div></figure>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Emacs Survial with Evil &amp; Family]]></title>
    <link href="http://pieux.github.io/blog/2013/11/29/emacs-survial-with-evil-and-family/"/>
    <updated>2013-11-29T23:33:00+08:00</updated>
    <id>http://pieux.github.io/blog/2013/11/29/emacs-survial-with-evil-and-family</id>
    <content type="html"><![CDATA[<h1>1 概览</h1>

<h2>1.1 安装 evil</h2>

<p>从网上找到的一个简易的方法，easy to be understood:</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>(defun require-package (package)
</span><span class='line'>  "Install given PACKAGE."
</span><span class='line'>  (unless (package-installed-p package)
</span><span class='line'>    (unless (assoc package package-archive-contents)
</span><span class='line'>      (package-refresh-contents))
</span><span class='line'>    (package-install package)))</span></code></pre></td></tr></table></div></figure>




<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>(require-package 'evil)
</span><span class='line'>(require 'evil)
</span><span class='line'>(evil-mode 1)</span></code></pre></td></tr></table></div></figure>


<h2>1.2 modes and states</h2>

<p>光标上用点颜色，看起来舒服点。红色是退回Emacs（使用<code>C-z</code>，再按一次<code>C-z</code>回到evil），</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>(setq evil-emacs-state-cursor '("red" box))
</span><span class='line'>(setq evil-normal-state-cursor '("green" box))
</span><span class='line'>(setq evil-insert-state-cursor '("orange" bar))</span></code></pre></td></tr></table></div></figure>


<blockquote><p>这里有个terminology的区别：vim中的<em>mode</em>指的是Normal, Insert, Visual等，vim是模式编辑器。但是在Emacs中，<em>mode</em>是指对特定文本定义的一组快捷键。所以，evil把vim中的<em>mode</em>称作<em>state</em>。</p></blockquote>

<h1>2 设置</h1>

<p>通过一堆variable设置evil，可以通过 <code>M-x customize-group RET evil RET</code> 查看当前的设置。</p>

<p><code>setq</code>设置全局变量，<code>setq-default</code>设置buffer-local的变量，而且要在evil加载前修改<sup id="fnref:1"><a href="#fn:1" rel="footnote">1</a></sup>。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>(setq evil-shift-width 8) 
</span><span class='line'>;; Load Evil
</span><span class='line'>(require ’evil) . . .</span></code></pre></td></tr></table></div></figure>


<p>下面列出的variable，基本上默认值和vim的行为类似，但是<em>evil-want-C-u-scroll</em>默认不是t。</p>

<p><em>evil-auto-indent</em> [Variable]</p>

<blockquote><p>t(default), nil，类似vim中的autoindent。</p></blockquote>

<p><em>evil-shift-width</em> [Variable]</p>

<blockquote><p>The number of columns a line is shifted by the commands > and &lt;.</p></blockquote>

<p><em>evil-repeat-move-cursor</em> [Variable]</p>

<blockquote><p>如果t(default)，使用<code>.</code>重复时光标改变位置。</p></blockquote>

<p><em>evil-find-skip-newlines</em> [Variable]</p>

<blockquote><p>如果t，那么<em>f</em>，<em>F</em>，<em>t</em>，<em>T</em>会查找到其他行。nil(default)。</p></blockquote>

<p><em>evil-move-cursor-back</em> [Variable]</p>

<blockquote><p>t(default)，和vim的行为类似，退出insert state时，光标前移一格。</p></blockquote>

<p><em>evil-want-fine-undo</em> [Variable]</p>

<blockquote><p>If t, then a change-based action like cw may be undone in several steps. If nil (the default), then it is undone in one step.</p></blockquote>

<p><em>evil-regexp-search</em> [Variable]</p>

<blockquote><p>t(default)，<code>/</code>，<code>?</code>使用正则表达式</p></blockquote>

<p><em>evil-search-wrap</em> [Variable]</p>

<blockquote><p>t(default)，<code>/</code>，<code>?</code>搜索是到底后从头再搜索。</p></blockquote>

<p><em>evil-flash-delay</em> [Variable]</p>

<blockquote><p>The number of seconds to flash search matches when pressing n and N.</p></blockquote>

<p><em>evil-want-C-i-jump</em> [Variable]</p>

<blockquote><p>If t (the default), then C-i jumps forwards in the jump list. If nil, then C-i inserts a tab.</p></blockquote>

<p><em>evil-want-C-u-scroll</em> [Variable]</p>

<blockquote><p>If t, then C-u scrolls the buffer. If nil (the default), then C-u begins a numeric prefix argument.</p></blockquote>

<h2>2.1 The cursor</h2>

<p>这个之前也已经涉及过，现在全面了解下：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>(setq evil-emacs-state-cursor '("red" box))
</span><span class='line'>(setq evil-normal-state-cursor '("green" box))
</span><span class='line'>(setq evil-insert-state-cursor '("orange" bar))</span></code></pre></td></tr></table></div></figure>


<p>一共这么多：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
<span class='line-number'>16</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>evil-default-cursor
</span><span class='line'>  The default cursor.
</span><span class='line'>evil-normal-state-cursor
</span><span class='line'>  The cursor for Normal state.
</span><span class='line'>evil-insert-state-cursor
</span><span class='line'>  The cursor for Insert state.
</span><span class='line'>evil-visual-state-cursor
</span><span class='line'>  The cursor for Visual state.
</span><span class='line'>evil-replace-state-cursor
</span><span class='line'>  The cursor for Replace state.
</span><span class='line'>evil-operator-state-cursor
</span><span class='line'>  The cursor for Operator-Pending state.
</span><span class='line'>evil-motion-state-cursor
</span><span class='line'>  The cursor for Motion state.
</span><span class='line'>evil-emacs-state-cursor
</span><span class='line'>  The cursor for Emacs state.</span></code></pre></td></tr></table></div></figure>


<h2>2.2 The initial state</h2>

<p>默认是进入 Normal State。我也就不修改了。</p>

<h1>3 Keymaps</h1>

<p>Evil 的键映射存储在多个keymaps中，每个 state 有一个全局的 keymap，比如对应于Normal State 的<code>evil-normal-state-map</code>。
通过 Emacs 的 <code>define-key</code> 来修改。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>;; bind key "w" to command foo
</span><span class='line'>(define-key evil-normal-state-map "w" ’foo)</span></code></pre></td></tr></table></div></figure>


<p><code>evil-maps.el</code> 包含所有的键绑定。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>evil-normal-state-map
</span><span class='line'>  The global keymap for Normal state.
</span><span class='line'>evil-insert-state-map
</span><span class='line'>  The global keymap for Insert state.
</span><span class='line'>evil-visual-state-map
</span><span class='line'>  The global keymap for Visual state.
</span><span class='line'>evil-replace-state-map
</span><span class='line'>  The global keymap for Replace state.
</span><span class='line'>evil-operator-state-map
</span><span class='line'>  The global keymap for Operator-Pending state.
</span><span class='line'>evil-motion-state-map
</span><span class='line'>  The global keymap for Motion state.</span></code></pre></td></tr></table></div></figure>


<p>每个 state 还有一个 buffer-local 的 keymap。也就是特定于该 buffer，优先于 global keymap。这些可以通过 mode hook 修改。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>evil-normal-state-local-map
</span><span class='line'>  Buffer-local keymap for Normal state.
</span><span class='line'>evil-insert-state-local-map
</span><span class='line'>  Buffer-local keymap for Insert state.
</span><span class='line'>evil-visual-state-local-map
</span><span class='line'>  Buffer-local keymap for Visual state.
</span><span class='line'>evil-replace-state-local-map
</span><span class='line'>  Buffer-local keymap for Replace state.
</span><span class='line'>evil-operator-state-local-map
</span><span class='line'>  Buffer-local keymap for Operator-Pending state.
</span><span class='line'>evil-motion-state-local-map
</span><span class='line'>  Buffer-local keymap for Motion state.</span></code></pre></td></tr></table></div></figure>


<h2>3.1 ‘evil-define-key’</h2>

<p>Evil 提供的方法，可以往 Emacs 的 keymap 中添加特定 state 的键绑定。比如:</p>

<p>定义了一个 minor mode，叫做 foo-mode。然后往该 mode 的 normal state 下修改键绑定。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>(define-minor-mode foo-mode
</span><span class='line'>       "Foo mode."
</span><span class='line'>       :keymap (make-sparse-keymap))
</span><span class='line'>     (evil-define-key ’normal foo-mode-map "w" ’bar)
</span><span class='line'>     (evil-define-key ’normal foo-mode-map "e" ’baz)</span></code></pre></td></tr></table></div></figure>


<p>然后用 hook，添加到 text-mode-hook 里。</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>(add-hook ’text-mode-hook ’foo-mode) ; enable alongside text-mode</span></code></pre></td></tr></table></div></figure>


<h2>Appendix 1</h2>

<p>什么是 vim 的 magic？</p>

<p>主要涉及到正则表达式。先留几个参考资料：</p>

<ol>
<li><a href="http://vimdoc.sourceforge.net/htmldoc/pattern.html#/magic">vimdoc</a></li>
<li><a href="http://vim.wikia.com/wiki/Simplifying_regular_expressions_using_magic_and_no-magic">vim.vikia</a></li>
</ol>


<p><strong>To Be Continued</strong></p>
<div class="footnotes">
<hr/>
<ol>
<li id="fn:1">
<p>Strictly speaking, the order only matters if the variable affects the way Evil is loaded. This is the case with some of the ‘evil-want-’ variables.<a href="#fnref:1" rev="footnote">&#8617;</a></p></li>
</ol>
</div>

]]></content>
  </entry>
  
  <entry>
    <title type="html"><![CDATA[Linux Useful Tricks]]></title>
    <link href="http://pieux.github.io/blog/2013/11/29/linux-useful-tricks/"/>
    <updated>2013-11-29T08:18:00+08:00</updated>
    <id>http://pieux.github.io/blog/2013/11/29/linux-useful-tricks</id>
    <content type="html"><![CDATA[<h2>课后任务</h2>

<p>使用vagrant搭建Linux虚拟机</p>

<p><a href="http://docs.vagrantup.com/v2/getting-started/index.html">官方网址</a></p>

<p>1 首先安装 <a href="http://www.virtualbox.org/">virtualbox</a></p>

<p>2 安装<a href="http://docs.vagrantup.com/v2/installation/">vagrant</a></p>

<p>3 打开cmd，或者终端，运行以下命令，注意这一步会下载一个Linux发行版，大约3，400M吧。所以，你也可以用迅雷到网上下载下来，然后把 <code>http://files.vagrantup.com/precise32.box</code> 改成你文件的路径，比如我的是<code>file:///Users/pieux/Documents/o/precise32.box</code></p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>$ vagrant init precise32 http://files.vagrantup.com/precise32.box
</span><span class='line'>$ vagrant up</span></code></pre></td></tr></table></div></figure>


<p>4 SSH 进入linux吧！<code>vagrant ssh</code>，退出就是 <code>exit</code></p>

<p>5 关闭Linux的命令是，休眠<code>vagrant suspend</code>，或者关闭<code>vagrant halt</code>。</p>

<h2>man 命令</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>1    使用者在shell中可以操作的指令或可执行档
</span><span class='line'>2 系統核心可呼叫的函数与工具等
</span><span class='line'>3 一些常用的函数(function)与函数库(library)，大部分是C的函数库(libc)
</span><span class='line'>4 装置档案的说明，通常在/dev下的档案
</span><span class='line'>5 设定档或者是某些档案的格式
</span><span class='line'>6 游戏(games)
</span><span class='line'>7 惯例与协定等，例如Linux档案系统、网络协定、ASCII code等等的說明
</span><span class='line'>8 系統管理員可用的管理指令
</span><span class='line'>9 跟kernel有关的文件</span></code></pre></td></tr></table></div></figure>


<h2>tree 命令</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>tree
</span><span class='line'>-a
</span><span class='line'>-A
</span><span class='line'>-C
</span><span class='line'>man tree</span></code></pre></td></tr></table></div></figure>


<h1>shell 快捷键</h1>

<p>编辑命令</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Ctrl + a ：移到命令行首
</span><span class='line'>Ctrl + e ：移到命令行尾
</span><span class='line'>Ctrl + f ：按字符前移（右向）
</span><span class='line'>Ctrl + b ：按字符后移（左向）
</span><span class='line'>Alt + f ：按单词前移（右向）
</span><span class='line'>Alt + b ：按单词后移（左向）
</span><span class='line'>Ctrl + u ：从光标处删除至命令行首
</span><span class='line'>Ctrl + k ：从光标处删除至命令行尾
</span><span class='line'>Ctrl + d ：删除光标处的字符
</span><span class='line'>Ctrl + y ：粘贴至光标后</span></code></pre></td></tr></table></div></figure>


<p>重新执行命令</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Ctrl + r：逆向搜索命令历史
</span><span class='line'>Ctrl + g：从历史搜索模式退出
</span><span class='line'>Ctrl + p：历史中的上一条命令
</span><span class='line'>Ctrl + n：历史中的下一条命令</span></code></pre></td></tr></table></div></figure>


<p>控制命令</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>Ctrl + l：清屏
</span><span class='line'>Ctrl + s：阻止屏幕输出
</span><span class='line'>Ctrl + q：允许屏幕输出
</span><span class='line'>Ctrl + c：终止命令
</span><span class='line'>Ctrl + z：挂起命令</span></code></pre></td></tr></table></div></figure>


<h2>grep 命令</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>grep
</span><span class='line'>-v 反选
</span><span class='line'>-E 正则
</span><span class='line'>-i 忽略大小写
</span><span class='line'>-n 加上行号</span></code></pre></td></tr></table></div></figure>


<p>简单的正则表达式：</p>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>^ 行首
</span><span class='line'>$ 行尾
</span><span class='line'>. 任意字符
</span><span class='line'>* &gt;0个重复
</span><span class='line'>+ &gt;1个重复
</span><span class='line'>[Gg], [A-Za-z]
</span><span class='line'>\&lt; 单词首
</span><span class='line'>\&gt; 单词尾</span></code></pre></td></tr></table></div></figure>


<h2>进程相关</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>ps -aux | grep process-name
</span><span class='line'>pgrep
</span><span class='line'>kill
</span><span class='line'>pkill
</span><span class='line'>killall</span></code></pre></td></tr></table></div></figure>


<h2>find</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>find -name
</span><span class='line'>find -not -name
</span><span class='line'>-i
</span><span class='line'>-type fdl
</span><span class='line'>-mindepth 3
</span><span class='line'>-maxdepth 3
</span><span class='line'>-exec ls -l {} \;
</span><span class='line'>| xargs ls -l</span></code></pre></td></tr></table></div></figure>


<h2>其他</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
<span class='line-number'>5</span>
<span class='line-number'>6</span>
<span class='line-number'>7</span>
<span class='line-number'>8</span>
<span class='line-number'>9</span>
<span class='line-number'>10</span>
<span class='line-number'>11</span>
<span class='line-number'>12</span>
<span class='line-number'>13</span>
<span class='line-number'>14</span>
<span class='line-number'>15</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>touch 创建文件
</span><span class='line'>alias 别名
</span><span class='line'>history
</span><span class='line'>sudo !! 重执行上一条命令
</span><span class='line'>cd - 进入之前的目录
</span><span class='line'>wc
</span><span class='line'>chmod 
</span><span class='line'>du -hd 1
</span><span class='line'>du -h --max-depth=1
</span><span class='line'>Ctrl-Z 挂起
</span><span class='line'>fg 恢复
</span><span class='line'>&gt; .gitignore
</span><span class='line'>&lt; .gitignore
</span><span class='line'>mv filename.{old,new}
</span><span class='line'>rm !(*.foo|*.bar|*.baz)</span></code></pre></td></tr></table></div></figure>


<h2>git 相关</h2>

<figure class='code'><div class="highlight"><table><tr><td class="gutter"><pre class="line-numbers"><span class='line-number'>1</span>
<span class='line-number'>2</span>
<span class='line-number'>3</span>
<span class='line-number'>4</span>
</pre></td><td class='code'><pre><code class=''><span class='line'>git add -A
</span><span class='line'>git reset --soft
</span><span class='line'>git reset --mixed
</span><span class='line'>git reset --hard</span></code></pre></td></tr></table></div></figure>


<h2>学习资料推荐</h2>

<p><a href="http://www.commandlinefu.com/commands/tagged/800/commandfu">http://www.commandlinefu.com/commands/tagged/800/commandfu</a></p>
]]></content>
  </entry>
  
</feed>
