Monday, March 31, 2008

 

2008-04 Wallpaper

2008-04 Standard

2008-04 Wide

這個月的桌布是長得很像荷包蛋的花!

Labels: , ,


Thursday, March 27, 2008

 

Akina遊拍風

最近從朱大那邊過來的流量實在是相當驚人呀!
在這裡向我原本稀少的讀者們推薦本Blog的第一大友站
http://blogs.myoops.org/lucifer.php
正妹經過也請去他那邊留著言貼個相簿之類的~
同時為了怕各位訪客們覺得我的Blog太悶
剛好又跑去外拍
所以選一些貼到Blog上
不過我沒有種像朱大那樣全部都貼大圖就是 XD

1.


2.


3.


4.


5.


6.


7.


8.


9.


10.


11.

Labels: , , , , , , ,


Friday, March 14, 2008

 

My TOEIC Grades

測驗日期: 2008/02/24
聽力成績: 455
閱讀成績: 300
總成績: 755
CEF等級: B2

上個月底去考多益
聽力寫得還不錯
不過閱讀實在是太大意了
前面的題目畫卡畫太久
以後記得一定要帶粗的那種2B鉛筆
不然我用自動鉛筆配0.5mm的2B筆心一個圈圈就要塗好久...
寫文法、填空時又東想西想寫太慢...
導致後面的閱讀十幾題來不及寫就亂猜啦!

看了一下多益統計資訊
755雖然沒有說很低
但也才剛剛好低空飛過我們博班的畢業標準750...
我準備這次多益買了一本原廠的模擬測驗還有一本Lognman的
不過並沒有全部做完~
希望以後再考能夠拿個金色的證書呀~

Labels: , ,


Monday, March 10, 2008

 

JAAS Callback Example

JAAS已經有內建讓你從console或是跳出一個GUI視窗讓使用者填入帳號密碼進行Authentication的功能了
如果你想要有其他種方式
就必須去實作CallbackHandler這個interface
下面我提供一個只有兩個類別、一個設定檔的範例給大家參考

SampleLoginModule.java


import java.util.Map;

import java.util.Arrays;

import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.callback.NameCallback;
import javax.security.auth.callback.PasswordCallback;
import javax.security.auth.login.LoginException;
import javax.security.auth.spi.LoginModule;

public class SampleLoginModule implements LoginModule {

  private Subject subject;
  private CallbackHandler callbackHandler;
  private Map<String, ?> sharedState;
  private Map<String, ?> options;

  public void initialize(Subject subject, CallbackHandler callbackHandler,
      Map<String, ?> sharedState, Map<String, ?> options) {
    this.subject = subject;
    this.callbackHandler = callbackHandler;
    this.sharedState = sharedState;
    this.options = options;
  }

  public boolean login() throws LoginException {
    if (callbackHandler == null)
      throw new LoginException("Error: no CallbackHandler");

    Callback[] callbacks = new Callback[2];
    callbacks[0] = new NameCallback("user name: ");
    callbacks[1] = new PasswordCallback("password: ", true);

    try {
      callbackHandler.handle(callbacks);
    } catch (Exception e) {
      e.printStackTrace();
    }
    String username = ((NameCallback) callbacks[0]).getName();
    char[] password = ((PasswordCallback) callbacks[1]).getPassword();

    System.out.println("Username: " + username);
    System.out.println("Password: " + Arrays.toString(password));

    return true;
  }

  public boolean commit() throws LoginException {
    return true;
  }

  public boolean abort() throws LoginException {
    return true;
  }

  public boolean logout() throws LoginException {
    return true;
  }
}

Test.java


import javax.security.auth.callback.CallbackHandler;
import javax.security.auth.login.LoginContext;

import com.sun.security.auth.callback.DialogCallbackHandler;
import com.sun.security.auth.callback.TextCallbackHandler;

public class Test {

  public static void main(String[] args) throws Exception {
    CallbackHandler textCallbackHandler = new TextCallbackHandler();
    CallbackHandler dialogCllbackHandler = new DialogCallbackHandler();

//    LoginContext lc = new LoginContext("Sample", textCallbackHandler);
    LoginContext lc = new LoginContext("Sample", dialogCllbackHandler);
    lc.login();
  }
}

sample_jaas.config


Sample {
    SampleLoginModule required;
};

放在同一個目錄中
執行


javac *.java
java -Djava.security.auth.login.config=sample_jaas.config Test
就可以跑跑看啦!

延伸閱讀

  1. jini寫的JAAS authentication 的介紹

Labels: , , , ,


 

Simple Swing Login Form

下面這段code會產生出上面那樣的小Dialog視窗讓你輸入帳號密碼進行登入
是最近玩JAAS時寫的
不過其實在JAAS裡面有更方便讓人拿來用的東西
那就是javax.security.auth.callback package與com.sun.security.auth.callback package裡面的東東
怎麼用的話...有機會再跟大家說


JPanel panel = new JPanel(new GridLayout(2, 2));
JTextField nameField = new JTextField();
JPasswordField passwordField = new JPasswordField();
panel.add(new JLabel("ID"));
panel.add(nameField);
panel.add(new JLabel("Password"));
panel.add(passwordField);
while (JOptionPane.showConfirmDialog(null, panel, "Please Login",
JOptionPane.OK_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE) != 0) {
}
String username = nameField.getText();
char[] password = passwordField.getPassword();

Labels: , ,