参考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” 博客