目前可知结构,如图所示,下面继续分析
在Tomcat中的*Base类基本都是实现了接口中大部分方法的基础类,将会有不同实现需求的少量方法设置为抽象方法,让不同的子类实现,大家可以学习这种设计思想、
BasicAuthenticator的authenticate方法
public boolean authenticate(HttpRequest request,
HttpResponse response,
LoginConfig config)
throws IOException {
// Have we already authenticated someone?
Principal principal =
((HttpServletRequest) request.getRequest()).getUserPrincipal();
if (principal != null) {
if (debug >= 1)
log("Already authenticated '" + principal.getName() + "'");
return (true);
}
// Validate any credentials already included with this request
HttpServletRequest hreq =
(HttpServletRequest) request.getRequest();
HttpServletResponse hres =
(HttpServletResponse) response.getResponse();
String authorization = request.getAuthorization();
String username = parseUsername(authorization);
String password = parsePassword(authorization);
principal = context.getRealm().authenticate(username, password);
if (principal != null) {
register(request, response, principal, Constants.BASIC_METHOD,
username, password);
return (true);
}
// Send an "unauthorized" response and an appropriate challenge
String realmName = config.getRealmName();
if (realmName == null)
realmName = hreq.getServerName() + ":" + hreq.getServerPort();
// if (debug >= 1)
// log("Challenging for realm '" + realmName + "'");
hres.setHeader("WWW-Authenticate",
"Basic realm=\"" + realmName + "\"");
hres.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
// hres.flushBuffer();
return (false);
}
从tomcat的设计中,我们还可以思考一下rcpc权限管理框架设计的一种思想:
由于本人其实对于tomcat的安全这块没有做深入了解,上面写的内容可能会有偏差,包括个人的理解方面,可能也会有问题,但是我这里更想介绍的是tomcat中权限与安全管理给我的一种启发和思考