再回頭閱讀Spring-Security3的文件,它提供一個獨立於其它Context之外(包括HTTP的Session)的運作環境:SecurityContextHolder,所以透過j_spring_security_check登入的資訊需從此處取得,可以在Action、Custom Tag或一般Java Class取得,如下:

Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
if (principal instanceof UserDetails) {
    logger.debug("username=" + ((UserDetails)principal).getUsername());
    logger.debug("pwd=" + ((UserDetails)principal).getPassword());
} else {
    logger.debug("username=" + ((UserDetails)principal).getUsername());
}

  偷窺登入者ID、Password過程有點麻煩,這也可知UserDetails是怎麼來的。

arrow
arrow
    全站熱搜

    Jemmy 發表在 痞客邦 留言(0) 人氣()