2025-05-23

參考java ee 6 tutorial的security一章,學習筆記
java ee應用分成多個tier(層), client層是瀏覽器等, web層是jsp,jsf等,business層是ejb,db層是jpa、jdbc等
不同tier的container分別提供security
security分成declarative and programmatic兩種風格
 
假設用declarative的xml方式,則在dd中表示(或annotation)
web tier的dd是web.xml
ejb的dd是ejb-jar.xml
(註:annotation被分在declarative,但是具有programmatic的特點,此處暫略)
 
 
假設用programmatic的方式,有8個方法可用:
EJBContext.isCallerInRole
EJBContext.getCallerPrincipal
HttpServletRequest.authenticate
HttpServletRequest.getAuthType
HttpServletRequest.getUserPrincipal
HttpServletRequest.isUserInRole
HttpServletRequest.login
HttpServletRequest.logout
 
Glassfish的安全 (單有一份glassfish admin guide可查)
 
用glassfish admin console可以創建user, admin-user
用工具配合可以創建cert證書等
 
在EJB中
用@DeclareRoles可以定義roles
用@RolesAllowed控制role對受控資源的訪問
 
 
在servlet中
用@HttpConstraint加@ServletSecurity定義和控制對受控資源的訪問
 
 
在開發jee app時,app developer需要隨時考慮roles,但不需要知道glassfish server的realm裡面的user分類,即groups
app roles和server用戶的groups可以做mapping,如果恰好名字相同一一對應,則用默認principal-to-role即可
 
 
本文出自 “meng_xx” 博客

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *